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