2010-06-09 00:52:24 +08:00
|
|
|
//===-- SBSourceManager.cpp -------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-09-13 08:29:56 +08:00
|
|
|
#include "lldb/API/SBDebugger.h"
|
2010-06-09 15:44:37 +08:00
|
|
|
#include "lldb/API/SBSourceManager.h"
|
2011-09-13 08:29:56 +08:00
|
|
|
#include "lldb/API/SBTarget.h"
|
2010-12-11 09:20:39 +08:00
|
|
|
#include "lldb/API/SBStream.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
#include "lldb/API/SBFileSpec.h"
|
2011-09-13 08:29:56 +08:00
|
|
|
#include "lldb/Core/Debugger.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/Stream.h"
|
|
|
|
#include "lldb/Core/StreamFile.h"
|
|
|
|
#include "lldb/Core/SourceManager.h"
|
|
|
|
|
2011-09-13 08:29:56 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-10-01 10:59:24 +08:00
|
|
|
namespace lldb_private
|
2011-09-13 08:29:56 +08:00
|
|
|
{
|
2011-10-01 10:59:24 +08:00
|
|
|
class SourceManagerImpl
|
2011-09-13 08:29:56 +08:00
|
|
|
{
|
2011-10-01 10:59:24 +08:00
|
|
|
public:
|
|
|
|
SourceManagerImpl (const lldb::DebuggerSP &debugger_sp)
|
|
|
|
{
|
|
|
|
m_debugger_sp = debugger_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
SourceManagerImpl (const lldb::TargetSP &target_sp)
|
|
|
|
{
|
|
|
|
m_target_sp = target_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
SourceManagerImpl (const SourceManagerImpl &rhs)
|
|
|
|
{
|
|
|
|
if (&rhs == this)
|
|
|
|
return;
|
|
|
|
m_debugger_sp = rhs.m_debugger_sp;
|
|
|
|
m_target_sp = rhs.m_target_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
DisplaySourceLinesWithLineNumbers (const lldb_private::FileSpec &file,
|
|
|
|
uint32_t line,
|
|
|
|
uint32_t context_before,
|
|
|
|
uint32_t context_after,
|
|
|
|
const char* current_line_cstr,
|
|
|
|
lldb_private::Stream *s)
|
|
|
|
{
|
2011-10-04 04:56:39 +08:00
|
|
|
if (!file)
|
2011-10-01 10:59:24 +08:00
|
|
|
return 0;
|
2011-09-13 08:29:56 +08:00
|
|
|
|
2011-10-01 10:59:24 +08:00
|
|
|
if (m_debugger_sp)
|
|
|
|
return m_debugger_sp->GetSourceManager().DisplaySourceLinesWithLineNumbers (file,
|
|
|
|
line,
|
|
|
|
context_before,
|
|
|
|
context_after,
|
|
|
|
current_line_cstr,
|
|
|
|
s);
|
|
|
|
else if (m_target_sp)
|
|
|
|
return m_target_sp->GetSourceManager().DisplaySourceLinesWithLineNumbers (file,
|
|
|
|
line,
|
|
|
|
context_before,
|
|
|
|
context_after,
|
|
|
|
current_line_cstr,
|
|
|
|
s);
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
lldb::DebuggerSP m_debugger_sp;
|
|
|
|
lldb::TargetSP m_target_sp;
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-09-13 08:29:56 +08:00
|
|
|
SBSourceManager::SBSourceManager (const SBDebugger &debugger)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-10-01 10:59:24 +08:00
|
|
|
m_opaque_ap.reset(new SourceManagerImpl (debugger.get_sp()));
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2011-09-13 08:29:56 +08:00
|
|
|
SBSourceManager::SBSourceManager (const SBTarget &target)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-10-01 10:59:24 +08:00
|
|
|
m_opaque_ap.reset(new SourceManagerImpl (target.get_sp()));
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2011-09-13 08:29:56 +08:00
|
|
|
SBSourceManager::SBSourceManager (const SBSourceManager &rhs)
|
2010-11-06 07:17:00 +08:00
|
|
|
{
|
2011-09-13 08:29:56 +08:00
|
|
|
if (&rhs == this)
|
|
|
|
return;
|
|
|
|
|
2011-10-01 10:59:24 +08:00
|
|
|
m_opaque_ap.reset(new SourceManagerImpl (*(rhs.m_opaque_ap.get())));
|
2010-11-06 07:17:00 +08:00
|
|
|
}
|
|
|
|
|
2011-09-13 08:29:56 +08:00
|
|
|
const lldb::SBSourceManager &
|
|
|
|
SBSourceManager::operator = (const lldb::SBSourceManager &rhs)
|
2010-11-06 07:17:00 +08:00
|
|
|
{
|
2011-10-01 10:59:24 +08:00
|
|
|
m_opaque_ap.reset (new SourceManagerImpl (*(rhs.m_opaque_ap.get())));
|
2010-11-06 07:17:00 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2011-09-13 08:29:56 +08:00
|
|
|
SBSourceManager::~SBSourceManager()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
size_t
|
|
|
|
SBSourceManager::DisplaySourceLinesWithLineNumbers
|
|
|
|
(
|
|
|
|
const SBFileSpec &file,
|
|
|
|
uint32_t line,
|
|
|
|
uint32_t context_before,
|
|
|
|
uint32_t context_after,
|
|
|
|
const char* current_line_cstr,
|
2010-12-11 09:20:39 +08:00
|
|
|
SBStream &s
|
2010-06-09 00:52:24 +08:00
|
|
|
)
|
|
|
|
{
|
2011-09-13 08:29:56 +08:00
|
|
|
if (m_opaque_ap.get() == NULL)
|
2010-06-09 00:52:24 +08:00
|
|
|
return 0;
|
|
|
|
|
2011-10-01 10:59:24 +08:00
|
|
|
return m_opaque_ap->DisplaySourceLinesWithLineNumbers (file.ref(),
|
2011-09-13 08:29:56 +08:00
|
|
|
line,
|
|
|
|
context_before,
|
|
|
|
context_after,
|
|
|
|
current_line_cstr,
|
2011-10-01 10:59:24 +08:00
|
|
|
s.get());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|