2010-06-08 16:52:24 +00: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 05:20:02 +00:00
|
|
|
#include "lldb/API/SBStream.h"
|
2010-10-06 03:09:58 +00:00
|
|
|
#include "lldb/Core/Disassembler.h"
|
2010-10-26 03:11:13 +00:00
|
|
|
#include "lldb/Core/Log.h"
|
2010-10-06 03:09:58 +00:00
|
|
|
#include "lldb/Core/Module.h"
|
2010-06-08 16:52:24 +00:00
|
|
|
#include "lldb/Symbol/Symbol.h"
|
2010-10-06 03:09:58 +00:00
|
|
|
#include "lldb/Target/ExecutionContext.h"
|
|
|
|
#include "lldb/Target/Target.h"
|
2010-06-08 16:52:24 +00:00
|
|
|
|
|
|
|
using namespace lldb;
|
2010-10-06 03:09:58 +00:00
|
|
|
using namespace lldb_private;
|
2010-06-08 16:52:24 +00:00
|
|
|
|
|
|
|
SBSymbol::SBSymbol () :
|
2010-06-23 01:19:29 +00:00
|
|
|
m_opaque_ptr (NULL)
|
2010-06-08 16:52:24 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SBSymbol::SBSymbol (lldb_private::Symbol *lldb_object_ptr) :
|
2010-06-23 01:19:29 +00:00
|
|
|
m_opaque_ptr (lldb_object_ptr)
|
2010-06-08 16:52:24 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-11-05 23:17:00 +00: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-08 16:52:24 +00:00
|
|
|
SBSymbol::~SBSymbol ()
|
|
|
|
{
|
2010-06-23 01:19:29 +00:00
|
|
|
m_opaque_ptr = NULL;
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
2010-12-07 05:40:31 +00:00
|
|
|
void
|
|
|
|
SBSymbol::SetSymbol (lldb_private::Symbol *lldb_object_ptr)
|
|
|
|
{
|
|
|
|
m_opaque_ptr = lldb_object_ptr;
|
|
|
|
}
|
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
bool
|
|
|
|
SBSymbol::IsValid () const
|
|
|
|
{
|
2010-06-23 01:19:29 +00:00
|
|
|
return m_opaque_ptr != NULL;
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
SBSymbol::GetName() const
|
|
|
|
{
|
2010-10-30 04:51:46 +00:00
|
|
|
const char *name = NULL;
|
2010-06-23 01:19:29 +00:00
|
|
|
if (m_opaque_ptr)
|
2010-10-30 04:51:46 +00:00
|
|
|
name = m_opaque_ptr->GetMangled().GetName().AsCString();
|
2010-10-26 23:49:36 +00:00
|
|
|
|
2013-03-27 23:08:40 +00:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 03:11:13 +00:00
|
|
|
if (log)
|
2014-04-04 04:06:10 +00:00
|
|
|
log->Printf ("SBSymbol(%p)::GetName () => \"%s\"",
|
|
|
|
static_cast<void*>(m_opaque_ptr), name ? name : "");
|
2010-10-30 04:51:46 +00:00
|
|
|
return name;
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
SBSymbol::GetMangledName () const
|
|
|
|
{
|
2010-10-30 04:51:46 +00:00
|
|
|
const char *name = NULL;
|
2010-06-23 01:19:29 +00:00
|
|
|
if (m_opaque_ptr)
|
2010-10-30 04:51:46 +00:00
|
|
|
name = m_opaque_ptr->GetMangled().GetMangledName().AsCString();
|
2013-03-27 23:08:40 +00:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-30 04:51:46 +00:00
|
|
|
if (log)
|
2014-04-04 04:06:10 +00:00
|
|
|
log->Printf ("SBSymbol(%p)::GetMangledName () => \"%s\"",
|
|
|
|
static_cast<void*>(m_opaque_ptr), name ? name : "");
|
2010-10-30 04:51:46 +00:00
|
|
|
|
|
|
|
return name;
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBSymbol::operator == (const SBSymbol &rhs) const
|
|
|
|
{
|
2010-06-23 01:19:29 +00:00
|
|
|
return m_opaque_ptr == rhs.m_opaque_ptr;
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBSymbol::operator != (const SBSymbol &rhs) const
|
|
|
|
{
|
2010-06-23 01:19:29 +00:00
|
|
|
return m_opaque_ptr != rhs.m_opaque_ptr;
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
2010-09-20 05:20:02 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
SBSymbol::GetDescription (SBStream &description)
|
|
|
|
{
|
2011-11-13 06:57:31 +00:00
|
|
|
Stream &strm = description.ref();
|
|
|
|
|
2010-09-20 05:20:02 +00:00
|
|
|
if (m_opaque_ptr)
|
|
|
|
{
|
2011-11-13 06:57:31 +00:00
|
|
|
m_opaque_ptr->GetDescription (&strm,
|
2010-09-22 23:01:29 +00:00
|
|
|
lldb::eDescriptionLevelFull, NULL);
|
2010-09-20 05:20:02 +00:00
|
|
|
}
|
|
|
|
else
|
2011-11-13 06:57:31 +00:00
|
|
|
strm.PutCString ("No value");
|
2010-09-20 05:20:02 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2010-10-06 03:09:58 +00:00
|
|
|
|
|
|
|
SBInstructionList
|
|
|
|
SBSymbol::GetInstructions (SBTarget target)
|
2013-03-02 00:26:47 +00:00
|
|
|
{
|
|
|
|
return GetInstructions (target, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
SBInstructionList
|
|
|
|
SBSymbol::GetInstructions (SBTarget target, const char *flavor_string)
|
2010-10-06 03:09:58 +00:00
|
|
|
{
|
|
|
|
SBInstructionList sb_instructions;
|
|
|
|
if (m_opaque_ptr)
|
|
|
|
{
|
2010-12-20 20:49:23 +00:00
|
|
|
Mutex::Locker api_locker;
|
2010-10-06 03:09:58 +00:00
|
|
|
ExecutionContext exe_ctx;
|
2012-01-30 07:41:31 +00:00
|
|
|
TargetSP target_sp (target.GetSP());
|
|
|
|
if (target_sp)
|
2010-12-20 20:49:23 +00:00
|
|
|
{
|
2012-05-04 23:02:50 +00:00
|
|
|
api_locker.Lock (target_sp->GetAPIMutex());
|
2012-01-30 07:41:31 +00:00
|
|
|
target_sp->CalculateExecutionContext (exe_ctx);
|
2010-12-20 20:49:23 +00:00
|
|
|
}
|
2012-03-07 21:03:09 +00:00
|
|
|
if (m_opaque_ptr->ValueIsAddress())
|
2010-10-06 03:09:58 +00:00
|
|
|
{
|
2015-06-25 21:46:34 +00:00
|
|
|
const Address &symbol_addr = m_opaque_ptr->GetAddressRef();
|
|
|
|
ModuleSP module_sp = symbol_addr.GetModule();
|
2012-01-29 20:56:30 +00:00
|
|
|
if (module_sp)
|
2010-10-06 03:09:58 +00:00
|
|
|
{
|
2015-06-25 21:46:34 +00:00
|
|
|
AddressRange symbol_range (symbol_addr, m_opaque_ptr->GetByteSize());
|
2013-09-12 23:23:35 +00:00
|
|
|
const bool prefer_file_cache = false;
|
2012-01-29 20:56:30 +00:00
|
|
|
sb_instructions.SetDisassembler (Disassembler::DisassembleRange (module_sp->GetArchitecture (),
|
2011-03-25 18:03:16 +00:00
|
|
|
NULL,
|
2013-03-02 00:26:47 +00:00
|
|
|
flavor_string,
|
2010-10-06 03:09:58 +00:00
|
|
|
exe_ctx,
|
2013-09-12 23:23:35 +00:00
|
|
|
symbol_range,
|
|
|
|
prefer_file_cache));
|
2010-10-06 03:09:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sb_instructions;
|
|
|
|
}
|
|
|
|
|
2010-10-26 23:49:36 +00:00
|
|
|
lldb_private::Symbol *
|
|
|
|
SBSymbol::get ()
|
|
|
|
{
|
|
|
|
return m_opaque_ptr;
|
|
|
|
}
|
2010-12-14 04:58:53 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
SBSymbol::reset (lldb_private::Symbol *symbol)
|
|
|
|
{
|
|
|
|
m_opaque_ptr = symbol;
|
|
|
|
}
|
2011-03-02 23:01:18 +00:00
|
|
|
|
|
|
|
SBAddress
|
|
|
|
SBSymbol::GetStartAddress ()
|
|
|
|
{
|
|
|
|
SBAddress addr;
|
2012-03-07 21:03:09 +00:00
|
|
|
if (m_opaque_ptr && m_opaque_ptr->ValueIsAddress())
|
2011-03-02 23:01:18 +00:00
|
|
|
{
|
2015-06-25 21:46:34 +00:00
|
|
|
addr.SetAddress (&m_opaque_ptr->GetAddressRef());
|
2011-03-02 23:01:18 +00:00
|
|
|
}
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
SBAddress
|
|
|
|
SBSymbol::GetEndAddress ()
|
|
|
|
{
|
|
|
|
SBAddress addr;
|
2012-03-07 21:03:09 +00:00
|
|
|
if (m_opaque_ptr && m_opaque_ptr->ValueIsAddress())
|
2011-03-02 23:01:18 +00:00
|
|
|
{
|
2012-03-07 21:03:09 +00:00
|
|
|
lldb::addr_t range_size = m_opaque_ptr->GetByteSize();
|
|
|
|
if (range_size > 0)
|
2011-03-02 23:01:18 +00:00
|
|
|
{
|
2015-06-25 21:46:34 +00:00
|
|
|
addr.SetAddress (&m_opaque_ptr->GetAddressRef());
|
2012-03-07 21:03:09 +00:00
|
|
|
addr->Slide (m_opaque_ptr->GetByteSize());
|
2011-03-02 23:01:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
SBSymbol::GetPrologueByteSize ()
|
|
|
|
{
|
|
|
|
if (m_opaque_ptr)
|
|
|
|
return m_opaque_ptr->GetPrologueByteSize();
|
|
|
|
return 0;
|
|
|
|
}
|
2011-03-31 01:08:07 +00:00
|
|
|
|
|
|
|
SymbolType
|
|
|
|
SBSymbol::GetType ()
|
|
|
|
{
|
|
|
|
if (m_opaque_ptr)
|
|
|
|
return m_opaque_ptr->GetType();
|
|
|
|
return eSymbolTypeInvalid;
|
|
|
|
}
|
2012-04-02 20:08:08 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
SBSymbol::IsExternal()
|
|
|
|
{
|
|
|
|
if (m_opaque_ptr)
|
|
|
|
return m_opaque_ptr->IsExternal();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBSymbol::IsSynthetic()
|
|
|
|
{
|
|
|
|
if (m_opaque_ptr)
|
|
|
|
return m_opaque_ptr->IsSynthetic();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|