2010-06-09 00:52:24 +08:00
|
|
|
//===-- SBCompileUnit.cpp ---------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/API/SBCompileUnit.h"
|
|
|
|
#include "lldb/API/SBLineEntry.h"
|
2010-09-20 13:20:02 +08:00
|
|
|
#include "lldb/API/SBStream.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Symbol/CompileUnit.h"
|
|
|
|
#include "lldb/Symbol/LineEntry.h"
|
|
|
|
#include "lldb/Symbol/LineTable.h"
|
2010-10-26 11:11:13 +08:00
|
|
|
#include "lldb/Core/Log.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
|
|
|
|
SBCompileUnit::SBCompileUnit () :
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_ptr (NULL)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SBCompileUnit::SBCompileUnit (lldb_private::CompileUnit *lldb_object_ptr) :
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_ptr (lldb_object_ptr)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-11-06 07:17:00 +08:00
|
|
|
SBCompileUnit::SBCompileUnit(const SBCompileUnit &rhs) :
|
|
|
|
m_opaque_ptr (rhs.m_opaque_ptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const SBCompileUnit &
|
|
|
|
SBCompileUnit::operator = (const SBCompileUnit &rhs)
|
|
|
|
{
|
|
|
|
m_opaque_ptr = rhs.m_opaque_ptr;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
SBCompileUnit::~SBCompileUnit ()
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_ptr = NULL;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SBFileSpec
|
|
|
|
SBCompileUnit::GetFileSpec () const
|
|
|
|
{
|
|
|
|
SBFileSpec file_spec;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ptr)
|
|
|
|
file_spec.SetFileSpec(*m_opaque_ptr);
|
2010-06-09 00:52:24 +08:00
|
|
|
return file_spec;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
SBCompileUnit::GetNumLineEntries () const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ptr)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
LineTable *line_table = m_opaque_ptr->GetLineTable ();
|
2010-06-09 00:52:24 +08:00
|
|
|
if (line_table)
|
|
|
|
return line_table->GetSize();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SBLineEntry
|
|
|
|
SBCompileUnit::GetLineEntryAtIndex (uint32_t idx) const
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
SBLineEntry sb_line_entry;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ptr)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
LineTable *line_table = m_opaque_ptr->GetLineTable ();
|
2010-06-09 00:52:24 +08:00
|
|
|
if (line_table)
|
|
|
|
{
|
|
|
|
LineEntry line_entry;
|
|
|
|
if (line_table->GetLineEntryAtIndex(idx, line_entry))
|
|
|
|
sb_line_entry.SetLineEntry(line_entry);
|
|
|
|
}
|
|
|
|
}
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
SBStream sstr;
|
|
|
|
sb_line_entry.GetDescription (sstr);
|
2010-10-31 11:01:06 +08:00
|
|
|
log->Printf ("SBCompileUnit(%p)::GetLineEntryAtIndex (idx=%u) => SBLineEntry(%p): '%s'",
|
|
|
|
m_opaque_ptr, idx, sb_line_entry.get(), sstr.GetData());
|
2010-10-26 11:11:13 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return sb_line_entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
SBCompileUnit::FindLineEntryIndex (uint32_t start_idx, uint32_t line, SBFileSpec *inline_file_spec) const
|
2011-09-23 08:54:11 +08:00
|
|
|
{
|
|
|
|
const bool exact = true;
|
|
|
|
return FindLineEntryIndex (start_idx, line, inline_file_spec, exact);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
SBCompileUnit::FindLineEntryIndex (uint32_t start_idx, uint32_t line, SBFileSpec *inline_file_spec, bool exact) const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-10-31 11:01:06 +08:00
|
|
|
uint32_t index = UINT32_MAX;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ptr)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
FileSpec file_spec;
|
|
|
|
if (inline_file_spec && inline_file_spec->IsValid())
|
|
|
|
file_spec = inline_file_spec->ref();
|
|
|
|
else
|
2010-06-23 09:19:29 +08:00
|
|
|
file_spec = *m_opaque_ptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-10-31 11:01:06 +08:00
|
|
|
index = m_opaque_ptr->FindLineEntry (start_idx,
|
|
|
|
line,
|
|
|
|
inline_file_spec ? inline_file_spec->get() : NULL,
|
2011-09-23 08:54:11 +08:00
|
|
|
exact,
|
2010-10-31 11:01:06 +08:00
|
|
|
NULL);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
if (log)
|
2010-10-27 07:49:36 +08:00
|
|
|
{
|
|
|
|
SBStream sstr;
|
2010-10-31 11:01:06 +08:00
|
|
|
if (index == UINT32_MAX)
|
|
|
|
{
|
|
|
|
log->Printf ("SBCompileUnit(%p)::FindLineEntryIndex (start_idx=%u, line=%u, SBFileSpec(%p)) => NOT FOUND",
|
|
|
|
m_opaque_ptr, start_idx, line, inline_file_spec ? inline_file_spec->get() : NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
log->Printf ("SBCompileUnit(%p)::FindLineEntryIndex (start_idx=%u, line=%u, SBFileSpec(%p)) => %u",
|
|
|
|
m_opaque_ptr, start_idx, line, inline_file_spec ? inline_file_spec->get() : NULL, index);
|
|
|
|
}
|
2010-10-27 07:49:36 +08:00
|
|
|
}
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-10-31 11:01:06 +08:00
|
|
|
return index;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2012-03-17 04:46:10 +08:00
|
|
|
uint32_t
|
|
|
|
SBCompileUnit::GetNumSupportFiles () const
|
|
|
|
{
|
|
|
|
if (m_opaque_ptr)
|
|
|
|
{
|
|
|
|
FileSpecList& support_files = m_opaque_ptr->GetSupportFiles ();
|
|
|
|
return support_files.GetSize();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SBFileSpec
|
|
|
|
SBCompileUnit::GetSupportFileAtIndex (uint32_t idx) const
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2012-03-17 04:46:10 +08:00
|
|
|
|
|
|
|
SBFileSpec sb_file_spec;
|
|
|
|
if (m_opaque_ptr)
|
|
|
|
{
|
|
|
|
FileSpecList &support_files = m_opaque_ptr->GetSupportFiles ();
|
|
|
|
FileSpec file_spec = support_files.GetFileSpecAtIndex(idx);
|
|
|
|
sb_file_spec.SetFileSpec(file_spec);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
SBStream sstr;
|
|
|
|
sb_file_spec.GetDescription (sstr);
|
|
|
|
log->Printf ("SBCompileUnit(%p)::GetGetFileSpecAtIndex (idx=%u) => SBFileSpec(%p): '%s'",
|
|
|
|
m_opaque_ptr, idx, sb_file_spec.get(), sstr.GetData());
|
|
|
|
}
|
|
|
|
|
|
|
|
return sb_file_spec;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
SBCompileUnit::FindSupportFileIndex (uint32_t start_idx, const SBFileSpec &sb_file, bool full)
|
|
|
|
{
|
|
|
|
if (m_opaque_ptr)
|
|
|
|
{
|
|
|
|
FileSpecList &support_files = m_opaque_ptr->GetSupportFiles ();
|
|
|
|
return support_files.FindFileIndex(start_idx, sb_file.ref(), full);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
bool
|
|
|
|
SBCompileUnit::IsValid () const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return m_opaque_ptr != NULL;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBCompileUnit::operator == (const SBCompileUnit &rhs) const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return m_opaque_ptr == rhs.m_opaque_ptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBCompileUnit::operator != (const SBCompileUnit &rhs) const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return m_opaque_ptr != rhs.m_opaque_ptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const lldb_private::CompileUnit *
|
|
|
|
SBCompileUnit::operator->() const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return m_opaque_ptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const lldb_private::CompileUnit &
|
|
|
|
SBCompileUnit::operator*() const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return *m_opaque_ptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2010-09-20 13:20:02 +08:00
|
|
|
|
2011-09-26 15:11:27 +08:00
|
|
|
lldb_private::CompileUnit *
|
|
|
|
SBCompileUnit::get ()
|
2010-10-27 07:49:36 +08:00
|
|
|
{
|
|
|
|
return m_opaque_ptr;
|
|
|
|
}
|
2010-12-14 12:58:53 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
SBCompileUnit::reset (lldb_private::CompileUnit *lldb_object_ptr)
|
|
|
|
{
|
|
|
|
m_opaque_ptr = lldb_object_ptr;
|
|
|
|
}
|
|
|
|
|
2010-10-27 07:49:36 +08:00
|
|
|
|
2010-09-20 13:20:02 +08:00
|
|
|
bool
|
|
|
|
SBCompileUnit::GetDescription (SBStream &description)
|
|
|
|
{
|
2011-11-13 14:57:31 +08:00
|
|
|
Stream &strm = description.ref();
|
|
|
|
|
2010-09-20 13:20:02 +08:00
|
|
|
if (m_opaque_ptr)
|
2010-09-21 00:21:41 +08:00
|
|
|
{
|
2011-11-13 14:57:31 +08:00
|
|
|
m_opaque_ptr->Dump (&strm, false);
|
2010-09-21 00:21:41 +08:00
|
|
|
}
|
2010-09-20 13:20:02 +08:00
|
|
|
else
|
2011-11-13 14:57:31 +08:00
|
|
|
strm.PutCString ("No value");
|
2010-09-20 13:20:02 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|