LLDB  mainline
SBDeclaration.cpp
Go to the documentation of this file.
1 //===-- SBDeclaration.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/Core/Declaration.h"
13 #include "lldb/Host/PosixApi.h"
15 #include "lldb/Utility/Stream.h"
16 
17 #include <climits>
18 
19 using namespace lldb;
20 using namespace lldb_private;
21 
23 
25  LLDB_INSTRUMENT_VA(this, rhs);
26 
27  m_opaque_up = clone(rhs.m_opaque_up);
28 }
29 
31  if (lldb_object_ptr)
32  m_opaque_up = std::make_unique<Declaration>(*lldb_object_ptr);
33 }
34 
36  LLDB_INSTRUMENT_VA(this, rhs);
37 
38  if (this != &rhs)
39  m_opaque_up = clone(rhs.m_opaque_up);
40  return *this;
41 }
42 
44  const lldb_private::Declaration &lldb_object_ref) {
45  ref() = lldb_object_ref;
46 }
47 
49 
50 bool SBDeclaration::IsValid() const {
51  LLDB_INSTRUMENT_VA(this);
52  return this->operator bool();
53 }
54 SBDeclaration::operator bool() const {
55  LLDB_INSTRUMENT_VA(this);
56 
57  return m_opaque_up.get() && m_opaque_up->IsValid();
58 }
59 
61  LLDB_INSTRUMENT_VA(this);
62 
63  SBFileSpec sb_file_spec;
64  if (m_opaque_up.get() && m_opaque_up->GetFile())
65  sb_file_spec.SetFileSpec(m_opaque_up->GetFile());
66 
67  return sb_file_spec;
68 }
69 
71  LLDB_INSTRUMENT_VA(this);
72 
73  uint32_t line = 0;
74  if (m_opaque_up)
75  line = m_opaque_up->GetLine();
76 
77 
78  return line;
79 }
80 
82  LLDB_INSTRUMENT_VA(this);
83 
84  if (m_opaque_up)
85  return m_opaque_up->GetColumn();
86  return 0;
87 }
88 
90  LLDB_INSTRUMENT_VA(this, filespec);
91 
92  if (filespec.IsValid())
93  ref().SetFile(filespec.ref());
94  else
95  ref().SetFile(FileSpec());
96 }
98  LLDB_INSTRUMENT_VA(this, line);
99 
100  ref().SetLine(line);
101 }
102 
104  LLDB_INSTRUMENT_VA(this, column);
105 
106  ref().SetColumn(column);
107 }
108 
109 bool SBDeclaration::operator==(const SBDeclaration &rhs) const {
110  LLDB_INSTRUMENT_VA(this, rhs);
111 
112  lldb_private::Declaration *lhs_ptr = m_opaque_up.get();
113  lldb_private::Declaration *rhs_ptr = rhs.m_opaque_up.get();
114 
115  if (lhs_ptr && rhs_ptr)
116  return lldb_private::Declaration::Compare(*lhs_ptr, *rhs_ptr) == 0;
117 
118  return lhs_ptr == rhs_ptr;
119 }
120 
121 bool SBDeclaration::operator!=(const SBDeclaration &rhs) const {
122  LLDB_INSTRUMENT_VA(this, rhs);
123 
124  lldb_private::Declaration *lhs_ptr = m_opaque_up.get();
125  lldb_private::Declaration *rhs_ptr = rhs.m_opaque_up.get();
126 
127  if (lhs_ptr && rhs_ptr)
128  return lldb_private::Declaration::Compare(*lhs_ptr, *rhs_ptr) != 0;
129 
130  return lhs_ptr != rhs_ptr;
131 }
132 
134  return m_opaque_up.get();
135 }
136 
138  if (m_opaque_up == nullptr)
139  m_opaque_up = std::make_unique<lldb_private::Declaration>();
140  return *m_opaque_up;
141 }
142 
144  return *m_opaque_up;
145 }
146 
148  LLDB_INSTRUMENT_VA(this, description);
149 
150  Stream &strm = description.ref();
151 
152  if (m_opaque_up) {
153  char file_path[PATH_MAX * 2];
154  m_opaque_up->GetFile().GetPath(file_path, sizeof(file_path));
155  strm.Printf("%s:%u", file_path, GetLine());
156  if (GetColumn() > 0)
157  strm.Printf(":%u", GetColumn());
158  } else
159  strm.PutCString("No value");
160 
161  return true;
162 }
163 
164 lldb_private::Declaration *SBDeclaration::get() { return m_opaque_up.get(); }
Instrumentation.h
lldb::SBDeclaration::ref
lldb_private::Declaration & ref()
Definition: SBDeclaration.cpp:137
lldb::SBStream::ref
lldb_private::Stream & ref()
Definition: SBStream.cpp:176
lldb::SBDeclaration::operator->
const lldb_private::Declaration * operator->() const
Definition: SBDeclaration.cpp:133
lldb::SBDeclaration::GetFileSpec
lldb::SBFileSpec GetFileSpec() const
Definition: SBDeclaration.cpp:60
lldb::SBDeclaration::~SBDeclaration
~SBDeclaration()
lldb::SBDeclaration::SetLine
void SetLine(uint32_t line)
Definition: SBDeclaration.cpp:97
lldb::SBDeclaration
Definition: SBDeclaration.h:18
lldb::SBDeclaration::operator=
const lldb::SBDeclaration & operator=(const lldb::SBDeclaration &rhs)
Definition: SBDeclaration.cpp:35
lldb::SBDeclaration::operator==
bool operator==(const lldb::SBDeclaration &rhs) const
Definition: SBDeclaration.cpp:109
lldb_private::Stream
Definition: Stream.h:28
lldb::SBDeclaration::m_opaque_up
std::unique_ptr< lldb_private::Declaration > m_opaque_up
Definition: SBDeclaration.h:66
lldb::SBFileSpec::SetFileSpec
void SetFileSpec(const lldb_private::FileSpec &fspec)
Definition: SBFileSpec.cpp:164
lldb_private::FileSpec
Definition: FileSpec.h:56
SBStream.h
lldb_private::clone
std::unique_ptr< T > clone(const std::unique_ptr< T > &src)
Definition: Utils.h:17
Utils.h
Declaration.h
lldb::SBFileSpec::ref
const lldb_private::FileSpec & ref() const
Definition: SBFileSpec.cpp:162
lldb::SBFileSpec::IsValid
bool IsValid() const
Definition: SBFileSpec.cpp:76
lldb::SBDeclaration::GetDescription
bool GetDescription(lldb::SBStream &description)
Definition: SBDeclaration.cpp:147
SBDeclaration.h
lldb::SBDeclaration::SetColumn
void SetColumn(uint32_t column)
Definition: SBDeclaration.cpp:103
lldb::SBDeclaration::SBDeclaration
SBDeclaration()
Definition: SBDeclaration.cpp:22
lldb::SBDeclaration::IsValid
bool IsValid() const
Definition: SBDeclaration.cpp:50
uint32_t
lldb::SBDeclaration::operator!=
bool operator!=(const lldb::SBDeclaration &rhs) const
Definition: SBDeclaration.cpp:121
lldb::SBDeclaration::SetDeclaration
void SetDeclaration(const lldb_private::Declaration &lldb_object_ref)
Definition: SBDeclaration.cpp:43
lldb::SBDeclaration::GetColumn
uint32_t GetColumn() const
Definition: SBDeclaration.cpp:81
lldb::SBFileSpec
Definition: SBFileSpec.h:16
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
PosixApi.h
lldb::SBDeclaration::GetLine
uint32_t GetLine() const
Definition: SBDeclaration.cpp:70
LLDB_INSTRUMENT_VA
#define LLDB_INSTRUMENT_VA(...)
Definition: Instrumentation.h:98
Stream.h
lldb_private::Stream::PutCString
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:63
lldb::SBDeclaration::SetFileSpec
void SetFileSpec(lldb::SBFileSpec filespec)
Definition: SBDeclaration.cpp:89
lldb::SBStream
Definition: SBStream.h:18
lldb_private::Declaration::Compare
static int Compare(const Declaration &lhs, const Declaration &rhs)
Compare two declaration objects.
Definition: Declaration.cpp:58
PATH_MAX
#define PATH_MAX
Definition: windows/PosixApi.h:25
lldb::SBDeclaration::get
lldb_private::Declaration * get()
Definition: SBDeclaration.cpp:164
lldb_private::Declaration
Definition: Declaration.h:24
lldb
Definition: SBAddress.h:15