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 | |
| 23 | using namespace lldb; |
| 24 | using namespace lldb_private; |
| 25 | |
Jim Ingham | cc63746 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 26 | class lldb::SBSourceManager_impl |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 27 | { |
Jim Ingham | cc63746 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 28 | public: |
| 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 | |
| 79 | private: |
| 80 | lldb::DebuggerSP m_debugger_sp; |
| 81 | lldb::TargetSP m_target_sp; |
| 82 | |
| 83 | }; |
| 84 | |
| 85 | SBSourceManager::SBSourceManager (const SBDebugger &debugger) |
| 86 | { |
| 87 | m_opaque_ap.reset(new SBSourceManager_impl (debugger)); |
| 88 | } |
| 89 | |
| 90 | SBSourceManager::SBSourceManager (const SBTarget &target) |
| 91 | { |
| 92 | m_opaque_ap.reset(new SBSourceManager_impl (target)); |
| 93 | } |
| 94 | |
| 95 | SBSourceManager::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 | |
| 103 | const lldb::SBSourceManager & |
| 104 | SBSourceManager::operator = (const lldb::SBSourceManager &rhs) |
| 105 | { |
| 106 | m_opaque_ap.reset (new SBSourceManager_impl (*(rhs.m_opaque_ap.get()))); |
| 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, |
| 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 | |
Jim Ingham | cc63746 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 128 | return m_opaque_ap->DisplaySourceLinesWithLineNumbers (file, |
| 129 | line, |
| 130 | context_before, |
| 131 | context_after, |
| 132 | current_line_cstr, |
| 133 | s); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 134 | } |