LLDB  mainline
SBSourceManager.cpp
Go to the documentation of this file.
1 //===-- SBSourceManager.cpp -------------------------------------*- C++ -*-===//
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;
35  m_debugger_wp = rhs.m_debugger_wp;
36  m_target_wp = rhs.m_target_wp;
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.reset(new SourceManagerImpl(debugger.get_sp()));
79 }
80 
83 
84  m_opaque_up.reset(new SourceManagerImpl(target.GetSP()));
85 }
86 
89  rhs);
90 
91  if (&rhs == this)
92  return;
93 
94  m_opaque_up.reset(new SourceManagerImpl(*(rhs.m_opaque_up.get())));
95 }
96 
97 const lldb::SBSourceManager &SBSourceManager::
98 operator=(const lldb::SBSourceManager &rhs) {
100  SBSourceManager, operator=,(const lldb::SBSourceManager &),
101  rhs);
102 
103  m_opaque_up.reset(new SourceManagerImpl(*(rhs.m_opaque_up.get())));
104  return LLDB_RECORD_RESULT(*this);
105 }
106 
107 SBSourceManager::~SBSourceManager() {}
108 
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) {
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 
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,
131  const char *, lldb::SBStream &),
132  file, line, column, context_before, context_after, current_line_cstr, s);
133 
134  if (m_opaque_up == NULL)
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 &));
156  uint32_t, const char *, lldb::SBStream &));
158  DisplaySourceLinesWithLineNumbersAndColumn,
160  uint32_t, uint32_t, const char *, lldb::SBStream &));
161 }
162 
163 }
164 }
The registry contains a unique mapping between functions and their ID.
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
SourceManagerImpl(const lldb::DebuggerSP &debugger_sp)
A file utility class.
Definition: FileSpec.h:55
SourceManagerImpl(const SourceManagerImpl &rhs)
SourceManagerImpl(const lldb::TargetSP &target_sp)
#define LLDB_REGISTER_CONSTRUCTOR(Class, Signature)
lldb::TargetSP GetSP() const
Definition: SBTarget.cpp:600
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)
#define LLDB_RECORD_CONSTRUCTOR(Class, Signature,...)
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature,...)
void RegisterMethods< SBSourceManager >(Registry &R)
Definition: SBAddress.h:15
lldb_private::Stream * get()
Definition: SBStream.cpp:160
#define LLDB_REGISTER_METHOD(Result, Class, Method, Signature)
class LLDB_API SBSourceManager
Definition: SBDefines.h:65
#define LLDB_RECORD_RESULT(Result)