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"
13#include "lldb/Host/PosixApi.h"
15#include "lldb/Utility/Stream.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<Declaration>(*lldb_object_ptr);
33}
34
36 LLDB_INSTRUMENT_VA(this, rhs);
37
38 if (this != &rhs)
40 return *this;
41}
42
44 const lldb_private::Declaration &lldb_object_ref) {
45 ref() = lldb_object_ref;
46}
47
49
52 return this->operator bool();
53}
54SBDeclaration::operator bool() const {
56
57 return m_opaque_up.get() && m_opaque_up->IsValid();
58}
59
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
70uint32_t SBDeclaration::GetLine() const {
72
73 uint32_t line = 0;
74 if (m_opaque_up)
75 line = m_opaque_up->GetLine();
76
77
78 return line;
79}
80
81uint32_t SBDeclaration::GetColumn() const {
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}
97void SBDeclaration::SetLine(uint32_t line) {
98 LLDB_INSTRUMENT_VA(this, line);
99
100 ref().SetLine(line);
101}
102
103void SBDeclaration::SetColumn(uint32_t column) {
104 LLDB_INSTRUMENT_VA(this, column);
105
106 ref().SetColumn(column);
107}
108
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
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
#define LLDB_INSTRUMENT_VA(...)
void SetColumn(uint32_t column)
bool GetDescription(lldb::SBStream &description)
const lldb_private::Declaration * operator->() const
void SetLine(uint32_t line)
lldb_private::Declaration * get()
lldb_private::Declaration & ref()
uint32_t GetLine() const
bool operator==(const lldb::SBDeclaration &rhs) const
bool IsValid() const
uint32_t GetColumn() const
void SetFileSpec(lldb::SBFileSpec filespec)
lldb::SBFileSpec GetFileSpec() const
bool operator!=(const lldb::SBDeclaration &rhs) const
std::unique_ptr< lldb_private::Declaration > m_opaque_up
Definition: SBDeclaration.h:66
const lldb::SBDeclaration & operator=(const lldb::SBDeclaration &rhs)
void SetDeclaration(const lldb_private::Declaration &lldb_object_ref)
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_private::Stream & ref()
Definition: SBStream.cpp:177
A class that describes the declaration location of a lldb object.
Definition: Declaration.h:24
void SetLine(uint32_t line)
Set accessor for the declaration line number.
Definition: Declaration.h:172
void SetColumn(uint16_t column)
Set accessor for the declaration column number.
Definition: Declaration.h:179
void SetFile(const FileSpec &file_spec)
Set accessor for the declaration file specification.
Definition: Declaration.h:165
static int Compare(const Declaration &lhs, const Declaration &rhs)
Compare two declaration objects.
Definition: Declaration.cpp:58
A file utility class.
Definition: FileSpec.h:56
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
#define PATH_MAX