1 //===-- SBSourceManager.cpp -----------------------------------------------===//
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 "lldb/API/SBDebugger.h"
11 #include "lldb/API/SBStream.h"
12 #include "lldb/API/SBTarget.h"
13 #include "lldb/Utility/Instrumentation.h"
15 #include "lldb/API/SBFileSpec.h"
16 #include "lldb/Core/Debugger.h"
17 #include "lldb/Core/SourceManager.h"
18 #include "lldb/Utility/Stream.h"
20 #include "lldb/Target/Target.h"
22 namespace lldb_private
{
23 class SourceManagerImpl
{
25 SourceManagerImpl(const lldb::DebuggerSP
&debugger_sp
)
26 : m_debugger_wp(debugger_sp
) {}
28 SourceManagerImpl(const lldb::TargetSP
&target_sp
) : m_target_wp(target_sp
) {}
30 SourceManagerImpl(const SourceManagerImpl
&rhs
) {
33 m_debugger_wp
= rhs
.m_debugger_wp
;
34 m_target_wp
= rhs
.m_target_wp
;
37 size_t DisplaySourceLinesWithLineNumbers(const lldb_private::FileSpec
&file
,
38 uint32_t line
, uint32_t column
,
39 uint32_t context_before
,
40 uint32_t context_after
,
41 const char *current_line_cstr
,
42 lldb_private::Stream
*s
) {
46 lldb::TargetSP
target_sp(m_target_wp
.lock());
48 return target_sp
->GetSourceManager().DisplaySourceLinesWithLineNumbers(
49 std::make_shared
<SupportFile
>(file
), line
, column
, context_before
,
50 context_after
, current_line_cstr
, s
);
52 lldb::DebuggerSP
debugger_sp(m_debugger_wp
.lock());
54 return debugger_sp
->GetSourceManager()
55 .DisplaySourceLinesWithLineNumbers(
56 std::make_shared
<SupportFile
>(file
), line
, column
,
57 context_before
, context_after
, current_line_cstr
, s
);
64 lldb::DebuggerWP m_debugger_wp
;
65 lldb::TargetWP m_target_wp
;
70 using namespace lldb_private
;
72 SBSourceManager::SBSourceManager(const SBDebugger
&debugger
) {
73 LLDB_INSTRUMENT_VA(this, debugger
);
75 m_opaque_up
= std::make_unique
<SourceManagerImpl
>(debugger
.get_sp());
78 SBSourceManager::SBSourceManager(const SBTarget
&target
) {
79 LLDB_INSTRUMENT_VA(this, target
);
81 m_opaque_up
= std::make_unique
<SourceManagerImpl
>(target
.GetSP());
84 SBSourceManager::SBSourceManager(const SBSourceManager
&rhs
) {
85 LLDB_INSTRUMENT_VA(this, rhs
);
90 m_opaque_up
= std::make_unique
<SourceManagerImpl
>(*rhs
.m_opaque_up
);
93 const lldb::SBSourceManager
&SBSourceManager::
94 operator=(const lldb::SBSourceManager
&rhs
) {
95 LLDB_INSTRUMENT_VA(this, rhs
);
97 m_opaque_up
= std::make_unique
<SourceManagerImpl
>(*rhs
.m_opaque_up
);
101 SBSourceManager::~SBSourceManager() = default;
103 size_t SBSourceManager::DisplaySourceLinesWithLineNumbers(
104 const SBFileSpec
&file
, uint32_t line
, uint32_t context_before
,
105 uint32_t context_after
, const char *current_line_cstr
, SBStream
&s
) {
106 LLDB_INSTRUMENT_VA(this, file
, line
, context_before
, context_after
,
107 current_line_cstr
, s
);
109 const uint32_t column
= 0;
110 return DisplaySourceLinesWithLineNumbersAndColumn(
111 file
.ref(), line
, column
, context_before
, context_after
,
112 current_line_cstr
, s
);
115 size_t SBSourceManager::DisplaySourceLinesWithLineNumbersAndColumn(
116 const SBFileSpec
&file
, uint32_t line
, uint32_t column
,
117 uint32_t context_before
, uint32_t context_after
,
118 const char *current_line_cstr
, SBStream
&s
) {
119 LLDB_INSTRUMENT_VA(this, file
, line
, column
, context_before
, context_after
,
120 current_line_cstr
, s
);
122 if (m_opaque_up
== nullptr)
125 return m_opaque_up
->DisplaySourceLinesWithLineNumbers(
126 file
.ref(), line
, column
, context_before
, context_after
,
127 current_line_cstr
, s
.get());