blob: 7bdeabcee72f5832c21eceea62a4e56868918a4c [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- SBSourceManager.cpp -------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Jim Inghamcc637462011-09-13 00:29:56 +000010#include "lldb/API/SBDebugger.h"
Eli Friedman7a62c8b2010-06-09 07:44:37 +000011#include "lldb/API/SBSourceManager.h"
Jim Inghamcc637462011-09-13 00:29:56 +000012#include "lldb/API/SBTarget.h"
Johnny Chene5791dd2010-12-11 01:20:39 +000013#include "lldb/API/SBStream.h"
Chris Lattner24943d22010-06-08 16:52:24 +000014
15#include "lldb/API/SBFileSpec.h"
Jim Inghamcc637462011-09-13 00:29:56 +000016#include "lldb/Core/Debugger.h"
Chris Lattner24943d22010-06-08 16:52:24 +000017#include "lldb/Core/Stream.h"
18#include "lldb/Core/StreamFile.h"
19#include "lldb/Core/SourceManager.h"
20
Jim Inghamcc637462011-09-13 00:29:56 +000021#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000022
23using namespace lldb;
24using namespace lldb_private;
25
Jim Inghamcc637462011-09-13 00:29:56 +000026class lldb::SBSourceManager_impl
Chris Lattner24943d22010-06-08 16:52:24 +000027{
Jim Inghamcc637462011-09-13 00:29:56 +000028public:
29 SBSourceManager_impl (const SBDebugger &debugger)
30 {
31 m_debugger_sp = debugger.m_opaque_sp;
32 }
33
34 SBSourceManager_impl (const SBTarget &target)
35 {
36 m_target_sp = target.m_opaque_sp;
37 }
38
39 SBSourceManager_impl (const SBSourceManager_impl &rhs)
40 {
41 if (&rhs == this)
42 return;
43 m_debugger_sp = rhs.m_debugger_sp;
44 m_target_sp = rhs.m_target_sp;
45 }
46
47 size_t
48 DisplaySourceLinesWithLineNumbers
49 (
50 const SBFileSpec &file,
51 uint32_t line,
52 uint32_t context_before,
53 uint32_t context_after,
54 const char* current_line_cstr,
55 SBStream &s
56 )
57 {
58 if (!file.IsValid())
59 return 0;
60
61 if (m_debugger_sp)
62 return m_debugger_sp->GetSourceManager().DisplaySourceLinesWithLineNumbers (*file,
63 line,
64 context_before,
65 context_after,
66 current_line_cstr,
67 s.m_opaque_ap.get());
68 else if (m_target_sp)
69 return m_target_sp->GetSourceManager().DisplaySourceLinesWithLineNumbers (*file,
70 line,
71 context_before,
72 context_after,
73 current_line_cstr,
74 s.m_opaque_ap.get());
75 else
76 return 0;
77 }
78
79private:
80 lldb::DebuggerSP m_debugger_sp;
81 lldb::TargetSP m_target_sp;
82
83};
84
85SBSourceManager::SBSourceManager (const SBDebugger &debugger)
86{
87 m_opaque_ap.reset(new SBSourceManager_impl (debugger));
88}
89
90SBSourceManager::SBSourceManager (const SBTarget &target)
91{
92 m_opaque_ap.reset(new SBSourceManager_impl (target));
93}
94
95SBSourceManager::SBSourceManager (const SBSourceManager &rhs)
96{
97 if (&rhs == this)
98 return;
99
100 m_opaque_ap.reset(new SBSourceManager_impl (*(rhs.m_opaque_ap.get())));
101}
102
103const lldb::SBSourceManager &
104SBSourceManager::operator = (const lldb::SBSourceManager &rhs)
105{
106 m_opaque_ap.reset (new SBSourceManager_impl (*(rhs.m_opaque_ap.get())));
107 return *this;
Chris Lattner24943d22010-06-08 16:52:24 +0000108}
109
110SBSourceManager::~SBSourceManager()
111{
112}
113
114size_t
115SBSourceManager::DisplaySourceLinesWithLineNumbers
116(
117 const SBFileSpec &file,
118 uint32_t line,
119 uint32_t context_before,
120 uint32_t context_after,
121 const char* current_line_cstr,
Johnny Chene5791dd2010-12-11 01:20:39 +0000122 SBStream &s
Chris Lattner24943d22010-06-08 16:52:24 +0000123)
124{
Jim Inghamcc637462011-09-13 00:29:56 +0000125 if (m_opaque_ap.get() == NULL)
Greg Clayton538eb822010-11-05 23:17:00 +0000126 return 0;
127
Jim Inghamcc637462011-09-13 00:29:56 +0000128 return m_opaque_ap->DisplaySourceLinesWithLineNumbers (file,
129 line,
130 context_before,
131 context_after,
132 current_line_cstr,
133 s);
Chris Lattner24943d22010-06-08 16:52:24 +0000134}