1 //===-- SBSourceManager.cpp -------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/API/SBSourceManager.h"
10 #include "SBReproducerPrivate.h"
11 #include "lldb/API/SBDebugger.h"
12 #include "lldb/API/SBStream.h"
13 #include "lldb/API/SBTarget.h"
15 #include "lldb/API/SBFileSpec.h"
16 #include "lldb/Core/Debugger.h"
17 #include "lldb/Core/SourceManager.h"
18 #include "lldb/Core/StreamFile.h"
19 #include "lldb/Utility/Stream.h"
21 #include "lldb/Target/Target.h"
23 namespace lldb_private
{
24 class SourceManagerImpl
{
26 SourceManagerImpl(const lldb::DebuggerSP
&debugger_sp
)
27 : m_debugger_wp(debugger_sp
), m_target_wp() {}
29 SourceManagerImpl(const lldb::TargetSP
&target_sp
)
30 : m_debugger_wp(), m_target_wp(target_sp
) {}
32 SourceManagerImpl(const SourceManagerImpl
&rhs
) {
35 m_debugger_wp
= rhs
.m_debugger_wp
;
36 m_target_wp
= rhs
.m_target_wp
;
39 size_t DisplaySourceLinesWithLineNumbers(const lldb_private::FileSpec
&file
,
40 uint32_t line
, uint32_t column
,
41 uint32_t context_before
,
42 uint32_t context_after
,
43 const char *current_line_cstr
,
44 lldb_private::Stream
*s
) {
48 lldb::TargetSP
target_sp(m_target_wp
.lock());
50 return target_sp
->GetSourceManager().DisplaySourceLinesWithLineNumbers(
51 file
, line
, column
, context_before
, context_after
, current_line_cstr
,
54 lldb::DebuggerSP
debugger_sp(m_debugger_wp
.lock());
56 return debugger_sp
->GetSourceManager()
57 .DisplaySourceLinesWithLineNumbers(file
, line
, column
,
58 context_before
, context_after
,
59 current_line_cstr
, s
);
66 lldb::DebuggerWP m_debugger_wp
;
67 lldb::TargetWP m_target_wp
;
72 using namespace lldb_private
;
74 SBSourceManager::SBSourceManager(const SBDebugger
&debugger
) {
75 LLDB_RECORD_CONSTRUCTOR(SBSourceManager
, (const lldb::SBDebugger
&),
78 m_opaque_up
.reset(new SourceManagerImpl(debugger
.get_sp()));
81 SBSourceManager::SBSourceManager(const SBTarget
&target
) {
82 LLDB_RECORD_CONSTRUCTOR(SBSourceManager
, (const lldb::SBTarget
&), target
);
84 m_opaque_up
.reset(new SourceManagerImpl(target
.GetSP()));
87 SBSourceManager::SBSourceManager(const SBSourceManager
&rhs
) {
88 LLDB_RECORD_CONSTRUCTOR(SBSourceManager
, (const lldb::SBSourceManager
&),
94 m_opaque_up
.reset(new SourceManagerImpl(*(rhs
.m_opaque_up
.get())));
97 const lldb::SBSourceManager
&SBSourceManager::
98 operator=(const lldb::SBSourceManager
&rhs
) {
99 LLDB_RECORD_METHOD(const lldb::SBSourceManager
&,
100 SBSourceManager
, operator=,(const lldb::SBSourceManager
&),
103 m_opaque_up
.reset(new SourceManagerImpl(*(rhs
.m_opaque_up
.get())));
104 return LLDB_RECORD_RESULT(*this);
107 SBSourceManager::~SBSourceManager() {}
109 size_t SBSourceManager::DisplaySourceLinesWithLineNumbers(
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
,
113 (const lldb::SBFileSpec
&, uint32_t, uint32_t, uint32_t,
114 const char *, lldb::SBStream
&),
115 file
, line
, context_before
, context_after
,
116 current_line_cstr
, s
);
118 const uint32_t column
= 0;
119 return DisplaySourceLinesWithLineNumbersAndColumn(
120 file
.ref(), line
, column
, context_before
, context_after
,
121 current_line_cstr
, s
);
124 size_t SBSourceManager::DisplaySourceLinesWithLineNumbersAndColumn(
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
,
130 (const lldb::SBFileSpec
&, uint32_t, uint32_t, uint32_t, uint32_t,
131 const char *, lldb::SBStream
&),
132 file
, line
, column
, context_before
, context_after
, current_line_cstr
, s
);
134 if (m_opaque_up
== nullptr)
137 return m_opaque_up
->DisplaySourceLinesWithLineNumbers(
138 file
.ref(), line
, column
, context_before
, context_after
,
139 current_line_cstr
, s
.get());
142 namespace lldb_private
{
146 void RegisterMethods
<SBSourceManager
>(Registry
&R
) {
147 LLDB_REGISTER_CONSTRUCTOR(SBSourceManager
, (const lldb::SBDebugger
&));
148 LLDB_REGISTER_CONSTRUCTOR(SBSourceManager
, (const lldb::SBTarget
&));
149 LLDB_REGISTER_CONSTRUCTOR(SBSourceManager
, (const lldb::SBSourceManager
&));
150 LLDB_REGISTER_METHOD(
151 const lldb::SBSourceManager
&,
152 SBSourceManager
, operator=,(const lldb::SBSourceManager
&));
153 LLDB_REGISTER_METHOD(size_t, SBSourceManager
,
154 DisplaySourceLinesWithLineNumbers
,
155 (const lldb::SBFileSpec
&, uint32_t, uint32_t,
156 uint32_t, const char *, lldb::SBStream
&));
157 LLDB_REGISTER_METHOD(size_t, SBSourceManager
,
158 DisplaySourceLinesWithLineNumbersAndColumn
,
159 (const lldb::SBFileSpec
&, uint32_t, uint32_t,
160 uint32_t, uint32_t, const char *, lldb::SBStream
&));