blob: caa1b0c1b526d8a5b2953dfdce25f75cd4f6e4c4 [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
Daniel Malead891f9b2012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Jim Inghamcc637462011-09-13 00:29:56 +000012#include "lldb/API/SBDebugger.h"
Eli Friedman7a62c8b2010-06-09 07:44:37 +000013#include "lldb/API/SBSourceManager.h"
Jim Inghamcc637462011-09-13 00:29:56 +000014#include "lldb/API/SBTarget.h"
Johnny Chene5791dd2010-12-11 01:20:39 +000015#include "lldb/API/SBStream.h"
Chris Lattner24943d22010-06-08 16:52:24 +000016
17#include "lldb/API/SBFileSpec.h"
Jim Inghamcc637462011-09-13 00:29:56 +000018#include "lldb/Core/Debugger.h"
Chris Lattner24943d22010-06-08 16:52:24 +000019#include "lldb/Core/Stream.h"
20#include "lldb/Core/StreamFile.h"
21#include "lldb/Core/SourceManager.h"
22
Jim Inghamcc637462011-09-13 00:29:56 +000023#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000024
Greg Clayton15afa9f2011-10-01 02:59:24 +000025namespace lldb_private
26{
27 class SourceManagerImpl
28 {
29 public:
30 SourceManagerImpl (const lldb::DebuggerSP &debugger_sp)
31 {
32 m_debugger_sp = debugger_sp;
33 }
34
35 SourceManagerImpl (const lldb::TargetSP &target_sp)
36 {
37 m_target_sp = target_sp;
38 }
39
40 SourceManagerImpl (const SourceManagerImpl &rhs)
41 {
42 if (&rhs == this)
43 return;
44 m_debugger_sp = rhs.m_debugger_sp;
45 m_target_sp = rhs.m_target_sp;
46 }
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 Chendccbc4b2011-12-20 00:04:58 +000053 const char *current_line_cstr,
Greg Clayton15afa9f2011-10-01 02:59:24 +000054 lldb_private::Stream *s)
55 {
Johnny Chen59566042011-10-03 20:56:39 +000056 if (!file)
Greg Clayton15afa9f2011-10-01 02:59:24 +000057 return 0;
58
59 if (m_debugger_sp)
60 return m_debugger_sp->GetSourceManager().DisplaySourceLinesWithLineNumbers (file,
61 line,
62 context_before,
63 context_after,
64 current_line_cstr,
65 s);
66 else if (m_target_sp)
67 return m_target_sp->GetSourceManager().DisplaySourceLinesWithLineNumbers (file,
68 line,
69 context_before,
70 context_after,
71 current_line_cstr,
72 s);
73 else
74 return 0;
75 }
76
77 private:
78 lldb::DebuggerSP m_debugger_sp;
79 lldb::TargetSP m_target_sp;
80
81 };
82}
83
Chris Lattner24943d22010-06-08 16:52:24 +000084using namespace lldb;
85using namespace lldb_private;
86
Jim Inghamcc637462011-09-13 00:29:56 +000087SBSourceManager::SBSourceManager (const SBDebugger &debugger)
88{
Greg Clayton15afa9f2011-10-01 02:59:24 +000089 m_opaque_ap.reset(new SourceManagerImpl (debugger.get_sp()));
Jim Inghamcc637462011-09-13 00:29:56 +000090}
91
92SBSourceManager::SBSourceManager (const SBTarget &target)
93{
Greg Clayton334d33a2012-01-30 07:41:31 +000094 m_opaque_ap.reset(new SourceManagerImpl (target.GetSP()));
Jim Inghamcc637462011-09-13 00:29:56 +000095}
96
97SBSourceManager::SBSourceManager (const SBSourceManager &rhs)
98{
99 if (&rhs == this)
100 return;
101
Greg Clayton15afa9f2011-10-01 02:59:24 +0000102 m_opaque_ap.reset(new SourceManagerImpl (*(rhs.m_opaque_ap.get())));
Jim Inghamcc637462011-09-13 00:29:56 +0000103}
104
105const lldb::SBSourceManager &
106SBSourceManager::operator = (const lldb::SBSourceManager &rhs)
107{
Greg Clayton15afa9f2011-10-01 02:59:24 +0000108 m_opaque_ap.reset (new SourceManagerImpl (*(rhs.m_opaque_ap.get())));
Jim Inghamcc637462011-09-13 00:29:56 +0000109 return *this;
Chris Lattner24943d22010-06-08 16:52:24 +0000110}
111
112SBSourceManager::~SBSourceManager()
113{
114}
115
116size_t
117SBSourceManager::DisplaySourceLinesWithLineNumbers
118(
119 const SBFileSpec &file,
120 uint32_t line,
121 uint32_t context_before,
122 uint32_t context_after,
Johnny Chendccbc4b2011-12-20 00:04:58 +0000123 const char *current_line_cstr,
Johnny Chene5791dd2010-12-11 01:20:39 +0000124 SBStream &s
Chris Lattner24943d22010-06-08 16:52:24 +0000125)
126{
Jim Inghamcc637462011-09-13 00:29:56 +0000127 if (m_opaque_ap.get() == NULL)
Greg Clayton538eb822010-11-05 23:17:00 +0000128 return 0;
129
Greg Clayton15afa9f2011-10-01 02:59:24 +0000130 return m_opaque_ap->DisplaySourceLinesWithLineNumbers (file.ref(),
Jim Inghamcc637462011-09-13 00:29:56 +0000131 line,
132 context_before,
133 context_after,
134 current_line_cstr,
Greg Clayton15afa9f2011-10-01 02:59:24 +0000135 s.get());
Chris Lattner24943d22010-06-08 16:52:24 +0000136}