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 | |
Daniel Malea | d891f9b | 2012-12-05 00:20:57 +0000 | [diff] [blame] | 10 | #include "lldb/lldb-python.h" |
| 11 | |
Jim Ingham | cc63746 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 12 | #include "lldb/API/SBDebugger.h" |
Eli Friedman | 7a62c8b | 2010-06-09 07:44:37 +0000 | [diff] [blame] | 13 | #include "lldb/API/SBSourceManager.h" |
Jim Ingham | cc63746 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 14 | #include "lldb/API/SBTarget.h" |
Johnny Chen | e5791dd | 2010-12-11 01:20:39 +0000 | [diff] [blame] | 15 | #include "lldb/API/SBStream.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 16 | |
| 17 | #include "lldb/API/SBFileSpec.h" |
Jim Ingham | cc63746 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 18 | #include "lldb/Core/Debugger.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | #include "lldb/Core/Stream.h" |
| 20 | #include "lldb/Core/StreamFile.h" |
| 21 | #include "lldb/Core/SourceManager.h" |
| 22 | |
Jim Ingham | cc63746 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 23 | #include "lldb/Target/Target.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | |
Greg Clayton | 15afa9f | 2011-10-01 02:59:24 +0000 | [diff] [blame] | 25 | namespace 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 Chen | dccbc4b | 2011-12-20 00:04:58 +0000 | [diff] [blame] | 53 | const char *current_line_cstr, |
Greg Clayton | 15afa9f | 2011-10-01 02:59:24 +0000 | [diff] [blame] | 54 | lldb_private::Stream *s) |
| 55 | { |
Johnny Chen | 5956604 | 2011-10-03 20:56:39 +0000 | [diff] [blame] | 56 | if (!file) |
Greg Clayton | 15afa9f | 2011-10-01 02:59:24 +0000 | [diff] [blame] | 57 | 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 Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 84 | using namespace lldb; |
| 85 | using namespace lldb_private; |
| 86 | |
Jim Ingham | cc63746 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 87 | SBSourceManager::SBSourceManager (const SBDebugger &debugger) |
| 88 | { |
Greg Clayton | 15afa9f | 2011-10-01 02:59:24 +0000 | [diff] [blame] | 89 | m_opaque_ap.reset(new SourceManagerImpl (debugger.get_sp())); |
Jim Ingham | cc63746 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | SBSourceManager::SBSourceManager (const SBTarget &target) |
| 93 | { |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 94 | m_opaque_ap.reset(new SourceManagerImpl (target.GetSP())); |
Jim Ingham | cc63746 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | SBSourceManager::SBSourceManager (const SBSourceManager &rhs) |
| 98 | { |
| 99 | if (&rhs == this) |
| 100 | return; |
| 101 | |
Greg Clayton | 15afa9f | 2011-10-01 02:59:24 +0000 | [diff] [blame] | 102 | m_opaque_ap.reset(new SourceManagerImpl (*(rhs.m_opaque_ap.get()))); |
Jim Ingham | cc63746 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | const lldb::SBSourceManager & |
| 106 | SBSourceManager::operator = (const lldb::SBSourceManager &rhs) |
| 107 | { |
Greg Clayton | 15afa9f | 2011-10-01 02:59:24 +0000 | [diff] [blame] | 108 | m_opaque_ap.reset (new SourceManagerImpl (*(rhs.m_opaque_ap.get()))); |
Jim Ingham | cc63746 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 109 | return *this; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | SBSourceManager::~SBSourceManager() |
| 113 | { |
| 114 | } |
| 115 | |
| 116 | size_t |
| 117 | SBSourceManager::DisplaySourceLinesWithLineNumbers |
| 118 | ( |
| 119 | const SBFileSpec &file, |
| 120 | uint32_t line, |
| 121 | uint32_t context_before, |
| 122 | uint32_t context_after, |
Johnny Chen | dccbc4b | 2011-12-20 00:04:58 +0000 | [diff] [blame] | 123 | const char *current_line_cstr, |
Johnny Chen | e5791dd | 2010-12-11 01:20:39 +0000 | [diff] [blame] | 124 | SBStream &s |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 125 | ) |
| 126 | { |
Jim Ingham | cc63746 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 127 | if (m_opaque_ap.get() == NULL) |
Greg Clayton | 538eb82 | 2010-11-05 23:17:00 +0000 | [diff] [blame] | 128 | return 0; |
| 129 | |
Greg Clayton | 15afa9f | 2011-10-01 02:59:24 +0000 | [diff] [blame] | 130 | return m_opaque_ap->DisplaySourceLinesWithLineNumbers (file.ref(), |
Jim Ingham | cc63746 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 131 | line, |
| 132 | context_before, |
| 133 | context_after, |
| 134 | current_line_cstr, |
Greg Clayton | 15afa9f | 2011-10-01 02:59:24 +0000 | [diff] [blame] | 135 | s.get()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 136 | } |