Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- 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 Ingham | cc63746 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 10 | #include "lldb/API/SBDebugger.h" |
Eli Friedman | 7a62c8b | 2010-06-09 07:44:37 +0000 | [diff] [blame] | 11 | #include "lldb/API/SBSourceManager.h" |
Jim Ingham | cc63746 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 12 | #include "lldb/API/SBTarget.h" |
Johnny Chen | e5791dd | 2010-12-11 01:20:39 +0000 | [diff] [blame] | 13 | #include "lldb/API/SBStream.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 14 | |
| 15 | #include "lldb/API/SBFileSpec.h" |
Jim Ingham | cc63746 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 16 | #include "lldb/Core/Debugger.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | #include "lldb/Core/Stream.h" |
| 18 | #include "lldb/Core/StreamFile.h" |
| 19 | #include "lldb/Core/SourceManager.h" |
| 20 | |
Jim Ingham | cc63746 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 21 | #include "lldb/Target/Target.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | |
Greg Clayton | 15afa9f | 2011-10-01 02:59:24 +0000 | [diff] [blame] | 23 | namespace lldb_private |
| 24 | { |
| 25 | class SourceManagerImpl |
| 26 | { |
| 27 | public: |
| 28 | SourceManagerImpl (const lldb::DebuggerSP &debugger_sp) |
| 29 | { |
| 30 | m_debugger_sp = debugger_sp; |
| 31 | } |
| 32 | |
| 33 | SourceManagerImpl (const lldb::TargetSP &target_sp) |
| 34 | { |
| 35 | m_target_sp = target_sp; |
| 36 | } |
| 37 | |
| 38 | SourceManagerImpl (const SourceManagerImpl &rhs) |
| 39 | { |
| 40 | if (&rhs == this) |
| 41 | return; |
| 42 | m_debugger_sp = rhs.m_debugger_sp; |
| 43 | m_target_sp = rhs.m_target_sp; |
| 44 | } |
| 45 | |
| 46 | size_t |
| 47 | DisplaySourceLinesWithLineNumbers (const lldb_private::FileSpec &file, |
| 48 | uint32_t line, |
| 49 | uint32_t context_before, |
| 50 | uint32_t context_after, |
Johnny Chen | dccbc4b | 2011-12-20 00:04:58 +0000 | [diff] [blame] | 51 | const char *current_line_cstr, |
Greg Clayton | 15afa9f | 2011-10-01 02:59:24 +0000 | [diff] [blame] | 52 | lldb_private::Stream *s) |
| 53 | { |
Johnny Chen | 5956604 | 2011-10-03 20:56:39 +0000 | [diff] [blame] | 54 | if (!file) |
Greg Clayton | 15afa9f | 2011-10-01 02:59:24 +0000 | [diff] [blame] | 55 | return 0; |
| 56 | |
| 57 | if (m_debugger_sp) |
| 58 | return m_debugger_sp->GetSourceManager().DisplaySourceLinesWithLineNumbers (file, |
| 59 | line, |
| 60 | context_before, |
| 61 | context_after, |
| 62 | current_line_cstr, |
| 63 | s); |
| 64 | else if (m_target_sp) |
| 65 | return m_target_sp->GetSourceManager().DisplaySourceLinesWithLineNumbers (file, |
| 66 | line, |
| 67 | context_before, |
| 68 | context_after, |
| 69 | current_line_cstr, |
| 70 | s); |
| 71 | else |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | private: |
| 76 | lldb::DebuggerSP m_debugger_sp; |
| 77 | lldb::TargetSP m_target_sp; |
| 78 | |
| 79 | }; |
| 80 | } |
| 81 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 82 | using namespace lldb; |
| 83 | using namespace lldb_private; |
| 84 | |
Jim Ingham | cc63746 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 85 | SBSourceManager::SBSourceManager (const SBDebugger &debugger) |
| 86 | { |
Greg Clayton | 15afa9f | 2011-10-01 02:59:24 +0000 | [diff] [blame] | 87 | m_opaque_ap.reset(new SourceManagerImpl (debugger.get_sp())); |
Jim Ingham | cc63746 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | SBSourceManager::SBSourceManager (const SBTarget &target) |
| 91 | { |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 92 | m_opaque_ap.reset(new SourceManagerImpl (target.GetSP())); |
Jim Ingham | cc63746 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | SBSourceManager::SBSourceManager (const SBSourceManager &rhs) |
| 96 | { |
| 97 | if (&rhs == this) |
| 98 | return; |
| 99 | |
Greg Clayton | 15afa9f | 2011-10-01 02:59:24 +0000 | [diff] [blame] | 100 | m_opaque_ap.reset(new SourceManagerImpl (*(rhs.m_opaque_ap.get()))); |
Jim Ingham | cc63746 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | const lldb::SBSourceManager & |
| 104 | SBSourceManager::operator = (const lldb::SBSourceManager &rhs) |
| 105 | { |
Greg Clayton | 15afa9f | 2011-10-01 02:59:24 +0000 | [diff] [blame] | 106 | m_opaque_ap.reset (new SourceManagerImpl (*(rhs.m_opaque_ap.get()))); |
Jim Ingham | cc63746 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 107 | return *this; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | SBSourceManager::~SBSourceManager() |
| 111 | { |
| 112 | } |
| 113 | |
| 114 | size_t |
| 115 | SBSourceManager::DisplaySourceLinesWithLineNumbers |
| 116 | ( |
| 117 | const SBFileSpec &file, |
| 118 | uint32_t line, |
| 119 | uint32_t context_before, |
| 120 | uint32_t context_after, |
Johnny Chen | dccbc4b | 2011-12-20 00:04:58 +0000 | [diff] [blame] | 121 | const char *current_line_cstr, |
Johnny Chen | e5791dd | 2010-12-11 01:20:39 +0000 | [diff] [blame] | 122 | SBStream &s |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 123 | ) |
| 124 | { |
Jim Ingham | cc63746 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 125 | if (m_opaque_ap.get() == NULL) |
Greg Clayton | 538eb82 | 2010-11-05 23:17:00 +0000 | [diff] [blame] | 126 | return 0; |
| 127 | |
Greg Clayton | 15afa9f | 2011-10-01 02:59:24 +0000 | [diff] [blame] | 128 | return m_opaque_ap->DisplaySourceLinesWithLineNumbers (file.ref(), |
Jim Ingham | cc63746 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 129 | line, |
| 130 | context_before, |
| 131 | context_after, |
| 132 | current_line_cstr, |
Greg Clayton | 15afa9f | 2011-10-01 02:59:24 +0000 | [diff] [blame] | 133 | s.get()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 134 | } |