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 10 #include "lldb/lldb-python.h" 11 12 #include "lldb/API/SBDebugger.h" 13 #include "lldb/API/SBSourceManager.h" 14 #include "lldb/API/SBTarget.h" 15 #include "lldb/API/SBStream.h" 16 17 #include "lldb/API/SBFileSpec.h" 18 #include "lldb/Core/Debugger.h" 19 #include "lldb/Core/Stream.h" 20 #include "lldb/Core/StreamFile.h" 21 #include "lldb/Core/SourceManager.h" 22 23 #include "lldb/Target/Target.h" 24 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, 53 const char *current_line_cstr, 54 lldb_private::Stream *s) 55 { 56 if (!file) 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 84 using namespace lldb; 85 using namespace lldb_private; 86 87 SBSourceManager::SBSourceManager (const SBDebugger &debugger) 88 { 89 m_opaque_ap.reset(new SourceManagerImpl (debugger.get_sp())); 90 } 91 92 SBSourceManager::SBSourceManager (const SBTarget &target) 93 { 94 m_opaque_ap.reset(new SourceManagerImpl (target.GetSP())); 95 } 96 97 SBSourceManager::SBSourceManager (const SBSourceManager &rhs) 98 { 99 if (&rhs == this) 100 return; 101 102 m_opaque_ap.reset(new SourceManagerImpl (*(rhs.m_opaque_ap.get()))); 103 } 104 105 const lldb::SBSourceManager & 106 SBSourceManager::operator = (const lldb::SBSourceManager &rhs) 107 { 108 m_opaque_ap.reset (new SourceManagerImpl (*(rhs.m_opaque_ap.get()))); 109 return *this; 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, 123 const char *current_line_cstr, 124 SBStream &s 125 ) 126 { 127 if (m_opaque_ap.get() == NULL) 128 return 0; 129 130 return m_opaque_ap->DisplaySourceLinesWithLineNumbers (file.ref(), 131 line, 132 context_before, 133 context_after, 134 current_line_cstr, 135 s.get()); 136 } 137