Raphael Isemann | 8081428 | 2020-01-24 08:23:27 +0100 | [diff] [blame] | 1 | //===-- SBDeclaration.cpp -------------------------------------------------===// |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 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 |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "lldb/API/SBDeclaration.h" |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 10 | #include "SBReproducerPrivate.h" |
Jonas Devlieghere | bd4bf82 | 2019-03-06 00:05:55 +0000 | [diff] [blame] | 11 | #include "Utils.h" |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 12 | #include "lldb/API/SBStream.h" |
Zachary Turner | 8d48cd6 | 2017-03-22 17:33:23 +0000 | [diff] [blame] | 13 | #include "lldb/Host/PosixApi.h" |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 14 | #include "lldb/Symbol/Declaration.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 15 | #include "lldb/Utility/Stream.h" |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 16 | |
Greg Clayton | df3df25 | 2012-10-12 16:23:23 +0000 | [diff] [blame] | 17 | #include <limits.h> |
| 18 | |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 19 | using namespace lldb; |
| 20 | using namespace lldb_private; |
| 21 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 22 | SBDeclaration::SBDeclaration() : m_opaque_up() { |
| 23 | LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBDeclaration); |
| 24 | } |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 25 | |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 26 | SBDeclaration::SBDeclaration(const SBDeclaration &rhs) : m_opaque_up() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 27 | LLDB_RECORD_CONSTRUCTOR(SBDeclaration, (const lldb::SBDeclaration &), rhs); |
| 28 | |
Jonas Devlieghere | bd4bf82 | 2019-03-06 00:05:55 +0000 | [diff] [blame] | 29 | m_opaque_up = clone(rhs.m_opaque_up); |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 30 | } |
| 31 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 32 | SBDeclaration::SBDeclaration(const lldb_private::Declaration *lldb_object_ptr) |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 33 | : m_opaque_up() { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 34 | if (lldb_object_ptr) |
Jonas Devlieghere | a8f3ae7 | 2019-08-14 22:19:23 +0000 | [diff] [blame] | 35 | m_opaque_up = std::make_unique<Declaration>(*lldb_object_ptr); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | const SBDeclaration &SBDeclaration::operator=(const SBDeclaration &rhs) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 39 | LLDB_RECORD_METHOD(const lldb::SBDeclaration &, |
| 40 | SBDeclaration, operator=,(const lldb::SBDeclaration &), |
| 41 | rhs); |
| 42 | |
Jonas Devlieghere | bd4bf82 | 2019-03-06 00:05:55 +0000 | [diff] [blame] | 43 | if (this != &rhs) |
| 44 | m_opaque_up = clone(rhs.m_opaque_up); |
Jonas Devlieghere | 306809f | 2019-04-03 21:31:22 +0000 | [diff] [blame] | 45 | return LLDB_RECORD_RESULT(*this); |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 46 | } |
| 47 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 48 | void SBDeclaration::SetDeclaration( |
| 49 | const lldb_private::Declaration &lldb_object_ref) { |
| 50 | ref() = lldb_object_ref; |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Jonas Devlieghere | 866b7a6 | 2020-02-17 22:57:06 -0800 | [diff] [blame] | 53 | SBDeclaration::~SBDeclaration() = default; |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 54 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 55 | bool SBDeclaration::IsValid() const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 56 | LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBDeclaration, IsValid); |
Pavel Labath | 7f5237b | 2019-03-11 13:58:46 +0000 | [diff] [blame] | 57 | return this->operator bool(); |
| 58 | } |
| 59 | SBDeclaration::operator bool() const { |
| 60 | LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBDeclaration, operator bool); |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 61 | |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 62 | return m_opaque_up.get() && m_opaque_up->IsValid(); |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 65 | SBFileSpec SBDeclaration::GetFileSpec() const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 66 | LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBFileSpec, SBDeclaration, |
| 67 | GetFileSpec); |
| 68 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 69 | |
| 70 | SBFileSpec sb_file_spec; |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 71 | if (m_opaque_up.get() && m_opaque_up->GetFile()) |
| 72 | sb_file_spec.SetFileSpec(m_opaque_up->GetFile()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 73 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 74 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 75 | return LLDB_RECORD_RESULT(sb_file_spec); |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 78 | uint32_t SBDeclaration::GetLine() const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 79 | LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBDeclaration, GetLine); |
| 80 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 81 | |
| 82 | uint32_t line = 0; |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 83 | if (m_opaque_up) |
| 84 | line = m_opaque_up->GetLine(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 85 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 86 | |
| 87 | return line; |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 90 | uint32_t SBDeclaration::GetColumn() const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 91 | LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBDeclaration, GetColumn); |
| 92 | |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 93 | if (m_opaque_up) |
| 94 | return m_opaque_up->GetColumn(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 95 | return 0; |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 98 | void SBDeclaration::SetFileSpec(lldb::SBFileSpec filespec) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 99 | LLDB_RECORD_METHOD(void, SBDeclaration, SetFileSpec, (lldb::SBFileSpec), |
| 100 | filespec); |
| 101 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 102 | if (filespec.IsValid()) |
| 103 | ref().SetFile(filespec.ref()); |
| 104 | else |
| 105 | ref().SetFile(FileSpec()); |
| 106 | } |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 107 | void SBDeclaration::SetLine(uint32_t line) { |
| 108 | LLDB_RECORD_METHOD(void, SBDeclaration, SetLine, (uint32_t), line); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 109 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 110 | ref().SetLine(line); |
| 111 | } |
| 112 | |
| 113 | void SBDeclaration::SetColumn(uint32_t column) { |
| 114 | LLDB_RECORD_METHOD(void, SBDeclaration, SetColumn, (uint32_t), column); |
| 115 | |
| 116 | ref().SetColumn(column); |
| 117 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 118 | |
| 119 | bool SBDeclaration::operator==(const SBDeclaration &rhs) const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 120 | LLDB_RECORD_METHOD_CONST( |
| 121 | bool, SBDeclaration, operator==,(const lldb::SBDeclaration &), rhs); |
| 122 | |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 123 | lldb_private::Declaration *lhs_ptr = m_opaque_up.get(); |
| 124 | lldb_private::Declaration *rhs_ptr = rhs.m_opaque_up.get(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 125 | |
| 126 | if (lhs_ptr && rhs_ptr) |
| 127 | return lldb_private::Declaration::Compare(*lhs_ptr, *rhs_ptr) == 0; |
| 128 | |
| 129 | return lhs_ptr == rhs_ptr; |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 130 | } |
| 131 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 132 | bool SBDeclaration::operator!=(const SBDeclaration &rhs) const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 133 | LLDB_RECORD_METHOD_CONST( |
| 134 | bool, SBDeclaration, operator!=,(const lldb::SBDeclaration &), rhs); |
| 135 | |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 136 | lldb_private::Declaration *lhs_ptr = m_opaque_up.get(); |
| 137 | lldb_private::Declaration *rhs_ptr = rhs.m_opaque_up.get(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 138 | |
| 139 | if (lhs_ptr && rhs_ptr) |
| 140 | return lldb_private::Declaration::Compare(*lhs_ptr, *rhs_ptr) != 0; |
| 141 | |
| 142 | return lhs_ptr != rhs_ptr; |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 143 | } |
| 144 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 145 | const lldb_private::Declaration *SBDeclaration::operator->() const { |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 146 | return m_opaque_up.get(); |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 147 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 148 | |
| 149 | lldb_private::Declaration &SBDeclaration::ref() { |
Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 150 | if (m_opaque_up == nullptr) |
Jonas Devlieghere | 1c0bbe4 | 2020-06-24 16:25:05 -0700 | [diff] [blame] | 151 | m_opaque_up = std::make_unique<lldb_private::Declaration>(); |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 152 | return *m_opaque_up; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | const lldb_private::Declaration &SBDeclaration::ref() const { |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 156 | return *m_opaque_up; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | bool SBDeclaration::GetDescription(SBStream &description) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 160 | LLDB_RECORD_METHOD(bool, SBDeclaration, GetDescription, (lldb::SBStream &), |
| 161 | description); |
| 162 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 163 | Stream &strm = description.ref(); |
| 164 | |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 165 | if (m_opaque_up) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 166 | char file_path[PATH_MAX * 2]; |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 167 | m_opaque_up->GetFile().GetPath(file_path, sizeof(file_path)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 168 | strm.Printf("%s:%u", file_path, GetLine()); |
| 169 | if (GetColumn() > 0) |
| 170 | strm.Printf(":%u", GetColumn()); |
| 171 | } else |
| 172 | strm.PutCString("No value"); |
| 173 | |
| 174 | return true; |
| 175 | } |
| 176 | |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 177 | lldb_private::Declaration *SBDeclaration::get() { return m_opaque_up.get(); } |
Michal Gorny | ae211ec | 2019-03-19 17:13:13 +0000 | [diff] [blame] | 178 | |
| 179 | namespace lldb_private { |
| 180 | namespace repro { |
| 181 | |
| 182 | template <> |
| 183 | void RegisterMethods<SBDeclaration>(Registry &R) { |
| 184 | LLDB_REGISTER_CONSTRUCTOR(SBDeclaration, ()); |
| 185 | LLDB_REGISTER_CONSTRUCTOR(SBDeclaration, (const lldb::SBDeclaration &)); |
| 186 | LLDB_REGISTER_METHOD( |
| 187 | const lldb::SBDeclaration &, |
| 188 | SBDeclaration, operator=,(const lldb::SBDeclaration &)); |
| 189 | LLDB_REGISTER_METHOD_CONST(bool, SBDeclaration, IsValid, ()); |
| 190 | LLDB_REGISTER_METHOD_CONST(bool, SBDeclaration, operator bool, ()); |
| 191 | LLDB_REGISTER_METHOD_CONST(lldb::SBFileSpec, SBDeclaration, GetFileSpec, |
| 192 | ()); |
| 193 | LLDB_REGISTER_METHOD_CONST(uint32_t, SBDeclaration, GetLine, ()); |
| 194 | LLDB_REGISTER_METHOD_CONST(uint32_t, SBDeclaration, GetColumn, ()); |
| 195 | LLDB_REGISTER_METHOD(void, SBDeclaration, SetFileSpec, (lldb::SBFileSpec)); |
| 196 | LLDB_REGISTER_METHOD(void, SBDeclaration, SetLine, (uint32_t)); |
| 197 | LLDB_REGISTER_METHOD(void, SBDeclaration, SetColumn, (uint32_t)); |
| 198 | LLDB_REGISTER_METHOD_CONST( |
| 199 | bool, SBDeclaration, operator==,(const lldb::SBDeclaration &)); |
| 200 | LLDB_REGISTER_METHOD_CONST( |
| 201 | bool, SBDeclaration, operator!=,(const lldb::SBDeclaration &)); |
| 202 | LLDB_REGISTER_METHOD(bool, SBDeclaration, GetDescription, |
| 203 | (lldb::SBStream &)); |
| 204 | } |
| 205 | |
| 206 | } |
| 207 | } |