Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / source / API / SBLineEntry.cpp
blob28d12e65fdaf8a7b6aae0531083b6f26c753e0f0
1 //===-- SBLineEntry.cpp ---------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 #include "lldb/API/SBLineEntry.h"
10 #include "Utils.h"
11 #include "lldb/API/SBStream.h"
12 #include "lldb/Host/PosixApi.h"
13 #include "lldb/Symbol/LineEntry.h"
14 #include "lldb/Utility/Instrumentation.h"
15 #include "lldb/Utility/StreamString.h"
17 #include <climits>
19 using namespace lldb;
20 using namespace lldb_private;
22 SBLineEntry::SBLineEntry() { LLDB_INSTRUMENT_VA(this); }
24 SBLineEntry::SBLineEntry(const SBLineEntry &rhs) {
25 LLDB_INSTRUMENT_VA(this, rhs);
27 m_opaque_up = clone(rhs.m_opaque_up);
30 SBLineEntry::SBLineEntry(const lldb_private::LineEntry *lldb_object_ptr) {
31 if (lldb_object_ptr)
32 m_opaque_up = std::make_unique<LineEntry>(*lldb_object_ptr);
35 const SBLineEntry &SBLineEntry::operator=(const SBLineEntry &rhs) {
36 LLDB_INSTRUMENT_VA(this, rhs);
38 if (this != &rhs)
39 m_opaque_up = clone(rhs.m_opaque_up);
40 return *this;
43 void SBLineEntry::SetLineEntry(const lldb_private::LineEntry &lldb_object_ref) {
44 m_opaque_up = std::make_unique<LineEntry>(lldb_object_ref);
47 SBLineEntry::~SBLineEntry() = default;
49 SBAddress SBLineEntry::GetStartAddress() const {
50 LLDB_INSTRUMENT_VA(this);
52 SBAddress sb_address;
53 if (m_opaque_up)
54 sb_address.SetAddress(m_opaque_up->range.GetBaseAddress());
56 return sb_address;
59 SBAddress SBLineEntry::GetEndAddress() const {
60 LLDB_INSTRUMENT_VA(this);
62 SBAddress sb_address;
63 if (m_opaque_up) {
64 sb_address.SetAddress(m_opaque_up->range.GetBaseAddress());
65 sb_address.OffsetAddress(m_opaque_up->range.GetByteSize());
67 return sb_address;
70 bool SBLineEntry::IsValid() const {
71 LLDB_INSTRUMENT_VA(this);
72 return this->operator bool();
74 SBLineEntry::operator bool() const {
75 LLDB_INSTRUMENT_VA(this);
77 return m_opaque_up.get() && m_opaque_up->IsValid();
80 SBFileSpec SBLineEntry::GetFileSpec() const {
81 LLDB_INSTRUMENT_VA(this);
83 SBFileSpec sb_file_spec;
84 if (m_opaque_up.get() && m_opaque_up->file)
85 sb_file_spec.SetFileSpec(m_opaque_up->file);
87 return sb_file_spec;
90 uint32_t SBLineEntry::GetLine() const {
91 LLDB_INSTRUMENT_VA(this);
93 uint32_t line = 0;
94 if (m_opaque_up)
95 line = m_opaque_up->line;
97 return line;
100 uint32_t SBLineEntry::GetColumn() const {
101 LLDB_INSTRUMENT_VA(this);
103 if (m_opaque_up)
104 return m_opaque_up->column;
105 return 0;
108 void SBLineEntry::SetFileSpec(lldb::SBFileSpec filespec) {
109 LLDB_INSTRUMENT_VA(this, filespec);
111 if (filespec.IsValid())
112 ref().file = filespec.ref();
113 else
114 ref().file.Clear();
116 void SBLineEntry::SetLine(uint32_t line) {
117 LLDB_INSTRUMENT_VA(this, line);
119 ref().line = line;
122 void SBLineEntry::SetColumn(uint32_t column) {
123 LLDB_INSTRUMENT_VA(this, column);
125 ref().line = column;
128 bool SBLineEntry::operator==(const SBLineEntry &rhs) const {
129 LLDB_INSTRUMENT_VA(this, rhs);
131 lldb_private::LineEntry *lhs_ptr = m_opaque_up.get();
132 lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_up.get();
134 if (lhs_ptr && rhs_ptr)
135 return lldb_private::LineEntry::Compare(*lhs_ptr, *rhs_ptr) == 0;
137 return lhs_ptr == rhs_ptr;
140 bool SBLineEntry::operator!=(const SBLineEntry &rhs) const {
141 LLDB_INSTRUMENT_VA(this, rhs);
143 lldb_private::LineEntry *lhs_ptr = m_opaque_up.get();
144 lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_up.get();
146 if (lhs_ptr && rhs_ptr)
147 return lldb_private::LineEntry::Compare(*lhs_ptr, *rhs_ptr) != 0;
149 return lhs_ptr != rhs_ptr;
152 const lldb_private::LineEntry *SBLineEntry::operator->() const {
153 return m_opaque_up.get();
156 lldb_private::LineEntry &SBLineEntry::ref() {
157 if (m_opaque_up == nullptr)
158 m_opaque_up = std::make_unique<lldb_private::LineEntry>();
159 return *m_opaque_up;
162 const lldb_private::LineEntry &SBLineEntry::ref() const { return *m_opaque_up; }
164 bool SBLineEntry::GetDescription(SBStream &description) {
165 LLDB_INSTRUMENT_VA(this, description);
167 Stream &strm = description.ref();
169 if (m_opaque_up) {
170 char file_path[PATH_MAX * 2];
171 m_opaque_up->file.GetPath(file_path, sizeof(file_path));
172 strm.Printf("%s:%u", file_path, GetLine());
173 if (GetColumn() > 0)
174 strm.Printf(":%u", GetColumn());
175 } else
176 strm.PutCString("No value");
178 return true;
181 lldb_private::LineEntry *SBLineEntry::get() { return m_opaque_up.get(); }