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 
9 #include "lldb/API/SBLineEntry.h"
10 #include "Utils.h"
11 #include "lldb/API/SBStream.h"
12 #include "lldb/Host/PosixApi.h"
13 #include "lldb/Symbol/LineEntry.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<LineEntry>(*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 
43 void SBLineEntry::SetLineEntry(const lldb_private::LineEntry &lldb_object_ref) {
44  m_opaque_up = std::make_unique<LineEntry>(lldb_object_ref);
45 }
46 
47 SBLineEntry::~SBLineEntry() = default;
48 
50  LLDB_INSTRUMENT_VA(this);
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 
60  LLDB_INSTRUMENT_VA(this);
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 
70 bool SBLineEntry::IsValid() const {
71  LLDB_INSTRUMENT_VA(this);
72  return this->operator bool();
73 }
74 SBLineEntry::operator bool() const {
75  LLDB_INSTRUMENT_VA(this);
76 
77  return m_opaque_up.get() && m_opaque_up->IsValid();
78 }
79 
81  LLDB_INSTRUMENT_VA(this);
82 
83  SBFileSpec sb_file_spec;
84  if (m_opaque_up.get() && m_opaque_up->file)
85  sb_file_spec.SetFileSpec(m_opaque_up->file);
86 
87  return sb_file_spec;
88 }
89 
91  LLDB_INSTRUMENT_VA(this);
92 
93  uint32_t line = 0;
94  if (m_opaque_up)
95  line = m_opaque_up->line;
96 
97  return line;
98 }
99 
101  LLDB_INSTRUMENT_VA(this);
102 
103  if (m_opaque_up)
104  return m_opaque_up->column;
105  return 0;
106 }
107 
109  LLDB_INSTRUMENT_VA(this, filespec);
110 
111  if (filespec.IsValid())
112  ref().file = filespec.ref();
113  else
114  ref().file.Clear();
115 }
117  LLDB_INSTRUMENT_VA(this, line);
118 
119  ref().line = line;
120 }
121 
123  LLDB_INSTRUMENT_VA(this, column);
124 
125  ref().line = column;
126 }
127 
128 bool SBLineEntry::operator==(const SBLineEntry &rhs) const {
129  LLDB_INSTRUMENT_VA(this, rhs);
130 
131  lldb_private::LineEntry *lhs_ptr = m_opaque_up.get();
132  lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_up.get();
133 
134  if (lhs_ptr && rhs_ptr)
135  return lldb_private::LineEntry::Compare(*lhs_ptr, *rhs_ptr) == 0;
136 
137  return lhs_ptr == rhs_ptr;
138 }
139 
140 bool SBLineEntry::operator!=(const SBLineEntry &rhs) const {
141  LLDB_INSTRUMENT_VA(this, rhs);
142 
143  lldb_private::LineEntry *lhs_ptr = m_opaque_up.get();
144  lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_up.get();
145 
146  if (lhs_ptr && rhs_ptr)
147  return lldb_private::LineEntry::Compare(*lhs_ptr, *rhs_ptr) != 0;
148 
149  return lhs_ptr != rhs_ptr;
150 }
151 
153  return m_opaque_up.get();
154 }
155 
157  if (m_opaque_up == nullptr)
158  m_opaque_up = std::make_unique<lldb_private::LineEntry>();
159  return *m_opaque_up;
160 }
161 
162 const lldb_private::LineEntry &SBLineEntry::ref() const { return *m_opaque_up; }
163 
165  LLDB_INSTRUMENT_VA(this, description);
166 
167  Stream &strm = description.ref();
168 
169  if (m_opaque_up) {
170  char file_path[PATH_MAX * 2];
171  m_opaque_up->file.GetPath(file_path, sizeof(file_path));
172  strm.Printf("%s:%u", file_path, GetLine());
173  if (GetColumn() > 0)
174  strm.Printf(":%u", GetColumn());
175  } else
176  strm.PutCString("No value");
177 
178  return true;
179 }
180 
181 lldb_private::LineEntry *SBLineEntry::get() { return m_opaque_up.get(); }
Instrumentation.h
SBLineEntry.h
lldb::SBLineEntry::operator=
const lldb::SBLineEntry & operator=(const lldb::SBLineEntry &rhs)
Definition: SBLineEntry.cpp:35
lldb_private::LineEntry::Compare
static int Compare(const LineEntry &lhs, const LineEntry &rhs)
Compare two LineEntry objects.
Definition: LineEntry.cpp:157
lldb::SBLineEntry::SetColumn
void SetColumn(uint32_t column)
Definition: SBLineEntry.cpp:122
lldb::SBStream::ref
lldb_private::Stream & ref()
Definition: SBStream.cpp:176
lldb::SBLineEntry::GetColumn
uint32_t GetColumn() const
Definition: SBLineEntry.cpp:100
lldb::SBLineEntry::GetStartAddress
lldb::SBAddress GetStartAddress() const
Definition: SBLineEntry.cpp:49
lldb::SBLineEntry::operator!=
bool operator!=(const lldb::SBLineEntry &rhs) const
Definition: SBLineEntry.cpp:140
lldb_private::Stream
Definition: Stream.h:28
lldb::SBAddress::SetAddress
void SetAddress(lldb::SBSection section, lldb::addr_t offset)
Definition: SBAddress.cpp:88
lldb::SBLineEntry::GetLine
uint32_t GetLine() const
Definition: SBLineEntry.cpp:90
lldb::SBFileSpec::SetFileSpec
void SetFileSpec(const lldb_private::FileSpec &fspec)
Definition: SBFileSpec.cpp:164
lldb::SBLineEntry::operator->
const lldb_private::LineEntry * operator->() const
Definition: SBLineEntry.cpp:152
lldb::SBAddress::OffsetAddress
bool OffsetAddress(addr_t offset)
Definition: SBAddress.cpp:139
SBStream.h
lldb::SBLineEntry::ref
lldb_private::LineEntry & ref()
Definition: SBLineEntry.cpp:156
lldb_private::clone
std::unique_ptr< T > clone(const std::unique_ptr< T > &src)
Definition: Utils.h:17
Utils.h
LineEntry.h
lldb::SBLineEntry::SBLineEntry
SBLineEntry()
Definition: SBLineEntry.cpp:22
lldb::SBLineEntry::GetFileSpec
lldb::SBFileSpec GetFileSpec() const
Definition: SBLineEntry.cpp:80
StreamString.h
lldb::SBLineEntry::IsValid
bool IsValid() const
Definition: SBLineEntry.cpp:70
lldb::SBLineEntry::GetEndAddress
lldb::SBAddress GetEndAddress() const
Definition: SBLineEntry.cpp:59
lldb::SBLineEntry::SetLine
void SetLine(uint32_t line)
Definition: SBLineEntry.cpp:116
lldb::SBFileSpec::ref
const lldb_private::FileSpec & ref() const
Definition: SBFileSpec.cpp:162
lldb::SBFileSpec::IsValid
bool IsValid() const
Definition: SBFileSpec.cpp:76
lldb::SBLineEntry::m_opaque_up
std::unique_ptr< lldb_private::LineEntry > m_opaque_up
Definition: SBLineEntry.h:73
lldb_private::FileSpec::Clear
void Clear()
Clears the object state.
Definition: FileSpec.cpp:259
lldb::SBLineEntry::SetFileSpec
void SetFileSpec(lldb::SBFileSpec filespec)
Definition: SBLineEntry.cpp:108
uint32_t
lldb::SBLineEntry::operator==
bool operator==(const lldb::SBLineEntry &rhs) const
Definition: SBLineEntry.cpp:128
lldb::SBFileSpec
Definition: SBFileSpec.h:16
lldb::SBLineEntry
Definition: SBLineEntry.h:18
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::SBAddress
Definition: SBAddress.h:17
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
PosixApi.h
LLDB_INSTRUMENT_VA
#define LLDB_INSTRUMENT_VA(...)
Definition: Instrumentation.h:98
lldb::SBLineEntry::SetLineEntry
void SetLineEntry(const lldb_private::LineEntry &lldb_object_ref)
Definition: SBLineEntry.cpp:43
lldb::SBLineEntry::GetDescription
bool GetDescription(lldb::SBStream &description)
Definition: SBLineEntry.cpp:164
lldb_private::Stream::PutCString
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:63
lldb::SBStream
Definition: SBStream.h:18
PATH_MAX
#define PATH_MAX
Definition: windows/PosixApi.h:25
lldb
Definition: SBAddress.h:15
lldb_private::LineEntry
Definition: LineEntry.h:20
lldb::SBLineEntry::get
lldb_private::LineEntry * get()
Definition: SBLineEntry.cpp:181
lldb::SBLineEntry::~SBLineEntry
~SBLineEntry()