blob: 8196b91d00b358acf80276dae6d9ed713182759e [file] [log] [blame]
Chris Lattner30fdc8d2010-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 Inghame37d6052011-09-13 00:29:56 +000010#include "lldb/API/SBDebugger.h"
Eli Friedman4c5de692010-06-09 07:44:37 +000011#include "lldb/API/SBSourceManager.h"
Jim Inghame37d6052011-09-13 00:29:56 +000012#include "lldb/API/SBTarget.h"
Johnny Chenf6eaba82010-12-11 01:20:39 +000013#include "lldb/API/SBStream.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000014
15#include "lldb/API/SBFileSpec.h"
Jim Inghame37d6052011-09-13 00:29:56 +000016#include "lldb/Core/Debugger.h"
Chris Lattner30fdc8d2010-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 Inghame37d6052011-09-13 00:29:56 +000021#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000022
Greg Clayton9a377662011-10-01 02:59:24 +000023namespace lldb_private
24{
25 class SourceManagerImpl
26 {
27 public:
Greg Clayton9585fbf2013-03-19 00:20:55 +000028 SourceManagerImpl (const lldb::DebuggerSP &debugger_sp) :
29 m_debugger_wp (debugger_sp),
30 m_target_wp ()
Greg Clayton9a377662011-10-01 02:59:24 +000031 {
Greg Clayton9a377662011-10-01 02:59:24 +000032 }
33
Greg Clayton9585fbf2013-03-19 00:20:55 +000034 SourceManagerImpl (const lldb::TargetSP &target_sp) :
35 m_debugger_wp (),
36 m_target_wp (target_sp)
Greg Clayton9a377662011-10-01 02:59:24 +000037 {
Greg Clayton9a377662011-10-01 02:59:24 +000038 }
39
40 SourceManagerImpl (const SourceManagerImpl &rhs)
41 {
42 if (&rhs == this)
43 return;
Greg Clayton9585fbf2013-03-19 00:20:55 +000044 m_debugger_wp = rhs.m_debugger_wp;
45 m_target_wp = rhs.m_target_wp;
Greg Clayton9a377662011-10-01 02:59:24 +000046 }
47
48 size_t
49 DisplaySourceLinesWithLineNumbers (const lldb_private::FileSpec &file,
50 uint32_t line,
51 uint32_t context_before,
52 uint32_t context_after,
Johnny Chen1cbbdac2011-12-20 00:04:58 +000053 const char *current_line_cstr,
Greg Clayton9a377662011-10-01 02:59:24 +000054 lldb_private::Stream *s)
55 {
Johnny Chen44d6d2c2011-10-03 20:56:39 +000056 if (!file)
Greg Clayton9a377662011-10-01 02:59:24 +000057 return 0;
58
Greg Clayton9585fbf2013-03-19 00:20:55 +000059 lldb::TargetSP target_sp (m_target_wp.lock());
60 if (target_sp)
61 {
62 return target_sp->GetSourceManager().DisplaySourceLinesWithLineNumbers (file,
63 line,
64 context_before,
65 context_after,
66 current_line_cstr,
67 s);
68 }
Greg Clayton9a377662011-10-01 02:59:24 +000069 else
Greg Clayton9585fbf2013-03-19 00:20:55 +000070 {
71 lldb::DebuggerSP debugger_sp (m_debugger_wp.lock());
72 if (debugger_sp)
73 {
74 return debugger_sp->GetSourceManager().DisplaySourceLinesWithLineNumbers (file,
75 line,
76 context_before,
77 context_after,
78 current_line_cstr,
79 s);
80 }
81 }
82 return 0;
Greg Clayton9a377662011-10-01 02:59:24 +000083 }
84
85 private:
Greg Clayton9585fbf2013-03-19 00:20:55 +000086 lldb::DebuggerWP m_debugger_wp;
87 lldb::TargetWP m_target_wp;
Greg Clayton9a377662011-10-01 02:59:24 +000088
89 };
90}
91
Chris Lattner30fdc8d2010-06-08 16:52:24 +000092using namespace lldb;
93using namespace lldb_private;
94
Jim Inghame37d6052011-09-13 00:29:56 +000095SBSourceManager::SBSourceManager (const SBDebugger &debugger)
96{
Greg Clayton9a377662011-10-01 02:59:24 +000097 m_opaque_ap.reset(new SourceManagerImpl (debugger.get_sp()));
Jim Inghame37d6052011-09-13 00:29:56 +000098}
99
100SBSourceManager::SBSourceManager (const SBTarget &target)
101{
Greg Claytonb9556ac2012-01-30 07:41:31 +0000102 m_opaque_ap.reset(new SourceManagerImpl (target.GetSP()));
Jim Inghame37d6052011-09-13 00:29:56 +0000103}
104
105SBSourceManager::SBSourceManager (const SBSourceManager &rhs)
106{
107 if (&rhs == this)
108 return;
109
Greg Clayton9a377662011-10-01 02:59:24 +0000110 m_opaque_ap.reset(new SourceManagerImpl (*(rhs.m_opaque_ap.get())));
Jim Inghame37d6052011-09-13 00:29:56 +0000111}
112
113const lldb::SBSourceManager &
114SBSourceManager::operator = (const lldb::SBSourceManager &rhs)
115{
Greg Clayton9a377662011-10-01 02:59:24 +0000116 m_opaque_ap.reset (new SourceManagerImpl (*(rhs.m_opaque_ap.get())));
Jim Inghame37d6052011-09-13 00:29:56 +0000117 return *this;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000118}
119
120SBSourceManager::~SBSourceManager()
121{
122}
123
124size_t
125SBSourceManager::DisplaySourceLinesWithLineNumbers
126(
127 const SBFileSpec &file,
128 uint32_t line,
129 uint32_t context_before,
130 uint32_t context_after,
Johnny Chen1cbbdac2011-12-20 00:04:58 +0000131 const char *current_line_cstr,
Johnny Chenf6eaba82010-12-11 01:20:39 +0000132 SBStream &s
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000133)
134{
Jim Inghame37d6052011-09-13 00:29:56 +0000135 if (m_opaque_ap.get() == NULL)
Greg Claytonefabb122010-11-05 23:17:00 +0000136 return 0;
137
Greg Clayton9a377662011-10-01 02:59:24 +0000138 return m_opaque_ap->DisplaySourceLinesWithLineNumbers (file.ref(),
Jim Inghame37d6052011-09-13 00:29:56 +0000139 line,
140 context_before,
141 context_after,
142 current_line_cstr,
Greg Clayton9a377662011-10-01 02:59:24 +0000143 s.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000144}