2010-06-09 00:52:24 +08:00
|
|
|
//===-- SBSymbol.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/SBSymbol.h"
|
2010-09-20 13:20:02 +08:00
|
|
|
#include "lldb/API/SBStream.h"
|
2010-10-06 11:09:58 +08:00
|
|
|
#include "lldb/Core/Disassembler.h"
|
2010-10-26 11:11:13 +08:00
|
|
|
#include "lldb/Core/Log.h"
|
2010-10-06 11:09:58 +08:00
|
|
|
#include "lldb/Core/Module.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Symbol/Symbol.h"
|
2010-10-06 11:09:58 +08:00
|
|
|
#include "lldb/Target/ExecutionContext.h"
|
|
|
|
#include "lldb/Target/Target.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
2010-10-06 11:09:58 +08:00
|
|
|
using namespace lldb_private;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
SBSymbol::SBSymbol () :
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_ptr (NULL)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SBSymbol::SBSymbol (lldb_private::Symbol *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
|
|
|
SBSymbol::SBSymbol (const lldb::SBSymbol &rhs) :
|
|
|
|
m_opaque_ptr (rhs.m_opaque_ptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const SBSymbol &
|
|
|
|
SBSymbol::operator = (const SBSymbol &rhs)
|
|
|
|
{
|
|
|
|
m_opaque_ptr = rhs.m_opaque_ptr;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
SBSymbol::~SBSymbol ()
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_ptr = NULL;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2010-12-07 13:40:31 +08:00
|
|
|
void
|
|
|
|
SBSymbol::SetSymbol (lldb_private::Symbol *lldb_object_ptr)
|
|
|
|
{
|
|
|
|
m_opaque_ptr = lldb_object_ptr;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
bool
|
|
|
|
SBSymbol::IsValid () const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return m_opaque_ptr != NULL;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
SBSymbol::GetName() const
|
|
|
|
{
|
2010-10-30 12:51:46 +08:00
|
|
|
const char *name = NULL;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ptr)
|
2010-10-30 12:51:46 +08:00
|
|
|
name = m_opaque_ptr->GetMangled().GetName().AsCString();
|
2010-10-27 07:49:36 +08:00
|
|
|
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
if (log)
|
2010-10-30 12:51:46 +08:00
|
|
|
log->Printf ("SBSymbol(%p)::GetName () => \"%s\"", m_opaque_ptr, name ? name : "");
|
|
|
|
return name;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
SBSymbol::GetMangledName () const
|
|
|
|
{
|
2010-10-30 12:51:46 +08:00
|
|
|
const char *name = NULL;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ptr)
|
2010-10-30 12:51:46 +08:00
|
|
|
name = m_opaque_ptr->GetMangled().GetMangledName().AsCString();
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-30 12:51:46 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf ("SBSymbol(%p)::GetMangledName () => \"%s\"", m_opaque_ptr, name ? name : "");
|
|
|
|
|
|
|
|
return name;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBSymbol::operator == (const SBSymbol &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
|
|
|
|
SBSymbol::operator != (const SBSymbol &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
|
|
|
}
|
2010-09-20 13:20:02 +08:00
|
|
|
|
|
|
|
bool
|
|
|
|
SBSymbol::GetDescription (SBStream &description)
|
|
|
|
{
|
|
|
|
if (m_opaque_ptr)
|
|
|
|
{
|
2010-09-23 07:01:29 +08:00
|
|
|
description.ref();
|
|
|
|
m_opaque_ptr->GetDescription (description.get(),
|
|
|
|
lldb::eDescriptionLevelFull, NULL);
|
2010-09-20 13:20:02 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
description.Printf ("No value");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2010-10-06 11:09:58 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SBInstructionList
|
|
|
|
SBSymbol::GetInstructions (SBTarget target)
|
|
|
|
{
|
|
|
|
SBInstructionList sb_instructions;
|
|
|
|
if (m_opaque_ptr)
|
|
|
|
{
|
2010-12-21 04:49:23 +08:00
|
|
|
Mutex::Locker api_locker;
|
2010-10-06 11:09:58 +08:00
|
|
|
ExecutionContext exe_ctx;
|
|
|
|
if (target.IsValid())
|
2010-12-21 04:49:23 +08:00
|
|
|
{
|
|
|
|
api_locker.Reset (target->GetAPIMutex().GetMutex());
|
2010-10-06 11:09:58 +08:00
|
|
|
target->CalculateExecutionContext (exe_ctx);
|
2010-12-21 04:49:23 +08:00
|
|
|
}
|
2010-10-06 11:09:58 +08:00
|
|
|
const AddressRange *symbol_range = m_opaque_ptr->GetAddressRangePtr();
|
|
|
|
if (symbol_range)
|
|
|
|
{
|
|
|
|
Module *module = symbol_range->GetBaseAddress().GetModule();
|
|
|
|
if (module)
|
|
|
|
{
|
|
|
|
sb_instructions.SetDisassembler (Disassembler::DisassembleRange (module->GetArchitecture (),
|
|
|
|
exe_ctx,
|
|
|
|
*symbol_range));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sb_instructions;
|
|
|
|
}
|
|
|
|
|
2010-10-27 07:49:36 +08:00
|
|
|
lldb_private::Symbol *
|
|
|
|
SBSymbol::get ()
|
|
|
|
{
|
|
|
|
return m_opaque_ptr;
|
|
|
|
}
|
2010-12-14 12:58:53 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
SBSymbol::reset (lldb_private::Symbol *symbol)
|
|
|
|
{
|
|
|
|
m_opaque_ptr = symbol;
|
|
|
|
}
|
2011-03-03 07:01:18 +08:00
|
|
|
|
|
|
|
SBAddress
|
|
|
|
SBSymbol::GetStartAddress ()
|
|
|
|
{
|
|
|
|
SBAddress addr;
|
|
|
|
if (m_opaque_ptr)
|
|
|
|
{
|
|
|
|
// Make sure the symbol is an address based symbol first:
|
|
|
|
AddressRange *symbol_arange_ptr = m_opaque_ptr->GetAddressRangePtr();
|
|
|
|
if (symbol_arange_ptr)
|
|
|
|
{
|
|
|
|
addr.SetAddress (&symbol_arange_ptr->GetBaseAddress());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
SBAddress
|
|
|
|
SBSymbol::GetEndAddress ()
|
|
|
|
{
|
|
|
|
SBAddress addr;
|
|
|
|
if (m_opaque_ptr)
|
|
|
|
{
|
|
|
|
AddressRange *symbol_arange_ptr = m_opaque_ptr->GetAddressRangePtr();
|
|
|
|
if (symbol_arange_ptr)
|
|
|
|
{
|
|
|
|
addr_t byte_size = symbol_arange_ptr->GetByteSize();
|
|
|
|
if (byte_size > 0)
|
|
|
|
{
|
|
|
|
addr.SetAddress (&symbol_arange_ptr->GetBaseAddress());
|
|
|
|
addr->Slide (byte_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
SBSymbol::GetPrologueByteSize ()
|
|
|
|
{
|
|
|
|
if (m_opaque_ptr)
|
|
|
|
return m_opaque_ptr->GetPrologueByteSize();
|
|
|
|
return 0;
|
|
|
|
}
|