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:
|
2013-03-19 08:20:55 +08:00
|
|
|
SourceManagerImpl (const lldb::DebuggerSP &debugger_sp) :
|
|
|
|
m_debugger_wp (debugger_sp),
|
|
|
|
m_target_wp ()
|
2011-10-01 10:59:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-03-19 08:20:55 +08:00
|
|
|
SourceManagerImpl (const lldb::TargetSP &target_sp) :
|
|
|
|
m_debugger_wp (),
|
|
|
|
m_target_wp (target_sp)
|
2011-10-01 10:59:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SourceManagerImpl (const SourceManagerImpl &rhs)
|
|
|
|
{
|
|
|
|
if (&rhs == this)
|
|
|
|
return;
|
2013-03-19 08:20:55 +08:00
|
|
|
m_debugger_wp = rhs.m_debugger_wp;
|
|
|
|
m_target_wp = rhs.m_target_wp;
|
2011-10-01 10:59:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
DisplaySourceLinesWithLineNumbers (const lldb_private::FileSpec &file,
|
|
|
|
uint32_t line,
|
|
|
|
uint32_t context_before,
|
|
|
|
uint32_t context_after,
|
2011-12-20 08:04:58 +08:00
|
|
|
const char *current_line_cstr,
|
2011-10-01 10:59:24 +08:00
|
|
|
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
|
|
|
|
2013-03-19 08:20:55 +08:00
|
|
|
lldb::TargetSP target_sp (m_target_wp.lock());
|
|
|
|
if (target_sp)
|
|
|
|
{
|
|
|
|
return target_sp->GetSourceManager().DisplaySourceLinesWithLineNumbers (file,
|
|
|
|
line,
|
|
|
|
context_before,
|
|
|
|
context_after,
|
|
|
|
current_line_cstr,
|
|
|
|
s);
|
|
|
|
}
|
2011-10-01 10:59:24 +08:00
|
|
|
else
|
2013-03-19 08:20:55 +08:00
|
|
|
{
|
|
|
|
lldb::DebuggerSP debugger_sp (m_debugger_wp.lock());
|
|
|
|
if (debugger_sp)
|
|
|
|
{
|
|
|
|
return debugger_sp->GetSourceManager().DisplaySourceLinesWithLineNumbers (file,
|
|
|
|
line,
|
|
|
|
context_before,
|
|
|
|
context_after,
|
|
|
|
current_line_cstr,
|
|
|
|
s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2011-10-01 10:59:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-03-19 08:20:55 +08:00
|
|
|
lldb::DebuggerWP m_debugger_wp;
|
|
|
|
lldb::TargetWP m_target_wp;
|
2011-10-01 10:59:24 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2012-01-30 15:41:31 +08:00
|
|
|
m_opaque_ap.reset(new SourceManagerImpl (target.GetSP()));
|
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,
|
2011-12-20 08:04:58 +08:00
|
|
|
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
|
|
|
}
|