Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- SBLineEntry.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/SBLineEntry.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" |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +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" |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 14 | #include "lldb/Symbol/LineEntry.h" |
Zachary Turner | 6f9e690 | 2017-03-03 20:56:28 +0000 | [diff] [blame] | 15 | #include "lldb/Utility/Log.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 16 | #include "lldb/Utility/StreamString.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | |
Jonas Devlieghere | bd4bf82 | 2019-03-06 00:05:55 +0000 | [diff] [blame] | 18 | #include <limits.h> |
| 19 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | using namespace lldb; |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 21 | using namespace lldb_private; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 23 | SBLineEntry::SBLineEntry() : m_opaque_up() { |
| 24 | LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBLineEntry); |
| 25 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 26 | |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 27 | SBLineEntry::SBLineEntry(const SBLineEntry &rhs) : m_opaque_up() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 28 | LLDB_RECORD_CONSTRUCTOR(SBLineEntry, (const lldb::SBLineEntry &), rhs); |
| 29 | |
Jonas Devlieghere | bd4bf82 | 2019-03-06 00:05:55 +0000 | [diff] [blame] | 30 | m_opaque_up = clone(rhs.m_opaque_up); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 31 | } |
| 32 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 33 | SBLineEntry::SBLineEntry(const lldb_private::LineEntry *lldb_object_ptr) |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 34 | : m_opaque_up() { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 35 | if (lldb_object_ptr) |
Jonas Devlieghere | bd4bf82 | 2019-03-06 00:05:55 +0000 | [diff] [blame] | 36 | m_opaque_up = llvm::make_unique<LineEntry>(*lldb_object_ptr); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | const SBLineEntry &SBLineEntry::operator=(const SBLineEntry &rhs) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 40 | LLDB_RECORD_METHOD(const lldb::SBLineEntry &, |
| 41 | SBLineEntry, operator=,(const lldb::SBLineEntry &), 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); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 45 | return *this; |
Greg Clayton | 8f7180b | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 46 | } |
| 47 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 48 | void SBLineEntry::SetLineEntry(const lldb_private::LineEntry &lldb_object_ref) { |
Jonas Devlieghere | bd4bf82 | 2019-03-06 00:05:55 +0000 | [diff] [blame] | 49 | m_opaque_up = llvm::make_unique<LineEntry>(lldb_object_ref); |
Greg Clayton | 8f7180b | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 52 | SBLineEntry::~SBLineEntry() {} |
Greg Clayton | 8f7180b | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 53 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 54 | SBAddress SBLineEntry::GetStartAddress() const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 55 | LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBAddress, SBLineEntry, |
| 56 | GetStartAddress); |
| 57 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 58 | SBAddress sb_address; |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 59 | if (m_opaque_up) |
| 60 | sb_address.SetAddress(&m_opaque_up->range.GetBaseAddress()); |
Greg Clayton | 8f7180b | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 61 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 62 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 63 | if (log) { |
| 64 | StreamString sstr; |
| 65 | const Address *addr = sb_address.get(); |
| 66 | if (addr) |
| 67 | addr->Dump(&sstr, NULL, Address::DumpStyleModuleWithFileAddress, |
| 68 | Address::DumpStyleInvalid, 4); |
| 69 | log->Printf("SBLineEntry(%p)::GetStartAddress () => SBAddress (%p): %s", |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 70 | static_cast<void *>(m_opaque_up.get()), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 71 | static_cast<void *>(sb_address.get()), sstr.GetData()); |
| 72 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 73 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 74 | return LLDB_RECORD_RESULT(sb_address); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 77 | SBAddress SBLineEntry::GetEndAddress() const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 78 | LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBAddress, SBLineEntry, GetEndAddress); |
| 79 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 80 | SBAddress sb_address; |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 81 | if (m_opaque_up) { |
| 82 | sb_address.SetAddress(&m_opaque_up->range.GetBaseAddress()); |
| 83 | sb_address.OffsetAddress(m_opaque_up->range.GetByteSize()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 84 | } |
| 85 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 86 | if (log) { |
| 87 | StreamString sstr; |
| 88 | const Address *addr = sb_address.get(); |
| 89 | if (addr) |
| 90 | addr->Dump(&sstr, NULL, Address::DumpStyleModuleWithFileAddress, |
| 91 | Address::DumpStyleInvalid, 4); |
| 92 | log->Printf("SBLineEntry(%p)::GetEndAddress () => SBAddress (%p): %s", |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 93 | static_cast<void *>(m_opaque_up.get()), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 94 | static_cast<void *>(sb_address.get()), sstr.GetData()); |
| 95 | } |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 96 | return LLDB_RECORD_RESULT(sb_address); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 99 | bool SBLineEntry::IsValid() const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 100 | LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBLineEntry, IsValid); |
| 101 | |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 102 | return m_opaque_up.get() && m_opaque_up->IsValid(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 105 | SBFileSpec SBLineEntry::GetFileSpec() const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 106 | LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBFileSpec, SBLineEntry, GetFileSpec); |
| 107 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 108 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 109 | |
| 110 | SBFileSpec sb_file_spec; |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 111 | if (m_opaque_up.get() && m_opaque_up->file) |
| 112 | sb_file_spec.SetFileSpec(m_opaque_up->file); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 113 | |
| 114 | if (log) { |
| 115 | SBStream sstr; |
| 116 | sb_file_spec.GetDescription(sstr); |
| 117 | log->Printf("SBLineEntry(%p)::GetFileSpec () => SBFileSpec(%p): %s", |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 118 | static_cast<void *>(m_opaque_up.get()), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 119 | static_cast<const void *>(sb_file_spec.get()), sstr.GetData()); |
| 120 | } |
| 121 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 122 | return LLDB_RECORD_RESULT(sb_file_spec); |
Greg Clayton | 8f7180b | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 125 | uint32_t SBLineEntry::GetLine() const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 126 | LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBLineEntry, GetLine); |
| 127 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 128 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 129 | |
| 130 | uint32_t line = 0; |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 131 | if (m_opaque_up) |
| 132 | line = m_opaque_up->line; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 133 | |
| 134 | if (log) |
| 135 | log->Printf("SBLineEntry(%p)::GetLine () => %u", |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 136 | static_cast<void *>(m_opaque_up.get()), line); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 137 | |
| 138 | return line; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 139 | } |
| 140 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 141 | uint32_t SBLineEntry::GetColumn() const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 142 | LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBLineEntry, GetColumn); |
| 143 | |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 144 | if (m_opaque_up) |
| 145 | return m_opaque_up->column; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 146 | return 0; |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 147 | } |
Caroline Tice | 750cd17 | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 148 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 149 | void SBLineEntry::SetFileSpec(lldb::SBFileSpec filespec) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 150 | LLDB_RECORD_METHOD(void, SBLineEntry, SetFileSpec, (lldb::SBFileSpec), |
| 151 | filespec); |
| 152 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 153 | if (filespec.IsValid()) |
| 154 | ref().file = filespec.ref(); |
| 155 | else |
| 156 | ref().file.Clear(); |
Caroline Tice | 750cd17 | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 157 | } |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 158 | void SBLineEntry::SetLine(uint32_t line) { |
| 159 | LLDB_RECORD_METHOD(void, SBLineEntry, SetLine, (uint32_t), line); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 160 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 161 | ref().line = line; |
| 162 | } |
| 163 | |
| 164 | void SBLineEntry::SetColumn(uint32_t column) { |
| 165 | LLDB_RECORD_METHOD(void, SBLineEntry, SetColumn, (uint32_t), column); |
| 166 | |
| 167 | ref().line = column; |
| 168 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 169 | |
| 170 | bool SBLineEntry::operator==(const SBLineEntry &rhs) const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 171 | LLDB_RECORD_METHOD_CONST( |
| 172 | bool, SBLineEntry, operator==,(const lldb::SBLineEntry &), rhs); |
| 173 | |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 174 | lldb_private::LineEntry *lhs_ptr = m_opaque_up.get(); |
| 175 | lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_up.get(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 176 | |
| 177 | if (lhs_ptr && rhs_ptr) |
| 178 | return lldb_private::LineEntry::Compare(*lhs_ptr, *rhs_ptr) == 0; |
| 179 | |
| 180 | return lhs_ptr == rhs_ptr; |
| 181 | } |
| 182 | |
| 183 | bool SBLineEntry::operator!=(const SBLineEntry &rhs) const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 184 | LLDB_RECORD_METHOD_CONST( |
| 185 | bool, SBLineEntry, operator!=,(const lldb::SBLineEntry &), rhs); |
| 186 | |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 187 | lldb_private::LineEntry *lhs_ptr = m_opaque_up.get(); |
| 188 | lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_up.get(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 189 | |
| 190 | if (lhs_ptr && rhs_ptr) |
| 191 | return lldb_private::LineEntry::Compare(*lhs_ptr, *rhs_ptr) != 0; |
| 192 | |
| 193 | return lhs_ptr != rhs_ptr; |
| 194 | } |
| 195 | |
| 196 | const lldb_private::LineEntry *SBLineEntry::operator->() const { |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 197 | return m_opaque_up.get(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | lldb_private::LineEntry &SBLineEntry::ref() { |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 201 | if (m_opaque_up == NULL) |
| 202 | m_opaque_up.reset(new lldb_private::LineEntry()); |
| 203 | return *m_opaque_up; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 204 | } |
| 205 | |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 206 | const lldb_private::LineEntry &SBLineEntry::ref() const { return *m_opaque_up; } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 207 | |
| 208 | bool SBLineEntry::GetDescription(SBStream &description) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 209 | LLDB_RECORD_METHOD(bool, SBLineEntry, GetDescription, (lldb::SBStream &), |
| 210 | description); |
| 211 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 212 | Stream &strm = description.ref(); |
| 213 | |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 214 | if (m_opaque_up) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 215 | char file_path[PATH_MAX * 2]; |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 216 | m_opaque_up->file.GetPath(file_path, sizeof(file_path)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 217 | strm.Printf("%s:%u", file_path, GetLine()); |
| 218 | if (GetColumn() > 0) |
| 219 | strm.Printf(":%u", GetColumn()); |
| 220 | } else |
| 221 | strm.PutCString("No value"); |
| 222 | |
| 223 | return true; |
| 224 | } |
| 225 | |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 226 | lldb_private::LineEntry *SBLineEntry::get() { return m_opaque_up.get(); } |