LLDB  mainline
SBDeclaration.cpp
Go to the documentation of this file.
1 //===-- SBDeclaration.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 
10 #include "SBReproducerPrivate.h"
11 #include "Utils.h"
12 #include "lldb/API/SBStream.h"
13 #include "lldb/Host/PosixApi.h"
15 #include "lldb/Utility/Stream.h"
16 
17 #include <limits.h>
18 
19 using namespace lldb;
20 using namespace lldb_private;
21 
22 SBDeclaration::SBDeclaration() : m_opaque_up() {
24 }
25 
26 SBDeclaration::SBDeclaration(const SBDeclaration &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<Declaration>(*lldb_object_ptr);
36 }
37 
40  SBDeclaration, operator=,(const lldb::SBDeclaration &),
41  rhs);
42 
43  if (this != &rhs)
44  m_opaque_up = clone(rhs.m_opaque_up);
45  return LLDB_RECORD_RESULT(*this);
46 }
47 
48 void SBDeclaration::SetDeclaration(
49  const lldb_private::Declaration &lldb_object_ref) {
50  ref() = lldb_object_ref;
51 }
52 
54 
55 bool SBDeclaration::IsValid() const {
57  return this->operator bool();
58 }
59 SBDeclaration::operator bool() const {
60  LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBDeclaration, operator bool);
61 
62  return m_opaque_up.get() && m_opaque_up->IsValid();
63 }
64 
67  GetFileSpec);
68 
69 
70  SBFileSpec sb_file_spec;
71  if (m_opaque_up.get() && m_opaque_up->GetFile())
72  sb_file_spec.SetFileSpec(m_opaque_up->GetFile());
73 
74 
75  return LLDB_RECORD_RESULT(sb_file_spec);
76 }
77 
80 
81 
82  uint32_t line = 0;
83  if (m_opaque_up)
84  line = m_opaque_up->GetLine();
85 
86 
87  return line;
88 }
89 
92 
93  if (m_opaque_up)
94  return m_opaque_up->GetColumn();
95  return 0;
96 }
97 
100  filespec);
101 
102  if (filespec.IsValid())
103  ref().SetFile(filespec.ref());
104  else
105  ref().SetFile(FileSpec());
106 }
109 
110  ref().SetLine(line);
111 }
112 
115 
116  ref().SetColumn(column);
117 }
118 
119 bool SBDeclaration::operator==(const SBDeclaration &rhs) const {
121  bool, SBDeclaration, operator==,(const lldb::SBDeclaration &), rhs);
122 
123  lldb_private::Declaration *lhs_ptr = m_opaque_up.get();
124  lldb_private::Declaration *rhs_ptr = rhs.m_opaque_up.get();
125 
126  if (lhs_ptr && rhs_ptr)
127  return lldb_private::Declaration::Compare(*lhs_ptr, *rhs_ptr) == 0;
128 
129  return lhs_ptr == rhs_ptr;
130 }
131 
132 bool SBDeclaration::operator!=(const SBDeclaration &rhs) const {
134  bool, SBDeclaration, operator!=,(const lldb::SBDeclaration &), rhs);
135 
136  lldb_private::Declaration *lhs_ptr = m_opaque_up.get();
137  lldb_private::Declaration *rhs_ptr = rhs.m_opaque_up.get();
138 
139  if (lhs_ptr && rhs_ptr)
140  return lldb_private::Declaration::Compare(*lhs_ptr, *rhs_ptr) != 0;
141 
142  return lhs_ptr != rhs_ptr;
143 }
144 
145 const lldb_private::Declaration *SBDeclaration::operator->() const {
146  return m_opaque_up.get();
147 }
148 
149 lldb_private::Declaration &SBDeclaration::ref() {
150  if (m_opaque_up == NULL)
151  m_opaque_up.reset(new lldb_private::Declaration());
152  return *m_opaque_up;
153 }
154 
155 const lldb_private::Declaration &SBDeclaration::ref() const {
156  return *m_opaque_up;
157 }
158 
161  description);
162 
163  Stream &strm = description.ref();
164 
165  if (m_opaque_up) {
166  char file_path[PATH_MAX * 2];
167  m_opaque_up->GetFile().GetPath(file_path, sizeof(file_path));
168  strm.Printf("%s:%u", file_path, GetLine());
169  if (GetColumn() > 0)
170  strm.Printf(":%u", GetColumn());
171  } else
172  strm.PutCString("No value");
173 
174  return true;
175 }
176 
177 lldb_private::Declaration *SBDeclaration::get() { return m_opaque_up.get(); }
178 
179 namespace lldb_private {
180 namespace repro {
181 
182 template <>
187  const lldb::SBDeclaration &,
188  SBDeclaration, operator=,(const lldb::SBDeclaration &));
190  LLDB_REGISTER_METHOD_CONST(bool, SBDeclaration, operator bool, ());
192  ());
199  bool, SBDeclaration, operator==,(const lldb::SBDeclaration &));
201  bool, SBDeclaration, operator!=,(const lldb::SBDeclaration &));
203  (lldb::SBStream &));
204 }
205 
206 }
207 }
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:61
The registry contains a unique mapping between functions and their ID.
void SetFile(const FileSpec &file_spec)
Set accessor for the declaration file specification.
Definition: Declaration.h:190
void SetColumn(uint32_t column)
Set accessor for the declaration column number.
Definition: Declaration.h:180
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
const lldb::SBDeclaration & operator=(const lldb::SBDeclaration &rhs)
void SetFileSpec(lldb::SBFileSpec filespec)
static int Compare(const Declaration &lhs, const Declaration &rhs)
Compare two declaration objects.
Definition: Declaration.cpp:69
A file utility class.
Definition: FileSpec.h:55
bool GetDescription(lldb::SBStream &description)
bool IsValid() const
bool IsValid() const
Definition: SBFileSpec.cpp:79
lldb::SBFileSpec GetFileSpec() const
#define LLDB_REGISTER_CONSTRUCTOR(Class, Signature)
bool operator!=(const lldb::SBDeclaration &rhs) const
void RegisterMethods< SBDeclaration >(Registry &R)
std::unique_ptr< T > clone(const std::unique_ptr< T > &src)
Definition: Utils.h:17
uint32_t GetColumn() const
#define LLDB_RECORD_CONSTRUCTOR(Class, Signature,...)
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature,...)
uint32_t GetLine() const
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:106
void SetColumn(uint32_t column)
lldb_private::Stream & ref()
Definition: SBStream.cpp:162
#define LLDB_RECORD_METHOD_CONST(Result, Class, Method, Signature,...)
lldb_private::Declaration * get()
bool operator==(const lldb::SBDeclaration &rhs) const
Definition: SBAddress.h:15
#define PATH_MAX
#define LLDB_REGISTER_METHOD(Result, Class, Method, Signature)
#define LLDB_RECORD_METHOD_CONST_NO_ARGS(Result, Class, Method)
void SetLine(uint32_t line)
Set accessor for the declaration line number.
Definition: Declaration.h:197
A class that describes the declaration location of a lldb object.
Definition: Declaration.h:24
void SetLine(uint32_t line)
#define LLDB_RECORD_RESULT(Result)
#define LLDB_REGISTER_METHOD_CONST(Result, Class, Method, Signature)