LLDB mainline
SBLineEntry.cpp
Go to the documentation of this file.
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//===----------------------------------------------------------------------===//
8
10#include "Utils.h"
11#include "lldb/API/SBStream.h"
12#include "lldb/Host/PosixApi.h"
16
17#include <climits>
18
19using namespace lldb;
20using namespace lldb_private;
21
23
25 LLDB_INSTRUMENT_VA(this, rhs);
26
28}
29
31 if (lldb_object_ptr)
32 m_opaque_up = std::make_unique<LineEntry>(*lldb_object_ptr);
33}
34
36 LLDB_INSTRUMENT_VA(this, rhs);
37
38 if (this != &rhs)
40 return *this;
41}
42
44 m_opaque_up = std::make_unique<LineEntry>(lldb_object_ref);
45}
46
48
51
52 SBAddress sb_address;
53 if (m_opaque_up)
54 sb_address.SetAddress(m_opaque_up->range.GetBaseAddress());
55
56 return sb_address;
57}
58
61
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());
66 }
67 return sb_address;
68}
69
71 bool include_inlined_functions) const {
73
74 SBAddress sb_address;
75 if (m_opaque_up) {
76 AddressRange line_range = m_opaque_up->GetSameLineContiguousAddressRange(
77 include_inlined_functions);
78
79 sb_address.SetAddress(line_range.GetBaseAddress());
80 sb_address.OffsetAddress(line_range.GetByteSize());
81 }
82 return sb_address;
83}
84
87 return this->operator bool();
88}
89SBLineEntry::operator bool() const {
91
92 return m_opaque_up.get() && m_opaque_up->IsValid();
93}
94
97
98 SBFileSpec sb_file_spec;
99 if (m_opaque_up.get() && m_opaque_up->GetFile())
100 sb_file_spec.SetFileSpec(m_opaque_up->GetFile());
101
102 return sb_file_spec;
103}
104
105uint32_t SBLineEntry::GetLine() const {
106 LLDB_INSTRUMENT_VA(this);
107
108 uint32_t line = 0;
109 if (m_opaque_up)
110 line = m_opaque_up->line;
111
112 return line;
113}
114
115uint32_t SBLineEntry::GetColumn() const {
116 LLDB_INSTRUMENT_VA(this);
117
118 if (m_opaque_up)
119 return m_opaque_up->column;
120 return 0;
121}
122
124 LLDB_INSTRUMENT_VA(this, filespec);
125
126 if (filespec.IsValid())
127 ref().file_sp = std::make_shared<SupportFile>(filespec.ref());
128 else
129 ref().file_sp = std::make_shared<SupportFile>();
130}
131void SBLineEntry::SetLine(uint32_t line) {
132 LLDB_INSTRUMENT_VA(this, line);
133
134 ref().line = line;
135}
136
137void SBLineEntry::SetColumn(uint32_t column) {
138 LLDB_INSTRUMENT_VA(this, column);
139
140 ref().line = column;
141}
142
143bool SBLineEntry::operator==(const SBLineEntry &rhs) const {
144 LLDB_INSTRUMENT_VA(this, rhs);
145
146 lldb_private::LineEntry *lhs_ptr = m_opaque_up.get();
147 lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_up.get();
148
149 if (lhs_ptr && rhs_ptr)
150 return lldb_private::LineEntry::Compare(*lhs_ptr, *rhs_ptr) == 0;
151
152 return lhs_ptr == rhs_ptr;
153}
154
155bool SBLineEntry::operator!=(const SBLineEntry &rhs) const {
156 LLDB_INSTRUMENT_VA(this, rhs);
157
158 lldb_private::LineEntry *lhs_ptr = m_opaque_up.get();
159 lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_up.get();
160
161 if (lhs_ptr && rhs_ptr)
162 return lldb_private::LineEntry::Compare(*lhs_ptr, *rhs_ptr) != 0;
163
164 return lhs_ptr != rhs_ptr;
165}
166
168 return m_opaque_up.get();
169}
170
172 if (m_opaque_up == nullptr)
173 m_opaque_up = std::make_unique<lldb_private::LineEntry>();
174 return *m_opaque_up;
175}
176
178
180 LLDB_INSTRUMENT_VA(this, description);
181
182 Stream &strm = description.ref();
183
184 if (m_opaque_up) {
185 char file_path[PATH_MAX * 2];
186 m_opaque_up->GetFile().GetPath(file_path, sizeof(file_path));
187 strm.Printf("%s:%u", file_path, GetLine());
188 if (GetColumn() > 0)
189 strm.Printf(":%u", GetColumn());
190 } else
191 strm.PutCString("No value");
192
193 return true;
194}
195
#define LLDB_INSTRUMENT_VA(...)
bool OffsetAddress(addr_t offset)
Definition: SBAddress.cpp:139
void SetAddress(lldb::SBSection section, lldb::addr_t offset)
Definition: SBAddress.cpp:88
void SetFileSpec(const lldb_private::FileSpec &fspec)
Definition: SBFileSpec.cpp:164
bool IsValid() const
Definition: SBFileSpec.cpp:76
const lldb_private::FileSpec & ref() const
Definition: SBFileSpec.cpp:162
lldb::SBAddress GetStartAddress() const
Definition: SBLineEntry.cpp:49
lldb_private::LineEntry & ref()
bool GetDescription(lldb::SBStream &description)
void SetLineEntry(const lldb_private::LineEntry &lldb_object_ref)
Definition: SBLineEntry.cpp:43
void SetLine(uint32_t line)
bool operator!=(const lldb::SBLineEntry &rhs) const
lldb_private::LineEntry * get()
uint32_t GetColumn() const
bool IsValid() const
Definition: SBLineEntry.cpp:85
std::unique_ptr< lldb_private::LineEntry > m_opaque_up
Definition: SBLineEntry.h:76
const lldb_private::LineEntry * operator->() const
bool operator==(const lldb::SBLineEntry &rhs) const
uint32_t GetLine() const
lldb::SBFileSpec GetFileSpec() const
Definition: SBLineEntry.cpp:95
void SetFileSpec(lldb::SBFileSpec filespec)
void SetColumn(uint32_t column)
lldb::SBAddress GetEndAddress() const
Definition: SBLineEntry.cpp:59
const lldb::SBLineEntry & operator=(const lldb::SBLineEntry &rhs)
Definition: SBLineEntry.cpp:35
lldb::SBAddress GetSameLineContiguousAddressRangeEnd(bool include_inlined_functions) const
Definition: SBLineEntry.cpp:70
lldb_private::Stream & ref()
Definition: SBStream.cpp:177
A section + offset based address range class.
Definition: AddressRange.h:25
Address & GetBaseAddress()
Get accessor for the base address of the range.
Definition: AddressRange.h:211
lldb::addr_t GetByteSize() const
Get accessor for the byte size of this range.
Definition: AddressRange.h:223
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:134
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:65
A class that represents a running process on the host machine.
std::unique_ptr< T > clone(const std::unique_ptr< T > &src)
Definition: Utils.h:17
Definition: SBAddress.h:15
A line table entry class.
Definition: LineEntry.h:21
static int Compare(const LineEntry &lhs, const LineEntry &rhs)
Compare two LineEntry objects.
Definition: LineEntry.cpp:147
uint32_t line
The source line number, or LLDB_INVALID_LINE_NUMBER if there is no line number information.
Definition: LineEntry.h:147
lldb::SupportFileSP file_sp
The source file, possibly mapped by the target.source-map setting.
Definition: LineEntry.h:140
#define PATH_MAX