1ac7ddfbfSEd Maste //===-- SBSourceManager.cpp -------------------------------------*- C++ -*-===//
2ac7ddfbfSEd Maste //
3ac7ddfbfSEd Maste // The LLVM Compiler Infrastructure
4ac7ddfbfSEd Maste //
5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
7ac7ddfbfSEd Maste //
8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
9ac7ddfbfSEd Maste
10ac7ddfbfSEd Maste #include "lldb/API/SBSourceManager.h"
11435933ddSDimitry Andric #include "lldb/API/SBDebugger.h"
12ac7ddfbfSEd Maste #include "lldb/API/SBStream.h"
13435933ddSDimitry Andric #include "lldb/API/SBTarget.h"
14ac7ddfbfSEd Maste
15ac7ddfbfSEd Maste #include "lldb/API/SBFileSpec.h"
16ac7ddfbfSEd Maste #include "lldb/Core/Debugger.h"
17435933ddSDimitry Andric #include "lldb/Core/SourceManager.h"
18ac7ddfbfSEd Maste #include "lldb/Core/StreamFile.h"
19f678e45dSDimitry Andric #include "lldb/Utility/Stream.h"
20ac7ddfbfSEd Maste
21ac7ddfbfSEd Maste #include "lldb/Target/Target.h"
22ac7ddfbfSEd Maste
23435933ddSDimitry Andric namespace lldb_private {
24435933ddSDimitry Andric class SourceManagerImpl {
25ac7ddfbfSEd Maste public:
SourceManagerImpl(const lldb::DebuggerSP & debugger_sp)26435933ddSDimitry Andric SourceManagerImpl(const lldb::DebuggerSP &debugger_sp)
27435933ddSDimitry Andric : m_debugger_wp(debugger_sp), m_target_wp() {}
28ac7ddfbfSEd Maste
SourceManagerImpl(const lldb::TargetSP & target_sp)29435933ddSDimitry Andric SourceManagerImpl(const lldb::TargetSP &target_sp)
30435933ddSDimitry Andric : m_debugger_wp(), m_target_wp(target_sp) {}
31ac7ddfbfSEd Maste
SourceManagerImpl(const SourceManagerImpl & rhs)32435933ddSDimitry Andric SourceManagerImpl(const SourceManagerImpl &rhs) {
33ac7ddfbfSEd Maste if (&rhs == this)
34ac7ddfbfSEd Maste return;
35ac7ddfbfSEd Maste m_debugger_wp = rhs.m_debugger_wp;
36ac7ddfbfSEd Maste m_target_wp = rhs.m_target_wp;
37ac7ddfbfSEd Maste }
38ac7ddfbfSEd Maste
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)39435933ddSDimitry Andric size_t DisplaySourceLinesWithLineNumbers(const lldb_private::FileSpec &file,
40435933ddSDimitry Andric uint32_t line, uint32_t column,
41ac7ddfbfSEd Maste uint32_t context_before,
42ac7ddfbfSEd Maste uint32_t context_after,
43ac7ddfbfSEd Maste const char *current_line_cstr,
44435933ddSDimitry Andric lldb_private::Stream *s) {
45ac7ddfbfSEd Maste if (!file)
46ac7ddfbfSEd Maste return 0;
47ac7ddfbfSEd Maste
48ac7ddfbfSEd Maste lldb::TargetSP target_sp(m_target_wp.lock());
49435933ddSDimitry Andric if (target_sp) {
50435933ddSDimitry Andric return target_sp->GetSourceManager().DisplaySourceLinesWithLineNumbers(
51435933ddSDimitry Andric file, line, column, context_before, context_after, current_line_cstr,
52ac7ddfbfSEd Maste s);
53435933ddSDimitry Andric } else {
54ac7ddfbfSEd Maste lldb::DebuggerSP debugger_sp(m_debugger_wp.lock());
55435933ddSDimitry Andric if (debugger_sp) {
56435933ddSDimitry Andric return debugger_sp->GetSourceManager()
57435933ddSDimitry Andric .DisplaySourceLinesWithLineNumbers(file, line, column,
58435933ddSDimitry Andric context_before, context_after,
59435933ddSDimitry Andric current_line_cstr, s);
60ac7ddfbfSEd Maste }
61ac7ddfbfSEd Maste }
62ac7ddfbfSEd Maste return 0;
63ac7ddfbfSEd Maste }
64ac7ddfbfSEd Maste
65ac7ddfbfSEd Maste private:
66ac7ddfbfSEd Maste lldb::DebuggerWP m_debugger_wp;
67ac7ddfbfSEd Maste lldb::TargetWP m_target_wp;
68ac7ddfbfSEd Maste };
69ac7ddfbfSEd Maste }
70ac7ddfbfSEd Maste
71ac7ddfbfSEd Maste using namespace lldb;
72ac7ddfbfSEd Maste using namespace lldb_private;
73ac7ddfbfSEd Maste
SBSourceManager(const SBDebugger & debugger)74435933ddSDimitry Andric SBSourceManager::SBSourceManager(const SBDebugger &debugger) {
75ac7ddfbfSEd Maste m_opaque_ap.reset(new SourceManagerImpl(debugger.get_sp()));
76ac7ddfbfSEd Maste }
77ac7ddfbfSEd Maste
SBSourceManager(const SBTarget & target)78435933ddSDimitry Andric SBSourceManager::SBSourceManager(const SBTarget &target) {
79ac7ddfbfSEd Maste m_opaque_ap.reset(new SourceManagerImpl(target.GetSP()));
80ac7ddfbfSEd Maste }
81ac7ddfbfSEd Maste
SBSourceManager(const SBSourceManager & rhs)82435933ddSDimitry Andric SBSourceManager::SBSourceManager(const SBSourceManager &rhs) {
83ac7ddfbfSEd Maste if (&rhs == this)
84ac7ddfbfSEd Maste return;
85ac7ddfbfSEd Maste
86ac7ddfbfSEd Maste m_opaque_ap.reset(new SourceManagerImpl(*(rhs.m_opaque_ap.get())));
87ac7ddfbfSEd Maste }
88ac7ddfbfSEd Maste
89435933ddSDimitry Andric const lldb::SBSourceManager &SBSourceManager::
operator =(const lldb::SBSourceManager & rhs)90435933ddSDimitry Andric operator=(const lldb::SBSourceManager &rhs) {
91ac7ddfbfSEd Maste m_opaque_ap.reset(new SourceManagerImpl(*(rhs.m_opaque_ap.get())));
92ac7ddfbfSEd Maste return *this;
93ac7ddfbfSEd Maste }
94ac7ddfbfSEd Maste
~SBSourceManager()95435933ddSDimitry Andric SBSourceManager::~SBSourceManager() {}
96435933ddSDimitry Andric
DisplaySourceLinesWithLineNumbers(const SBFileSpec & file,uint32_t line,uint32_t context_before,uint32_t context_after,const char * current_line_cstr,SBStream & s)97435933ddSDimitry Andric size_t SBSourceManager::DisplaySourceLinesWithLineNumbers(
98435933ddSDimitry Andric const SBFileSpec &file, uint32_t line, uint32_t context_before,
99435933ddSDimitry Andric uint32_t context_after, const char *current_line_cstr, SBStream &s) {
100435933ddSDimitry Andric const uint32_t column = 0;
101435933ddSDimitry Andric return DisplaySourceLinesWithLineNumbersAndColumn(
102435933ddSDimitry Andric file.ref(), line, column, context_before, context_after,
103435933ddSDimitry Andric current_line_cstr, s);
104ac7ddfbfSEd Maste }
105ac7ddfbfSEd Maste
DisplaySourceLinesWithLineNumbersAndColumn(const SBFileSpec & file,uint32_t line,uint32_t column,uint32_t context_before,uint32_t context_after,const char * current_line_cstr,SBStream & s)106435933ddSDimitry Andric size_t SBSourceManager::DisplaySourceLinesWithLineNumbersAndColumn(
107435933ddSDimitry Andric const SBFileSpec &file, uint32_t line, uint32_t column,
108435933ddSDimitry Andric uint32_t context_before, uint32_t context_after,
109435933ddSDimitry Andric const char *current_line_cstr, SBStream &s) {
110*b5893f02SDimitry Andric if (m_opaque_ap == NULL)
111ac7ddfbfSEd Maste return 0;
112ac7ddfbfSEd Maste
113435933ddSDimitry Andric return m_opaque_ap->DisplaySourceLinesWithLineNumbers(
114435933ddSDimitry Andric file.ref(), line, column, context_before, context_after,
115435933ddSDimitry Andric current_line_cstr, s.get());
116ac7ddfbfSEd Maste }
117