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