LLDB  mainline
SBLineEntry.cpp
Go to the documentation of this file.
1 //===-- SBLineEntry.cpp -----------------------------------------*- C++ -*-===//
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 
9 #include "lldb/API/SBLineEntry.h"
10 #include "SBReproducerPrivate.h"
11 #include "Utils.h"
12 #include "lldb/API/SBStream.h"
13 #include "lldb/Host/PosixApi.h"
14 #include "lldb/Symbol/LineEntry.h"
16 
17 #include <limits.h>
18 
19 using namespace lldb;
20 using namespace lldb_private;
21 
22 SBLineEntry::SBLineEntry() : m_opaque_up() {
24 }
25 
26 SBLineEntry::SBLineEntry(const SBLineEntry &rhs) : m_opaque_up() {
28 
29  m_opaque_up = clone(rhs.m_opaque_up);
30 }
31 
33  : m_opaque_up() {
34  if (lldb_object_ptr)
35  m_opaque_up = llvm::make_unique<LineEntry>(*lldb_object_ptr);
36 }
37 
40  SBLineEntry, operator=,(const lldb::SBLineEntry &), rhs);
41 
42  if (this != &rhs)
43  m_opaque_up = clone(rhs.m_opaque_up);
44  return LLDB_RECORD_RESULT(*this);
45 }
46 
47 void SBLineEntry::SetLineEntry(const lldb_private::LineEntry &lldb_object_ref) {
48  m_opaque_up = llvm::make_unique<LineEntry>(lldb_object_ref);
49 }
50 
52 
56 
57  SBAddress sb_address;
58  if (m_opaque_up)
59  sb_address.SetAddress(&m_opaque_up->range.GetBaseAddress());
60 
61  return LLDB_RECORD_RESULT(sb_address);
62 }
63 
66 
67  SBAddress sb_address;
68  if (m_opaque_up) {
69  sb_address.SetAddress(&m_opaque_up->range.GetBaseAddress());
70  sb_address.OffsetAddress(m_opaque_up->range.GetByteSize());
71  }
72  return LLDB_RECORD_RESULT(sb_address);
73 }
74 
75 bool SBLineEntry::IsValid() const {
77  return this->operator bool();
78 }
79 SBLineEntry::operator bool() const {
80  LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBLineEntry, operator bool);
81 
82  return m_opaque_up.get() && m_opaque_up->IsValid();
83 }
84 
87 
88  SBFileSpec sb_file_spec;
89  if (m_opaque_up.get() && m_opaque_up->file)
90  sb_file_spec.SetFileSpec(m_opaque_up->file);
91 
92  return LLDB_RECORD_RESULT(sb_file_spec);
93 }
94 
97 
98  uint32_t line = 0;
99  if (m_opaque_up)
100  line = m_opaque_up->line;
101 
102  return line;
103 }
104 
107 
108  if (m_opaque_up)
109  return m_opaque_up->column;
110  return 0;
111 }
112 
115  filespec);
116 
117  if (filespec.IsValid())
118  ref().file = filespec.ref();
119  else
120  ref().file.Clear();
121 }
124 
125  ref().line = line;
126 }
127 
130 
131  ref().line = column;
132 }
133 
134 bool SBLineEntry::operator==(const SBLineEntry &rhs) const {
136  bool, SBLineEntry, operator==,(const lldb::SBLineEntry &), rhs);
137 
138  lldb_private::LineEntry *lhs_ptr = m_opaque_up.get();
139  lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_up.get();
140 
141  if (lhs_ptr && rhs_ptr)
142  return lldb_private::LineEntry::Compare(*lhs_ptr, *rhs_ptr) == 0;
143 
144  return lhs_ptr == rhs_ptr;
145 }
146 
147 bool SBLineEntry::operator!=(const SBLineEntry &rhs) const {
149  bool, SBLineEntry, operator!=,(const lldb::SBLineEntry &), rhs);
150 
151  lldb_private::LineEntry *lhs_ptr = m_opaque_up.get();
152  lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_up.get();
153 
154  if (lhs_ptr && rhs_ptr)
155  return lldb_private::LineEntry::Compare(*lhs_ptr, *rhs_ptr) != 0;
156 
157  return lhs_ptr != rhs_ptr;
158 }
159 
160 const lldb_private::LineEntry *SBLineEntry::operator->() const {
161  return m_opaque_up.get();
162 }
163 
164 lldb_private::LineEntry &SBLineEntry::ref() {
165  if (m_opaque_up == NULL)
166  m_opaque_up.reset(new lldb_private::LineEntry());
167  return *m_opaque_up;
168 }
169 
170 const lldb_private::LineEntry &SBLineEntry::ref() const { return *m_opaque_up; }
171 
174  description);
175 
176  Stream &strm = description.ref();
177 
178  if (m_opaque_up) {
179  char file_path[PATH_MAX * 2];
180  m_opaque_up->file.GetPath(file_path, sizeof(file_path));
181  strm.Printf("%s:%u", file_path, GetLine());
182  if (GetColumn() > 0)
183  strm.Printf(":%u", GetColumn());
184  } else
185  strm.PutCString("No value");
186 
187  return true;
188 }
189 
190 lldb_private::LineEntry *SBLineEntry::get() { return m_opaque_up.get(); }
191 
192 namespace lldb_private {
193 namespace repro {
194 
195 template <>
200  SBLineEntry, operator=,(const lldb::SBLineEntry &));
202  ());
205  LLDB_REGISTER_METHOD_CONST(bool, SBLineEntry, operator bool, ());
213  bool, SBLineEntry, operator==,(const lldb::SBLineEntry &));
215  bool, SBLineEntry, operator!=,(const lldb::SBLineEntry &));
217 }
218 
219 }
220 }
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:61
A line table entry class.
Definition: LineEntry.h:20
The registry contains a unique mapping between functions and their ID.
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
#define LLDB_RECORD_CONSTRUCTOR_NO_ARGS(Class)
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
lldb::SBAddress GetEndAddress() const
Definition: SBLineEntry.cpp:64
lldb::SBAddress GetStartAddress() const
Definition: SBLineEntry.cpp:53
lldb::SBFileSpec GetFileSpec() const
Definition: SBLineEntry.cpp:85
static int Compare(const LineEntry &lhs, const LineEntry &rhs)
Compare two LineEntry objects.
Definition: LineEntry.cpp:158
lldb_private::LineEntry * get()
void SetAddress(lldb::SBSection section, lldb::addr_t offset)
Definition: SBAddress.cpp:95
void Clear()
Clears the object state.
Definition: FileSpec.cpp:285
uint32_t GetColumn() const
bool IsValid() const
Definition: SBFileSpec.cpp:79
bool IsValid() const
Definition: SBLineEntry.cpp:75
void RegisterMethods< SBLineEntry >(Registry &R)
#define LLDB_REGISTER_CONSTRUCTOR(Class, Signature)
std::unique_ptr< T > clone(const std::unique_ptr< T > &src)
Definition: Utils.h:17
#define LLDB_RECORD_CONSTRUCTOR(Class, Signature,...)
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature,...)
FileSpec file
The source file, possibly mapped by the target.source-map setting.
Definition: LineEntry.h:151
uint32_t line
The source line number, or zero if there is no line number information.
Definition: LineEntry.h:154
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:106
void SetFileSpec(lldb::SBFileSpec filespec)
lldb_private::Stream & ref()
Definition: SBStream.cpp:162
bool OffsetAddress(addr_t offset)
Definition: SBAddress.cpp:154
#define LLDB_RECORD_METHOD_CONST(Result, Class, Method, Signature,...)
uint32_t GetLine() const
Definition: SBLineEntry.cpp:95
bool operator==(const lldb::SBLineEntry &rhs) const
void SetColumn(uint32_t column)
bool operator!=(const lldb::SBLineEntry &rhs) const
Definition: SBAddress.h:15
#define PATH_MAX
#define LLDB_REGISTER_METHOD(Result, Class, Method, Signature)
const lldb::SBLineEntry & operator=(const lldb::SBLineEntry &rhs)
Definition: SBLineEntry.cpp:38
bool GetDescription(lldb::SBStream &description)
#define LLDB_RECORD_METHOD_CONST_NO_ARGS(Result, Class, Method)
void SetLine(uint32_t line)
#define LLDB_RECORD_RESULT(Result)
#define LLDB_REGISTER_METHOD_CONST(Result, Class, Method, Signature)