LLDB  mainline
SBSourceManager.cpp
Go to the documentation of this file.
1 //===-- SBSourceManager.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 "SBReproducerPrivate.h"
11 #include "lldb/API/SBDebugger.h"
12 #include "lldb/API/SBStream.h"
13 #include "lldb/API/SBTarget.h"
14 
15 #include "lldb/API/SBFileSpec.h"
16 #include "lldb/Core/Debugger.h"
18 #include "lldb/Core/StreamFile.h"
19 #include "lldb/Utility/Stream.h"
20 
21 #include "lldb/Target/Target.h"
22 
23 namespace lldb_private {
25 public:
26  SourceManagerImpl(const lldb::DebuggerSP &debugger_sp)
27  : m_debugger_wp(debugger_sp), m_target_wp() {}
28 
29  SourceManagerImpl(const lldb::TargetSP &target_sp)
30  : m_debugger_wp(), m_target_wp(target_sp) {}
31 
33  if (&rhs == this)
34  return;
37  }
38 
40  uint32_t line, uint32_t column,
41  uint32_t context_before,
42  uint32_t context_after,
43  const char *current_line_cstr,
45  if (!file)
46  return 0;
47 
48  lldb::TargetSP target_sp(m_target_wp.lock());
49  if (target_sp) {
50  return target_sp->GetSourceManager().DisplaySourceLinesWithLineNumbers(
51  file, line, column, context_before, context_after, current_line_cstr,
52  s);
53  } else {
54  lldb::DebuggerSP debugger_sp(m_debugger_wp.lock());
55  if (debugger_sp) {
56  return debugger_sp->GetSourceManager()
57  .DisplaySourceLinesWithLineNumbers(file, line, column,
58  context_before, context_after,
59  current_line_cstr, s);
60  }
61  }
62  return 0;
63  }
64 
65 private:
66  lldb::DebuggerWP m_debugger_wp;
67  lldb::TargetWP m_target_wp;
68 };
69 }
70 
71 using namespace lldb;
72 using namespace lldb_private;
73 
76  debugger);
77 
78  m_opaque_up = std::make_unique<SourceManagerImpl>(debugger.get_sp());
79 }
80 
83 
84  m_opaque_up = std::make_unique<SourceManagerImpl>(target.GetSP());
85 }
86 
89  rhs);
90 
91  if (&rhs == this)
92  return;
93 
94  m_opaque_up = std::make_unique<SourceManagerImpl>(*(rhs.m_opaque_up.get()));
95 }
96 
100  SBSourceManager, operator=,(const lldb::SBSourceManager &),
101  rhs);
102 
103  m_opaque_up = std::make_unique<SourceManagerImpl>(*(rhs.m_opaque_up.get()));
104  return LLDB_RECORD_RESULT(*this);
105 }
106 
108 
110  const SBFileSpec &file, uint32_t line, uint32_t context_before,
111  uint32_t context_after, const char *current_line_cstr, SBStream &s) {
112  LLDB_RECORD_METHOD(size_t, SBSourceManager, DisplaySourceLinesWithLineNumbers,
114  const char *, lldb::SBStream &),
115  file, line, context_before, context_after,
116  current_line_cstr, s);
117 
118  const uint32_t column = 0;
119  return DisplaySourceLinesWithLineNumbersAndColumn(
120  file.ref(), line, column, context_before, context_after,
121  current_line_cstr, s);
122 }
123 
125  const SBFileSpec &file, uint32_t line, uint32_t column,
126  uint32_t context_before, uint32_t context_after,
127  const char *current_line_cstr, SBStream &s) {
129  size_t, SBSourceManager, DisplaySourceLinesWithLineNumbersAndColumn,
131  const char *, lldb::SBStream &),
132  file, line, column, context_before, context_after, current_line_cstr, s);
133 
134  if (m_opaque_up == nullptr)
135  return 0;
136 
137  return m_opaque_up->DisplaySourceLinesWithLineNumbers(
138  file.ref(), line, column, context_before, context_after,
139  current_line_cstr, s.get());
140 }
141 
142 namespace lldb_private {
143 namespace repro {
144 
145 template <>
151  const lldb::SBSourceManager &,
152  SBSourceManager, operator=,(const lldb::SBSourceManager &));
154  DisplaySourceLinesWithLineNumbers,
156  uint32_t, const char *, lldb::SBStream &));
158  DisplaySourceLinesWithLineNumbersAndColumn,
160  uint32_t, uint32_t, const char *, lldb::SBStream &));
161 }
162 
163 }
164 }
lldb::SBSourceManager::DisplaySourceLinesWithLineNumbersAndColumn
size_t DisplaySourceLinesWithLineNumbersAndColumn(const lldb::SBFileSpec &file, uint32_t line, uint32_t column, uint32_t context_before, uint32_t context_after, const char *current_line_cstr, lldb::SBStream &s)
Definition: SBSourceManager.cpp:124
LLDB_RECORD_RESULT
#define LLDB_RECORD_RESULT(Result)
Definition: ReproducerInstrumentation.h:211
lldb::SBSourceManager::~SBSourceManager
~SBSourceManager()
SourceManager.h
lldb_private::Stream
Definition: Stream.h:28
SBReproducerPrivate.h
LLDB_REGISTER_CONSTRUCTOR
#define LLDB_REGISTER_CONSTRUCTOR(Class, Signature)
Definition: ReproducerInstrumentation.h:89
Debugger.h
SBSourceManager.h
Target.h
lldb::SBTarget
Definition: SBTarget.h:29
lldb_private::FileSpec
Definition: FileSpec.h:56
SBStream.h
lldb_private::SourceManagerImpl::m_target_wp
lldb::TargetWP m_target_wp
Definition: SBSourceManager.cpp:67
lldb::SBStream::get
lldb_private::Stream * get()
Definition: SBStream.cpp:176
LLDB_RECORD_METHOD
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature,...)
Definition: ReproducerInstrumentation.h:158
lldb::SBDebugger
Definition: SBDebugger.h:34
lldb::SBSourceManager::operator=
const lldb::SBSourceManager & operator=(const lldb::SBSourceManager &rhs)
Definition: SBSourceManager.cpp:98
SBFileSpec.h
lldb::SBFileSpec::ref
const lldb_private::FileSpec & ref() const
Definition: SBFileSpec.cpp:168
SBDebugger.h
lldb::SBSourceManager::SBSourceManager
SBSourceManager(const SBDebugger &debugger)
Definition: SBSourceManager.cpp:74
LLDB_RECORD_CONSTRUCTOR
#define LLDB_RECORD_CONSTRUCTOR(Class, Signature,...)
Definition: ReproducerInstrumentation.h:133
StreamFile.h
lldb_private::repro::Registry
The registry contains a unique mapping between functions and their ID.
Definition: ReproducerInstrumentation.h:517
lldb_private::SourceManagerImpl::SourceManagerImpl
SourceManagerImpl(const lldb::DebuggerSP &debugger_sp)
Definition: SBSourceManager.cpp:26
uint32_t
lldb_private::SourceManagerImpl::m_debugger_wp
lldb::DebuggerWP m_debugger_wp
Definition: SBSourceManager.cpp:66
lldb_private::SourceManagerImpl::SourceManagerImpl
SourceManagerImpl(const SourceManagerImpl &rhs)
Definition: SBSourceManager.cpp:32
lldb::SBSourceManager::DisplaySourceLinesWithLineNumbers
size_t DisplaySourceLinesWithLineNumbers(const lldb::SBFileSpec &file, uint32_t line, uint32_t context_before, uint32_t context_after, const char *current_line_cstr, lldb::SBStream &s)
Definition: SBSourceManager.cpp:109
lldb::SBFileSpec
Definition: SBFileSpec.h:16
lldb_private::SourceManagerImpl
Definition: SBSourceManager.cpp:24
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::SourceManagerImpl::SourceManagerImpl
SourceManagerImpl(const lldb::TargetSP &target_sp)
Definition: SBSourceManager.cpp:29
lldb_private::SourceManagerImpl::DisplaySourceLinesWithLineNumbers
size_t DisplaySourceLinesWithLineNumbers(const lldb_private::FileSpec &file, uint32_t line, uint32_t column, uint32_t context_before, uint32_t context_after, const char *current_line_cstr, lldb_private::Stream *s)
Definition: SBSourceManager.cpp:39
lldb::SBTarget::GetSP
lldb::TargetSP GetSP() const
Definition: SBTarget.cpp:605
lldb::SBSourceManager::m_opaque_up
std::unique_ptr< lldb_private::SourceManagerImpl > m_opaque_up
Definition: SBSourceManager.h:42
Stream.h
lldb::SBDebugger::get_sp
const lldb::DebuggerSP & get_sp() const
Definition: SBDebugger.cpp:1285
lldb::SBStream
Definition: SBStream.h:18
lldb_private::repro::RegisterMethods< SBSourceManager >
void RegisterMethods< SBSourceManager >(Registry &R)
Definition: SBSourceManager.cpp:146
SBTarget.h
lldb
Definition: SBAddress.h:15
LLDB_REGISTER_METHOD
#define LLDB_REGISTER_METHOD(Result, Class, Method, Signature)
Definition: ReproducerInstrumentation.h:93
lldb::SBSourceManager
Definition: SBSourceManager.h:18