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"
19#include "lldb/Utility/Stream.h"
20
21#include "lldb/Target/Target.h"
22
23namespace lldb_private {
25public:
26 SourceManagerImpl(const lldb::DebuggerSP &debugger_sp)
27 : m_debugger_wp(debugger_sp) {}
28
29 SourceManagerImpl(const lldb::TargetSP &target_sp) : m_target_wp(target_sp) {}
30
32 if (&rhs == this)
33 return;
36 }
37
39 uint32_t line, uint32_t column,
40 uint32_t context_before,
41 uint32_t context_after,
42 const char *current_line_cstr,
44 if (!file)
45 return 0;
46
47 lldb::TargetSP target_sp(m_target_wp.lock());
48 if (target_sp) {
49 return target_sp->GetSourceManager().DisplaySourceLinesWithLineNumbers(
50 file, line, column, context_before, context_after, current_line_cstr,
51 s);
52 } else {
53 lldb::DebuggerSP debugger_sp(m_debugger_wp.lock());
54 if (debugger_sp) {
55 return debugger_sp->GetSourceManager()
56 .DisplaySourceLinesWithLineNumbers(file, line, column,
57 context_before, context_after,
58 current_line_cstr, s);
59 }
60 }
61 return 0;
62 }
63
64private:
65 lldb::DebuggerWP m_debugger_wp;
66 lldb::TargetWP m_target_wp;
67};
68}
69
70using namespace lldb;
71using namespace lldb_private;
72
74 LLDB_INSTRUMENT_VA(this, debugger);
75
76 m_opaque_up = std::make_unique<SourceManagerImpl>(debugger.get_sp());
77}
78
80 LLDB_INSTRUMENT_VA(this, target);
81
82 m_opaque_up = std::make_unique<SourceManagerImpl>(target.GetSP());
83}
84
86 LLDB_INSTRUMENT_VA(this, rhs);
87
88 if (&rhs == this)
89 return;
90
91 m_opaque_up = std::make_unique<SourceManagerImpl>(*rhs.m_opaque_up);
92}
93
96 LLDB_INSTRUMENT_VA(this, rhs);
97
98 m_opaque_up = std::make_unique<SourceManagerImpl>(*rhs.m_opaque_up);
99 return *this;
100}
101
103
105 const SBFileSpec &file, uint32_t line, uint32_t context_before,
106 uint32_t context_after, const char *current_line_cstr, SBStream &s) {
107 LLDB_INSTRUMENT_VA(this, file, line, context_before, context_after,
108 current_line_cstr, s);
109
110 const uint32_t column = 0;
112 file.ref(), line, column, context_before, context_after,
113 current_line_cstr, s);
114}
115
117 const SBFileSpec &file, uint32_t line, uint32_t column,
118 uint32_t context_before, uint32_t context_after,
119 const char *current_line_cstr, SBStream &s) {
120 LLDB_INSTRUMENT_VA(this, file, line, column, context_before, context_after,
121 current_line_cstr, s);
122
123 if (m_opaque_up == nullptr)
124 return 0;
125
126 return m_opaque_up->DisplaySourceLinesWithLineNumbers(
127 file.ref(), line, column, context_before, context_after,
128 current_line_cstr, s.get());
129}
#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:174
lldb::TargetSP GetSP() const
Definition: SBTarget.cpp:577
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: SBAttachInfo.h:14
Definition: SBAddress.h:15