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 "lldb/API/SBDebugger.h"
11#include "lldb/API/SBStream.h"
12#include "lldb/API/SBTarget.h"
14
15#include "lldb/API/SBFileSpec.h"
16#include "lldb/Core/Debugger.h"
18#include "lldb/Utility/Stream.h"
19
20#include "lldb/Target/Target.h"
21
22namespace lldb_private {
24public:
26 : m_debugger_wp(debugger_sp) {}
27
28 SourceManagerImpl(const lldb::TargetSP &target_sp) : m_target_wp(target_sp) {}
29
31 if (&rhs == this)
32 return;
35 }
36
38 uint32_t line, uint32_t column,
39 uint32_t context_before,
40 uint32_t context_after,
41 const char *current_line_cstr,
43 if (!file)
44 return 0;
45
46 lldb::TargetSP target_sp(m_target_wp.lock());
47 if (target_sp) {
48 return target_sp->GetSourceManager().DisplaySourceLinesWithLineNumbers(
49 file, line, column, context_before, context_after, current_line_cstr,
50 s);
51 } else {
52 lldb::DebuggerSP debugger_sp(m_debugger_wp.lock());
53 if (debugger_sp) {
54 return debugger_sp->GetSourceManager()
55 .DisplaySourceLinesWithLineNumbers(file, line, column,
56 context_before, context_after,
57 current_line_cstr, s);
58 }
59 }
60 return 0;
61 }
62
63private:
66};
67}
68
69using namespace lldb;
70using namespace lldb_private;
71
73 LLDB_INSTRUMENT_VA(this, debugger);
74
75 m_opaque_up = std::make_unique<SourceManagerImpl>(debugger.get_sp());
76}
77
79 LLDB_INSTRUMENT_VA(this, target);
80
81 m_opaque_up = std::make_unique<SourceManagerImpl>(target.GetSP());
82}
83
85 LLDB_INSTRUMENT_VA(this, rhs);
86
87 if (&rhs == this)
88 return;
89
90 m_opaque_up = std::make_unique<SourceManagerImpl>(*rhs.m_opaque_up);
91}
92
95 LLDB_INSTRUMENT_VA(this, rhs);
96
97 m_opaque_up = std::make_unique<SourceManagerImpl>(*rhs.m_opaque_up);
98 return *this;
99}
100
102
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);
108
109 const uint32_t column = 0;
111 file.ref(), line, column, context_before, context_after,
112 current_line_cstr, s);
113}
114
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);
121
122 if (m_opaque_up == nullptr)
123 return 0;
124
125 return m_opaque_up->DisplaySourceLinesWithLineNumbers(
126 file.ref(), line, column, context_before, context_after,
127 current_line_cstr, s.get());
128}
#define LLDB_INSTRUMENT_VA(...)
const lldb::DebuggerSP & get_sp() const
const lldb_private::FileSpec & ref() const
Definition: SBFileSpec.cpp:162
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)
std::unique_ptr< lldb_private::SourceManagerImpl > m_opaque_up
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)
SBSourceManager(const SBDebugger &debugger)
const lldb::SBSourceManager & operator=(const lldb::SBSourceManager &rhs)
lldb_private::Stream * get()
Definition: SBStream.cpp:175
lldb::TargetSP GetSP() const
Definition: SBTarget.cpp:585
A file utility class.
Definition: FileSpec.h:56
SourceManagerImpl(const SourceManagerImpl &rhs)
SourceManagerImpl(const lldb::TargetSP &target_sp)
SourceManagerImpl(const lldb::DebuggerSP &debugger_sp)
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)
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
std::weak_ptr< lldb_private::Debugger > DebuggerWP
Definition: lldb-forward.h:338
std::shared_ptr< lldb_private::Debugger > DebuggerSP
Definition: lldb-forward.h:337
std::weak_ptr< lldb_private::Target > TargetWP
Definition: lldb-forward.h:445
std::shared_ptr< lldb_private::Target > TargetSP
Definition: lldb-forward.h:444