Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- SBLineEntry.cpp -----------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Stephen Wilson | 8acdbb8 | 2011-04-08 13:36:44 +0000 | [diff] [blame] | 10 | #include <limits.h> |
| 11 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 12 | #include "lldb/API/SBLineEntry.h" |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 13 | #include "lldb/API/SBStream.h" |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 14 | #include "lldb/Core/Log.h" |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 15 | #include "lldb/Symbol/LineEntry.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 | |
| 18 | using namespace lldb; |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 19 | using namespace lldb_private; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 21 | SBLineEntry::SBLineEntry() : m_opaque_ap() {} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 23 | SBLineEntry::SBLineEntry(const SBLineEntry &rhs) : m_opaque_ap() { |
| 24 | if (rhs.IsValid()) |
| 25 | ref() = rhs.ref(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 26 | } |
| 27 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 28 | SBLineEntry::SBLineEntry(const lldb_private::LineEntry *lldb_object_ptr) |
| 29 | : m_opaque_ap() { |
| 30 | if (lldb_object_ptr) |
| 31 | ref() = *lldb_object_ptr; |
| 32 | } |
| 33 | |
| 34 | const SBLineEntry &SBLineEntry::operator=(const SBLineEntry &rhs) { |
| 35 | if (this != &rhs) { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 36 | if (rhs.IsValid()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 37 | ref() = rhs.ref(); |
Greg Clayton | 8f7180b | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 38 | else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 39 | m_opaque_ap.reset(); |
| 40 | } |
| 41 | return *this; |
Greg Clayton | 8f7180b | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 44 | void SBLineEntry::SetLineEntry(const lldb_private::LineEntry &lldb_object_ref) { |
| 45 | ref() = lldb_object_ref; |
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 | SBLineEntry::~SBLineEntry() {} |
Greg Clayton | 8f7180b | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 49 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 50 | SBAddress SBLineEntry::GetStartAddress() const { |
| 51 | SBAddress sb_address; |
| 52 | if (m_opaque_ap.get()) |
| 53 | sb_address.SetAddress(&m_opaque_ap->range.GetBaseAddress()); |
Greg Clayton | 8f7180b | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 54 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 55 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 56 | if (log) { |
| 57 | StreamString sstr; |
| 58 | const Address *addr = sb_address.get(); |
| 59 | if (addr) |
| 60 | addr->Dump(&sstr, NULL, Address::DumpStyleModuleWithFileAddress, |
| 61 | Address::DumpStyleInvalid, 4); |
| 62 | log->Printf("SBLineEntry(%p)::GetStartAddress () => SBAddress (%p): %s", |
| 63 | static_cast<void *>(m_opaque_ap.get()), |
| 64 | static_cast<void *>(sb_address.get()), sstr.GetData()); |
| 65 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 66 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 67 | return sb_address; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 70 | SBAddress SBLineEntry::GetEndAddress() const { |
| 71 | SBAddress sb_address; |
| 72 | if (m_opaque_ap.get()) { |
| 73 | sb_address.SetAddress(&m_opaque_ap->range.GetBaseAddress()); |
| 74 | sb_address.OffsetAddress(m_opaque_ap->range.GetByteSize()); |
| 75 | } |
| 76 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 77 | if (log) { |
| 78 | StreamString sstr; |
| 79 | const Address *addr = sb_address.get(); |
| 80 | if (addr) |
| 81 | addr->Dump(&sstr, NULL, Address::DumpStyleModuleWithFileAddress, |
| 82 | Address::DumpStyleInvalid, 4); |
| 83 | log->Printf("SBLineEntry(%p)::GetEndAddress () => SBAddress (%p): %s", |
| 84 | static_cast<void *>(m_opaque_ap.get()), |
| 85 | static_cast<void *>(sb_address.get()), sstr.GetData()); |
| 86 | } |
| 87 | return sb_address; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 90 | bool SBLineEntry::IsValid() const { |
| 91 | return m_opaque_ap.get() && m_opaque_ap->IsValid(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 94 | SBFileSpec SBLineEntry::GetFileSpec() const { |
| 95 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 96 | |
| 97 | SBFileSpec sb_file_spec; |
| 98 | if (m_opaque_ap.get() && m_opaque_ap->file) |
| 99 | sb_file_spec.SetFileSpec(m_opaque_ap->file); |
| 100 | |
| 101 | if (log) { |
| 102 | SBStream sstr; |
| 103 | sb_file_spec.GetDescription(sstr); |
| 104 | log->Printf("SBLineEntry(%p)::GetFileSpec () => SBFileSpec(%p): %s", |
| 105 | static_cast<void *>(m_opaque_ap.get()), |
| 106 | static_cast<const void *>(sb_file_spec.get()), sstr.GetData()); |
| 107 | } |
| 108 | |
| 109 | return sb_file_spec; |
Greg Clayton | 8f7180b | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 112 | uint32_t SBLineEntry::GetLine() const { |
| 113 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 114 | |
| 115 | uint32_t line = 0; |
| 116 | if (m_opaque_ap.get()) |
| 117 | line = m_opaque_ap->line; |
| 118 | |
| 119 | if (log) |
| 120 | log->Printf("SBLineEntry(%p)::GetLine () => %u", |
| 121 | static_cast<void *>(m_opaque_ap.get()), line); |
| 122 | |
| 123 | return line; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 124 | } |
| 125 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 126 | uint32_t SBLineEntry::GetColumn() const { |
| 127 | if (m_opaque_ap.get()) |
| 128 | return m_opaque_ap->column; |
| 129 | return 0; |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 130 | } |
Caroline Tice | 750cd17 | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 131 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 132 | void SBLineEntry::SetFileSpec(lldb::SBFileSpec filespec) { |
| 133 | if (filespec.IsValid()) |
| 134 | ref().file = filespec.ref(); |
| 135 | else |
| 136 | ref().file.Clear(); |
Caroline Tice | 750cd17 | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 137 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 138 | void SBLineEntry::SetLine(uint32_t line) { ref().line = line; } |
| 139 | |
| 140 | void SBLineEntry::SetColumn(uint32_t column) { ref().line = column; } |
| 141 | |
| 142 | bool SBLineEntry::operator==(const SBLineEntry &rhs) const { |
| 143 | lldb_private::LineEntry *lhs_ptr = m_opaque_ap.get(); |
| 144 | lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_ap.get(); |
| 145 | |
| 146 | if (lhs_ptr && rhs_ptr) |
| 147 | return lldb_private::LineEntry::Compare(*lhs_ptr, *rhs_ptr) == 0; |
| 148 | |
| 149 | return lhs_ptr == rhs_ptr; |
| 150 | } |
| 151 | |
| 152 | bool SBLineEntry::operator!=(const SBLineEntry &rhs) const { |
| 153 | lldb_private::LineEntry *lhs_ptr = m_opaque_ap.get(); |
| 154 | lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_ap.get(); |
| 155 | |
| 156 | if (lhs_ptr && rhs_ptr) |
| 157 | return lldb_private::LineEntry::Compare(*lhs_ptr, *rhs_ptr) != 0; |
| 158 | |
| 159 | return lhs_ptr != rhs_ptr; |
| 160 | } |
| 161 | |
| 162 | const lldb_private::LineEntry *SBLineEntry::operator->() const { |
| 163 | return m_opaque_ap.get(); |
| 164 | } |
| 165 | |
| 166 | lldb_private::LineEntry &SBLineEntry::ref() { |
| 167 | if (m_opaque_ap.get() == NULL) |
| 168 | m_opaque_ap.reset(new lldb_private::LineEntry()); |
| 169 | return *m_opaque_ap; |
| 170 | } |
| 171 | |
| 172 | const lldb_private::LineEntry &SBLineEntry::ref() const { return *m_opaque_ap; } |
| 173 | |
| 174 | bool SBLineEntry::GetDescription(SBStream &description) { |
| 175 | Stream &strm = description.ref(); |
| 176 | |
| 177 | if (m_opaque_ap.get()) { |
| 178 | char file_path[PATH_MAX * 2]; |
| 179 | m_opaque_ap->file.GetPath(file_path, sizeof(file_path)); |
| 180 | strm.Printf("%s:%u", file_path, GetLine()); |
| 181 | if (GetColumn() > 0) |
| 182 | strm.Printf(":%u", GetColumn()); |
| 183 | } else |
| 184 | strm.PutCString("No value"); |
| 185 | |
| 186 | return true; |
| 187 | } |
| 188 | |
| 189 | lldb_private::LineEntry *SBLineEntry::get() { return m_opaque_ap.get(); } |