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)
|
2015-07-09 06:32:23 +08:00
|
|
|
name = m_opaque_ptr->GetName().AsCString();
|
2010-10-27 07:49:36 +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
|
|
|
if (log)
|
2014-04-04 12:06:10 +08:00
|
|
|
log->Printf ("SBSymbol(%p)::GetName () => \"%s\"",
|
|
|
|
static_cast<void*>(m_opaque_ptr), name ? name : "");
|
2010-10-30 12:51:46 +08:00
|
|
|
return name;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2015-07-07 02:28:46 +08:00
|
|
|
const char *
|
|
|
|
SBSymbol::GetDisplayName() const
|
|
|
|
{
|
|
|
|
const char *name = NULL;
|
|
|
|
if (m_opaque_ptr)
|
2015-07-09 06:32:23 +08:00
|
|
|
name = m_opaque_ptr->GetMangled().GetDisplayDemangledName(m_opaque_ptr->GetLanguage()).AsCString();
|
2015-07-07 02:28:46 +08:00
|
|
|
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
|
|
|
if (log)
|
|
|
|
log->Printf ("SBSymbol(%p)::GetDisplayName () => \"%s\"",
|
|
|
|
static_cast<void*>(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();
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-30 12:51:46 +08:00
|
|
|
if (log)
|
2014-04-04 12:06:10 +08:00
|
|
|
log->Printf ("SBSymbol(%p)::GetMangledName () => \"%s\"",
|
|
|
|
static_cast<void*>(m_opaque_ptr), name ? name : "");
|
2010-10-30 12:51:46 +08:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2011-11-13 14:57:31 +08:00
|
|
|
Stream &strm = description.ref();
|
|
|
|
|
2010-09-20 13:20:02 +08:00
|
|
|
if (m_opaque_ptr)
|
|
|
|
{
|
2011-11-13 14:57:31 +08:00
|
|
|
m_opaque_ptr->GetDescription (&strm,
|
2010-09-23 07:01:29 +08:00
|
|
|
lldb::eDescriptionLevelFull, NULL);
|
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;
|
|
|
|
}
|
2010-10-06 11:09:58 +08:00
|
|
|
|
|
|
|
SBInstructionList
|
|
|
|
SBSymbol::GetInstructions (SBTarget target)
|
2013-03-02 08:26:47 +08:00
|
|
|
{
|
|
|
|
return GetInstructions (target, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
SBInstructionList
|
|
|
|
SBSymbol::GetInstructions (SBTarget target, const char *flavor_string)
|
2010-10-06 11:09:58 +08:00
|
|
|
{
|
|
|
|
SBInstructionList sb_instructions;
|
|
|
|
if (m_opaque_ptr)
|
|
|
|
{
|
|
|
|
ExecutionContext exe_ctx;
|
2012-01-30 15:41:31 +08:00
|
|
|
TargetSP target_sp (target.GetSP());
|
2016-05-19 13:13:57 +08:00
|
|
|
std::unique_lock<std::recursive_mutex> lock;
|
2012-01-30 15:41:31 +08:00
|
|
|
if (target_sp)
|
2010-12-21 04:49:23 +08:00
|
|
|
{
|
2016-05-19 13:13:57 +08:00
|
|
|
lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
|
|
|
|
|
2012-01-30 15:41:31 +08:00
|
|
|
target_sp->CalculateExecutionContext (exe_ctx);
|
2010-12-21 04:49:23 +08:00
|
|
|
}
|
2012-03-08 05:03:09 +08:00
|
|
|
if (m_opaque_ptr->ValueIsAddress())
|
2010-10-06 11:09:58 +08:00
|
|
|
{
|
2015-06-26 05:46:34 +08:00
|
|
|
const Address &symbol_addr = m_opaque_ptr->GetAddressRef();
|
|
|
|
ModuleSP module_sp = symbol_addr.GetModule();
|
2012-01-30 04:56:30 +08:00
|
|
|
if (module_sp)
|
2010-10-06 11:09:58 +08:00
|
|
|
{
|
2015-06-26 05:46:34 +08:00
|
|
|
AddressRange symbol_range (symbol_addr, m_opaque_ptr->GetByteSize());
|
2013-09-13 07:23:35 +08:00
|
|
|
const bool prefer_file_cache = false;
|
2012-01-30 04:56:30 +08:00
|
|
|
sb_instructions.SetDisassembler (Disassembler::DisassembleRange (module_sp->GetArchitecture (),
|
2011-03-26 02:03:16 +08:00
|
|
|
NULL,
|
2013-03-02 08:26:47 +08:00
|
|
|
flavor_string,
|
2010-10-06 11:09:58 +08:00
|
|
|
exe_ctx,
|
2013-09-13 07:23:35 +08:00
|
|
|
symbol_range,
|
|
|
|
prefer_file_cache));
|
2010-10-06 11:09:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
2012-03-08 05:03:09 +08:00
|
|
|
if (m_opaque_ptr && m_opaque_ptr->ValueIsAddress())
|
2011-03-03 07:01:18 +08:00
|
|
|
{
|
2015-06-26 05:46:34 +08:00
|
|
|
addr.SetAddress (&m_opaque_ptr->GetAddressRef());
|
2011-03-03 07:01:18 +08:00
|
|
|
}
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
SBAddress
|
|
|
|
SBSymbol::GetEndAddress ()
|
|
|
|
{
|
|
|
|
SBAddress addr;
|
2012-03-08 05:03:09 +08:00
|
|
|
if (m_opaque_ptr && m_opaque_ptr->ValueIsAddress())
|
2011-03-03 07:01:18 +08:00
|
|
|
{
|
2012-03-08 05:03:09 +08:00
|
|
|
lldb::addr_t range_size = m_opaque_ptr->GetByteSize();
|
|
|
|
if (range_size > 0)
|
2011-03-03 07:01:18 +08:00
|
|
|
{
|
2015-06-26 05:46:34 +08:00
|
|
|
addr.SetAddress (&m_opaque_ptr->GetAddressRef());
|
2012-03-08 05:03:09 +08:00
|
|
|
addr->Slide (m_opaque_ptr->GetByteSize());
|
2011-03-03 07:01:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
SBSymbol::GetPrologueByteSize ()
|
|
|
|
{
|
|
|
|
if (m_opaque_ptr)
|
|
|
|
return m_opaque_ptr->GetPrologueByteSize();
|
|
|
|
return 0;
|
|
|
|
}
|
2011-03-31 09:08:07 +08:00
|
|
|
|
|
|
|
SymbolType
|
|
|
|
SBSymbol::GetType ()
|
|
|
|
{
|
|
|
|
if (m_opaque_ptr)
|
|
|
|
return m_opaque_ptr->GetType();
|
|
|
|
return eSymbolTypeInvalid;
|
|
|
|
}
|
2012-04-03 04:08:08 +08: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;
|
|
|
|
}
|
|
|
|
|