2010-06-09 00:52:24 +08:00
|
|
|
//===-- Symbol.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/Symbol/Symbol.h"
|
|
|
|
|
|
|
|
#include "lldb/Core/Module.h"
|
2013-10-22 02:40:51 +08:00
|
|
|
#include "lldb/Core/ModuleSpec.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/Section.h"
|
|
|
|
#include "lldb/Core/Stream.h"
|
<rdar://problem/11757916>
Make breakpoint setting by file and line much more efficient by only looking for inlined breakpoint locations if we are setting a breakpoint in anything but a source implementation file. Implementing this complex for a many reasons. Turns out that parsing compile units lazily had some issues with respect to how we need to do things with DWARF in .o files. So the fixes in the checkin for this makes these changes:
- Add a new setting called "target.inline-breakpoint-strategy" which can be set to "never", "always", or "headers". "never" will never try and set any inlined breakpoints (fastest). "always" always looks for inlined breakpoint locations (slowest, but most accurate). "headers", which is the default setting, will only look for inlined breakpoint locations if the breakpoint is set in what are consudered to be header files, which is realy defined as "not in an implementation source file".
- modify the breakpoint setting by file and line to check the current "target.inline-breakpoint-strategy" setting and act accordingly
- Modify compile units to be able to get their language and other info lazily. This allows us to create compile units from the debug map and not have to fill all of the details in, and then lazily discover this information as we go on debuggging. This is needed to avoid parsing all .o files when setting breakpoints in implementation only files (no inlines). Otherwise we would need to parse the .o file, the object file (mach-o in our case) and the symbol file (DWARF in the object file) just to see what the compile unit was.
- modify the "SymbolFileDWARFDebugMap" to subclass lldb_private::Module so that the virtual "GetObjectFile()" and "GetSymbolVendor()" functions can be intercepted when the .o file contenst are later lazilly needed. Prior to this fix, when we first instantiated the "SymbolFileDWARFDebugMap" class, we would also make modules, object files and symbol files for every .o file in the debug map because we needed to fix up the sections in the .o files with information that is in the executable debug map. Now we lazily do this in the DebugMapModule::GetObjectFile()
Cleaned up header includes a bit as well.
llvm-svn: 162860
2012-08-30 05:13:06 +08:00
|
|
|
#include "lldb/Symbol/ObjectFile.h"
|
|
|
|
#include "lldb/Symbol/Symtab.h"
|
2013-07-04 00:35:41 +08:00
|
|
|
#include "lldb/Symbol/Function.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Target/Process.h"
|
2010-09-15 07:36:40 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2013-07-02 03:45:50 +08:00
|
|
|
#include "lldb/Symbol/SymbolVendor.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
|
|
|
|
Symbol::Symbol() :
|
2011-04-12 03:41:40 +08:00
|
|
|
SymbolContextScope (),
|
2011-10-20 02:09:39 +08:00
|
|
|
m_uid (UINT32_MAX),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_type_data (0),
|
|
|
|
m_type_data_resolved (false),
|
|
|
|
m_is_synthetic (false),
|
|
|
|
m_is_debug (false),
|
|
|
|
m_is_external (false),
|
|
|
|
m_size_is_sibling (false),
|
|
|
|
m_size_is_synthesized (false),
|
2013-07-10 09:23:25 +08:00
|
|
|
m_size_is_valid (false),
|
2012-11-27 09:52:16 +08:00
|
|
|
m_demangled_is_synthesized (false),
|
2011-11-23 05:20:33 +08:00
|
|
|
m_type (eSymbolTypeInvalid),
|
2013-06-20 05:50:28 +08:00
|
|
|
m_mangled (),
|
|
|
|
m_addr_range (),
|
|
|
|
m_flags ()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Symbol::Symbol
|
|
|
|
(
|
2011-10-20 02:09:39 +08:00
|
|
|
uint32_t symID,
|
2010-06-09 00:52:24 +08:00
|
|
|
const char *name,
|
|
|
|
bool name_is_mangled,
|
|
|
|
SymbolType type,
|
|
|
|
bool external,
|
|
|
|
bool is_debug,
|
|
|
|
bool is_trampoline,
|
|
|
|
bool is_artificial,
|
2012-02-24 09:59:29 +08:00
|
|
|
const lldb::SectionSP §ion_sp,
|
2010-06-09 00:52:24 +08:00
|
|
|
addr_t offset,
|
2013-01-26 02:06:21 +08:00
|
|
|
addr_t size,
|
2013-04-14 07:17:23 +08:00
|
|
|
bool size_is_valid,
|
2010-06-09 00:52:24 +08:00
|
|
|
uint32_t flags
|
|
|
|
) :
|
2011-04-12 03:41:40 +08:00
|
|
|
SymbolContextScope (),
|
2011-10-20 02:09:39 +08:00
|
|
|
m_uid (symID),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_type_data (0),
|
|
|
|
m_type_data_resolved (false),
|
|
|
|
m_is_synthetic (is_artificial),
|
|
|
|
m_is_debug (is_debug),
|
|
|
|
m_is_external (external),
|
|
|
|
m_size_is_sibling (false),
|
|
|
|
m_size_is_synthesized (false),
|
2013-07-10 09:23:25 +08:00
|
|
|
m_size_is_valid (size_is_valid || size > 0),
|
2012-11-27 09:52:16 +08:00
|
|
|
m_demangled_is_synthesized (false),
|
2011-11-23 05:20:33 +08:00
|
|
|
m_type (type),
|
2013-06-20 05:50:28 +08:00
|
|
|
m_mangled (ConstString(name), name_is_mangled),
|
|
|
|
m_addr_range (section_sp, offset, size),
|
|
|
|
m_flags (flags)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Symbol::Symbol
|
|
|
|
(
|
2011-10-20 02:09:39 +08:00
|
|
|
uint32_t symID,
|
2010-06-09 00:52:24 +08:00
|
|
|
const char *name,
|
|
|
|
bool name_is_mangled,
|
|
|
|
SymbolType type,
|
|
|
|
bool external,
|
|
|
|
bool is_debug,
|
|
|
|
bool is_trampoline,
|
|
|
|
bool is_artificial,
|
|
|
|
const AddressRange &range,
|
2013-04-14 07:17:23 +08:00
|
|
|
bool size_is_valid,
|
2010-06-09 00:52:24 +08:00
|
|
|
uint32_t flags
|
|
|
|
) :
|
2011-04-12 03:41:40 +08:00
|
|
|
SymbolContextScope (),
|
2011-10-20 02:09:39 +08:00
|
|
|
m_uid (symID),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_type_data (0),
|
|
|
|
m_type_data_resolved (false),
|
|
|
|
m_is_synthetic (is_artificial),
|
|
|
|
m_is_debug (is_debug),
|
|
|
|
m_is_external (external),
|
|
|
|
m_size_is_sibling (false),
|
|
|
|
m_size_is_synthesized (false),
|
2013-07-10 09:23:25 +08:00
|
|
|
m_size_is_valid (size_is_valid || range.GetByteSize() > 0),
|
2012-11-27 09:52:16 +08:00
|
|
|
m_demangled_is_synthesized (false),
|
2011-11-23 05:20:33 +08:00
|
|
|
m_type (type),
|
2013-06-20 05:50:28 +08:00
|
|
|
m_mangled (ConstString(name), name_is_mangled),
|
|
|
|
m_addr_range (range),
|
|
|
|
m_flags (flags)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Symbol::Symbol(const Symbol& rhs):
|
2011-04-12 03:41:40 +08:00
|
|
|
SymbolContextScope (rhs),
|
2011-10-20 02:09:39 +08:00
|
|
|
m_uid (rhs.m_uid),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_type_data (rhs.m_type_data),
|
|
|
|
m_type_data_resolved (rhs.m_type_data_resolved),
|
|
|
|
m_is_synthetic (rhs.m_is_synthetic),
|
|
|
|
m_is_debug (rhs.m_is_debug),
|
|
|
|
m_is_external (rhs.m_is_external),
|
|
|
|
m_size_is_sibling (rhs.m_size_is_sibling),
|
|
|
|
m_size_is_synthesized (false),
|
2013-07-10 09:23:25 +08:00
|
|
|
m_size_is_valid (rhs.m_size_is_valid),
|
2012-11-27 09:52:16 +08:00
|
|
|
m_demangled_is_synthesized (rhs.m_demangled_is_synthesized),
|
2011-11-23 05:20:33 +08:00
|
|
|
m_type (rhs.m_type),
|
2013-06-20 05:50:28 +08:00
|
|
|
m_mangled (rhs.m_mangled),
|
|
|
|
m_addr_range (rhs.m_addr_range),
|
|
|
|
m_flags (rhs.m_flags)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const Symbol&
|
|
|
|
Symbol::operator= (const Symbol& rhs)
|
|
|
|
{
|
|
|
|
if (this != &rhs)
|
|
|
|
{
|
2010-08-31 02:11:35 +08:00
|
|
|
SymbolContextScope::operator= (rhs);
|
2011-10-20 02:09:39 +08:00
|
|
|
m_uid = rhs.m_uid;
|
2010-06-09 00:52:24 +08:00
|
|
|
m_type_data = rhs.m_type_data;
|
|
|
|
m_type_data_resolved = rhs.m_type_data_resolved;
|
|
|
|
m_is_synthetic = rhs.m_is_synthetic;
|
|
|
|
m_is_debug = rhs.m_is_debug;
|
|
|
|
m_is_external = rhs.m_is_external;
|
|
|
|
m_size_is_sibling = rhs.m_size_is_sibling;
|
|
|
|
m_size_is_synthesized = rhs.m_size_is_sibling;
|
2013-07-10 09:23:25 +08:00
|
|
|
m_size_is_valid = rhs.m_size_is_valid;
|
2012-11-27 09:52:16 +08:00
|
|
|
m_demangled_is_synthesized = rhs.m_demangled_is_synthesized;
|
2011-11-23 05:20:33 +08:00
|
|
|
m_type = rhs.m_type;
|
2013-06-20 05:50:28 +08:00
|
|
|
m_mangled = rhs.m_mangled;
|
2011-11-23 05:20:33 +08:00
|
|
|
m_addr_range = rhs.m_addr_range;
|
2013-06-20 05:50:28 +08:00
|
|
|
m_flags = rhs.m_flags;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2011-10-20 02:09:39 +08:00
|
|
|
void
|
|
|
|
Symbol::Clear()
|
|
|
|
{
|
|
|
|
m_uid = UINT32_MAX;
|
|
|
|
m_mangled.Clear();
|
|
|
|
m_type_data = 0;
|
|
|
|
m_type_data_resolved = false;
|
|
|
|
m_is_synthetic = false;
|
|
|
|
m_is_debug = false;
|
|
|
|
m_is_external = false;
|
|
|
|
m_size_is_sibling = false;
|
|
|
|
m_size_is_synthesized = false;
|
2013-07-10 09:23:25 +08:00
|
|
|
m_size_is_valid = false;
|
2012-11-27 09:52:16 +08:00
|
|
|
m_demangled_is_synthesized = false;
|
2011-11-23 05:20:33 +08:00
|
|
|
m_type = eSymbolTypeInvalid;
|
2011-10-20 02:09:39 +08:00
|
|
|
m_flags = 0;
|
2011-11-23 05:20:33 +08:00
|
|
|
m_addr_range.Clear();
|
2011-10-20 02:09:39 +08:00
|
|
|
}
|
|
|
|
|
2012-03-08 05:03:09 +08:00
|
|
|
bool
|
|
|
|
Symbol::ValueIsAddress() const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-03-08 05:03:09 +08:00
|
|
|
return m_addr_range.GetBaseAddress().GetSection().get() != NULL;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2013-10-22 02:40:51 +08:00
|
|
|
ConstString
|
|
|
|
Symbol::GetReExportedSymbolName() const
|
|
|
|
{
|
|
|
|
if (m_type == eSymbolTypeReExported)
|
|
|
|
{
|
|
|
|
// For eSymbolTypeReExported, the "const char *" from a ConstString
|
|
|
|
// is used as the offset in the address range base address. We can
|
|
|
|
// then make this back into a string that is the re-exported name.
|
|
|
|
intptr_t str_ptr = m_addr_range.GetBaseAddress().GetOffset();
|
|
|
|
if (str_ptr != 0)
|
|
|
|
return ConstString((const char *)str_ptr);
|
|
|
|
else
|
|
|
|
return GetName();
|
|
|
|
}
|
|
|
|
return ConstString();
|
|
|
|
}
|
|
|
|
|
|
|
|
FileSpec
|
|
|
|
Symbol::GetReExportedSymbolSharedLibrary() const
|
|
|
|
{
|
|
|
|
if (m_type == eSymbolTypeReExported)
|
|
|
|
{
|
|
|
|
// For eSymbolTypeReExported, the "const char *" from a ConstString
|
|
|
|
// is used as the offset in the address range base address. We can
|
|
|
|
// then make this back into a string that is the re-exported name.
|
|
|
|
intptr_t str_ptr = m_addr_range.GetByteSize();
|
|
|
|
if (str_ptr != 0)
|
|
|
|
return FileSpec((const char *)str_ptr, false);
|
|
|
|
}
|
|
|
|
return FileSpec();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Symbol::SetReExportedSymbolName(const ConstString &name)
|
|
|
|
{
|
|
|
|
if (m_type == eSymbolTypeReExported)
|
|
|
|
{
|
|
|
|
// For eSymbolTypeReExported, the "const char *" from a ConstString
|
|
|
|
// is used as the offset in the address range base address.
|
|
|
|
m_addr_range.GetBaseAddress().SetOffset((intptr_t)name.GetCString());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Symbol::SetReExportedSymbolSharedLibrary(const FileSpec &fspec)
|
|
|
|
{
|
|
|
|
if (m_type == eSymbolTypeReExported)
|
|
|
|
{
|
|
|
|
// For eSymbolTypeReExported, the "const char *" from a ConstString
|
|
|
|
// is used as the offset in the address range base address.
|
|
|
|
m_addr_range.SetByteSize((intptr_t)ConstString(fspec.GetPath().c_str()).GetCString());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
uint32_t
|
|
|
|
Symbol::GetSiblingIndex() const
|
|
|
|
{
|
|
|
|
return m_size_is_sibling ? m_addr_range.GetByteSize() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Symbol::IsTrampoline () const
|
|
|
|
{
|
|
|
|
return m_type == eSymbolTypeTrampoline;
|
|
|
|
}
|
|
|
|
|
2013-02-28 04:13:38 +08:00
|
|
|
bool
|
|
|
|
Symbol::IsIndirect () const
|
|
|
|
{
|
|
|
|
return m_type == eSymbolTypeResolver;
|
|
|
|
}
|
|
|
|
|
2010-06-29 05:30:43 +08:00
|
|
|
void
|
2010-09-15 07:36:40 +08:00
|
|
|
Symbol::GetDescription (Stream *s, lldb::DescriptionLevel level, Target *target) const
|
2010-06-29 05:30:43 +08:00
|
|
|
{
|
2012-05-16 02:43:44 +08:00
|
|
|
s->Printf("id = {0x%8.8x}", m_uid);
|
2011-09-24 13:04:40 +08:00
|
|
|
|
2012-02-24 09:59:29 +08:00
|
|
|
if (m_addr_range.GetBaseAddress().GetSection())
|
2010-06-29 05:30:43 +08:00
|
|
|
{
|
2012-03-08 07:30:39 +08:00
|
|
|
if (ValueIsAddress())
|
2010-06-29 05:30:43 +08:00
|
|
|
{
|
2012-03-08 07:30:39 +08:00
|
|
|
const lldb::addr_t byte_size = GetByteSize();
|
|
|
|
if (byte_size > 0)
|
2010-09-10 09:30:46 +08:00
|
|
|
{
|
|
|
|
s->PutCString (", range = ");
|
2010-09-15 07:36:40 +08:00
|
|
|
m_addr_range.Dump(s, target, Address::DumpStyleLoadAddress, Address::DumpStyleFileAddress);
|
2010-09-10 09:30:46 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s->PutCString (", address = ");
|
2010-09-15 07:36:40 +08:00
|
|
|
m_addr_range.GetBaseAddress().Dump(s, target, Address::DumpStyleLoadAddress, Address::DumpStyleFileAddress);
|
2010-09-10 09:30:46 +08:00
|
|
|
}
|
2010-06-29 05:30:43 +08:00
|
|
|
}
|
|
|
|
else
|
2012-11-30 05:49:15 +08:00
|
|
|
s->Printf (", value = 0x%16.16" PRIx64, m_addr_range.GetBaseAddress().GetOffset());
|
2011-09-24 13:04:40 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_size_is_sibling)
|
2012-11-30 05:49:15 +08:00
|
|
|
s->Printf (", sibling = %5" PRIu64, m_addr_range.GetBaseAddress().GetOffset());
|
2011-09-24 13:04:40 +08:00
|
|
|
else
|
2012-11-30 05:49:15 +08:00
|
|
|
s->Printf (", value = 0x%16.16" PRIx64, m_addr_range.GetBaseAddress().GetOffset());
|
2010-06-29 05:30:43 +08:00
|
|
|
}
|
2012-02-01 16:09:32 +08:00
|
|
|
if (m_mangled.GetDemangledName())
|
|
|
|
s->Printf(", name=\"%s\"", m_mangled.GetDemangledName().AsCString());
|
|
|
|
if (m_mangled.GetMangledName())
|
|
|
|
s->Printf(", mangled=\"%s\"", m_mangled.GetMangledName().AsCString());
|
|
|
|
|
2010-06-29 05:30:43 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void
|
2010-09-15 07:36:40 +08:00
|
|
|
Symbol::Dump(Stream *s, Target *target, uint32_t index) const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
|
|
|
|
// s->Indent();
|
|
|
|
// s->Printf("Symbol[%5u] %6u %c%c %-12s ",
|
|
|
|
s->Printf("[%5u] %6u %c%c%c %-12s ",
|
|
|
|
index,
|
|
|
|
GetID(),
|
|
|
|
m_is_debug ? 'D' : ' ',
|
|
|
|
m_is_synthetic ? 'S' : ' ',
|
|
|
|
m_is_external ? 'X' : ' ',
|
|
|
|
GetTypeAsString());
|
|
|
|
|
2012-03-08 05:03:09 +08:00
|
|
|
// Make sure the size of the symbol is up to date before dumping
|
|
|
|
GetByteSize();
|
|
|
|
|
|
|
|
if (ValueIsAddress())
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
if (!m_addr_range.GetBaseAddress().Dump(s, NULL, Address::DumpStyleFileAddress))
|
|
|
|
s->Printf("%*s", 18, "");
|
|
|
|
|
|
|
|
s->PutChar(' ');
|
|
|
|
|
2010-09-15 07:36:40 +08:00
|
|
|
if (!m_addr_range.GetBaseAddress().Dump(s, target, Address::DumpStyleLoadAddress))
|
2010-06-09 00:52:24 +08:00
|
|
|
s->Printf("%*s", 18, "");
|
|
|
|
|
|
|
|
const char *format = m_size_is_sibling ?
|
|
|
|
" Sibling -> [%5llu] 0x%8.8x %s\n":
|
2012-11-30 05:49:15 +08:00
|
|
|
" 0x%16.16" PRIx64 " 0x%8.8x %s\n";
|
2010-06-09 00:52:24 +08:00
|
|
|
s->Printf( format,
|
2012-03-08 07:30:39 +08:00
|
|
|
GetByteSize(),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_flags,
|
|
|
|
m_mangled.GetName().AsCString(""));
|
|
|
|
}
|
2013-10-22 02:40:51 +08:00
|
|
|
else if (m_type == eSymbolTypeReExported)
|
|
|
|
{
|
|
|
|
s->Printf (" 0x%8.8x %s",
|
|
|
|
m_flags,
|
|
|
|
m_mangled.GetName().AsCString(""));
|
|
|
|
|
|
|
|
ConstString reexport_name = GetReExportedSymbolName();
|
|
|
|
intptr_t shlib = m_addr_range.GetByteSize();
|
|
|
|
if (shlib)
|
|
|
|
s->Printf(" -> %s`%s\n", (const char *)shlib, reexport_name.GetCString());
|
|
|
|
else
|
|
|
|
s->Printf(" -> %s\n", reexport_name.GetCString());
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
const char *format = m_size_is_sibling ?
|
2012-11-30 05:49:15 +08:00
|
|
|
"0x%16.16" PRIx64 " Sibling -> [%5llu] 0x%8.8x %s\n":
|
|
|
|
"0x%16.16" PRIx64 " 0x%16.16" PRIx64 " 0x%8.8x %s\n";
|
2010-06-09 00:52:24 +08:00
|
|
|
s->Printf( format,
|
|
|
|
m_addr_range.GetBaseAddress().GetOffset(),
|
2012-03-08 07:30:39 +08:00
|
|
|
GetByteSize(),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_flags,
|
|
|
|
m_mangled.GetName().AsCString(""));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
Symbol::GetPrologueByteSize ()
|
|
|
|
{
|
2013-02-28 04:13:38 +08:00
|
|
|
if (m_type == eSymbolTypeCode || m_type == eSymbolTypeResolver)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
if (!m_type_data_resolved)
|
|
|
|
{
|
|
|
|
m_type_data_resolved = true;
|
2013-07-04 00:35:41 +08:00
|
|
|
|
|
|
|
const Address &base_address = m_addr_range.GetBaseAddress();
|
|
|
|
Function *function = base_address.CalculateSymbolContextFunction();
|
|
|
|
if (function)
|
|
|
|
{
|
|
|
|
// Functions have line entries which can also potentially have end of prologue information.
|
|
|
|
// So if this symbol points to a function, use the prologue information from there.
|
|
|
|
m_type_data = function->GetPrologueByteSize();
|
|
|
|
}
|
|
|
|
else
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2013-07-04 00:35:41 +08:00
|
|
|
ModuleSP module_sp (base_address.GetModule());
|
|
|
|
SymbolContext sc;
|
|
|
|
if (module_sp)
|
2013-07-02 03:45:50 +08:00
|
|
|
{
|
2013-07-04 00:35:41 +08:00
|
|
|
uint32_t resolved_flags = module_sp->ResolveSymbolContextForAddress (base_address,
|
|
|
|
eSymbolContextLineEntry,
|
|
|
|
sc);
|
|
|
|
if (resolved_flags & eSymbolContextLineEntry)
|
2013-07-02 03:45:50 +08:00
|
|
|
{
|
2013-07-04 00:35:41 +08:00
|
|
|
// Default to the end of the first line entry.
|
|
|
|
m_type_data = sc.line_entry.range.GetByteSize();
|
|
|
|
|
|
|
|
// Set address for next line.
|
|
|
|
Address addr (base_address);
|
|
|
|
addr.Slide (m_type_data);
|
2013-07-02 03:45:50 +08:00
|
|
|
|
2013-07-04 00:35:41 +08:00
|
|
|
// Check the first few instructions and look for one that has a line number that is
|
|
|
|
// different than the first entry. This is also done in Function::GetPrologueByteSize().
|
|
|
|
uint16_t total_offset = m_type_data;
|
|
|
|
for (int idx = 0; idx < 6; ++idx)
|
2013-07-02 03:45:50 +08:00
|
|
|
{
|
2013-07-04 00:35:41 +08:00
|
|
|
SymbolContext sc_temp;
|
|
|
|
resolved_flags = module_sp->ResolveSymbolContextForAddress (addr, eSymbolContextLineEntry, sc_temp);
|
|
|
|
// Make sure we got line number information...
|
|
|
|
if (!(resolved_flags & eSymbolContextLineEntry))
|
|
|
|
break;
|
|
|
|
|
|
|
|
// If this line number is different than our first one, use it and we're done.
|
|
|
|
if (sc_temp.line_entry.line != sc.line_entry.line)
|
|
|
|
{
|
|
|
|
m_type_data = total_offset;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Slide addr up to the next line address.
|
|
|
|
addr.Slide (sc_temp.line_entry.range.GetByteSize());
|
|
|
|
total_offset += sc_temp.line_entry.range.GetByteSize();
|
|
|
|
// If we've gone too far, bail out.
|
|
|
|
if (total_offset >= m_addr_range.GetByteSize())
|
|
|
|
break;
|
2013-07-02 03:45:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-04 00:35:41 +08:00
|
|
|
// Sanity check - this may be a function in the middle of code that has debug information, but
|
|
|
|
// not for this symbol. So the line entries surrounding us won't lie inside our function.
|
|
|
|
// In that case, the line entry will be bigger than we are, so we do that quick check and
|
|
|
|
// if that is true, we just return 0.
|
|
|
|
if (m_type_data >= m_addr_range.GetByteSize())
|
|
|
|
m_type_data = 0;
|
2013-07-02 03:45:50 +08:00
|
|
|
}
|
2013-07-04 00:35:41 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// TODO: expose something in Process to figure out the
|
|
|
|
// size of a function prologue.
|
2013-07-02 03:45:50 +08:00
|
|
|
m_type_data = 0;
|
2013-07-04 00:35:41 +08:00
|
|
|
}
|
2013-07-02 03:45:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return m_type_data;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Symbol::Compare(const ConstString& name, SymbolType type) const
|
|
|
|
{
|
2011-10-29 08:54:12 +08:00
|
|
|
if (type == eSymbolTypeAny || m_type == type)
|
2010-06-09 00:52:24 +08:00
|
|
|
return m_mangled.GetMangledName() == name || m_mangled.GetDemangledName() == name;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ENUM_TO_CSTRING(x) case eSymbolType##x: return #x;
|
|
|
|
|
|
|
|
const char *
|
|
|
|
Symbol::GetTypeAsString() const
|
|
|
|
{
|
|
|
|
switch (m_type)
|
|
|
|
{
|
|
|
|
ENUM_TO_CSTRING(Invalid);
|
|
|
|
ENUM_TO_CSTRING(Absolute);
|
|
|
|
ENUM_TO_CSTRING(Code);
|
2013-10-22 02:40:51 +08:00
|
|
|
ENUM_TO_CSTRING(Resolver);
|
2010-06-09 00:52:24 +08:00
|
|
|
ENUM_TO_CSTRING(Data);
|
|
|
|
ENUM_TO_CSTRING(Trampoline);
|
|
|
|
ENUM_TO_CSTRING(Runtime);
|
|
|
|
ENUM_TO_CSTRING(Exception);
|
|
|
|
ENUM_TO_CSTRING(SourceFile);
|
|
|
|
ENUM_TO_CSTRING(HeaderFile);
|
|
|
|
ENUM_TO_CSTRING(ObjectFile);
|
|
|
|
ENUM_TO_CSTRING(CommonBlock);
|
|
|
|
ENUM_TO_CSTRING(Block);
|
|
|
|
ENUM_TO_CSTRING(Local);
|
|
|
|
ENUM_TO_CSTRING(Param);
|
|
|
|
ENUM_TO_CSTRING(Variable);
|
|
|
|
ENUM_TO_CSTRING(VariableType);
|
|
|
|
ENUM_TO_CSTRING(LineEntry);
|
|
|
|
ENUM_TO_CSTRING(LineHeader);
|
|
|
|
ENUM_TO_CSTRING(ScopeBegin);
|
|
|
|
ENUM_TO_CSTRING(ScopeEnd);
|
|
|
|
ENUM_TO_CSTRING(Additional);
|
|
|
|
ENUM_TO_CSTRING(Compiler);
|
|
|
|
ENUM_TO_CSTRING(Instrumentation);
|
|
|
|
ENUM_TO_CSTRING(Undefined);
|
2011-12-03 10:30:59 +08:00
|
|
|
ENUM_TO_CSTRING(ObjCClass);
|
|
|
|
ENUM_TO_CSTRING(ObjCMetaClass);
|
|
|
|
ENUM_TO_CSTRING(ObjCIVar);
|
2013-10-22 02:40:51 +08:00
|
|
|
ENUM_TO_CSTRING(ReExported);
|
2010-06-09 00:52:24 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return "<unknown SymbolType>";
|
|
|
|
}
|
|
|
|
|
2010-08-31 02:11:35 +08:00
|
|
|
void
|
|
|
|
Symbol::CalculateSymbolContext (SymbolContext *sc)
|
|
|
|
{
|
|
|
|
// Symbols can reconstruct the symbol and the module in the symbol context
|
|
|
|
sc->symbol = this;
|
2012-03-08 05:03:09 +08:00
|
|
|
if (ValueIsAddress())
|
|
|
|
sc->module_sp = GetAddress().GetModule();
|
2012-01-30 04:56:30 +08:00
|
|
|
else
|
|
|
|
sc->module_sp.reset();
|
2010-08-31 02:11:35 +08:00
|
|
|
}
|
|
|
|
|
2012-02-24 09:59:29 +08:00
|
|
|
ModuleSP
|
2011-08-13 05:40:01 +08:00
|
|
|
Symbol::CalculateSymbolContextModule ()
|
|
|
|
{
|
2012-03-08 05:03:09 +08:00
|
|
|
if (ValueIsAddress())
|
|
|
|
return GetAddress().GetModule();
|
2012-02-24 09:59:29 +08:00
|
|
|
return ModuleSP();
|
2011-08-13 05:40:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Symbol *
|
|
|
|
Symbol::CalculateSymbolContextSymbol ()
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2010-08-31 02:11:35 +08:00
|
|
|
void
|
|
|
|
Symbol::DumpSymbolContext (Stream *s)
|
|
|
|
{
|
|
|
|
bool dumped_module = false;
|
2012-03-08 05:03:09 +08:00
|
|
|
if (ValueIsAddress())
|
|
|
|
{
|
|
|
|
ModuleSP module_sp (GetAddress().GetModule());
|
2012-02-24 09:59:29 +08:00
|
|
|
if (module_sp)
|
2010-08-31 02:11:35 +08:00
|
|
|
{
|
|
|
|
dumped_module = true;
|
2012-02-24 09:59:29 +08:00
|
|
|
module_sp->DumpSymbolContext(s);
|
2010-08-31 02:11:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dumped_module)
|
|
|
|
s->PutCString(", ");
|
|
|
|
|
|
|
|
s->Printf("Symbol{0x%8.8x}", GetID());
|
|
|
|
}
|
|
|
|
|
2012-03-02 11:01:16 +08:00
|
|
|
lldb::addr_t
|
|
|
|
Symbol::GetByteSize () const
|
|
|
|
{
|
2013-07-10 09:23:25 +08:00
|
|
|
return m_addr_range.GetByteSize();
|
2012-03-02 11:01:16 +08:00
|
|
|
}
|
|
|
|
|
2013-10-22 02:40:51 +08:00
|
|
|
Symbol *
|
|
|
|
Symbol::ResolveReExportedSymbol (Target &target)
|
|
|
|
{
|
|
|
|
ConstString reexport_name (GetReExportedSymbolName());
|
|
|
|
if (reexport_name)
|
|
|
|
{
|
|
|
|
ModuleSpec module_spec;
|
|
|
|
ModuleSP module_sp;
|
|
|
|
module_spec.GetFileSpec() = GetReExportedSymbolSharedLibrary();
|
|
|
|
if (module_spec.GetFileSpec())
|
|
|
|
{
|
|
|
|
// Try searching for the module file spec first using the full path
|
|
|
|
module_sp = target.GetImages().FindFirstModule(module_spec);
|
|
|
|
if (!module_sp)
|
|
|
|
{
|
|
|
|
// Next try and find the module by basename in case environment
|
|
|
|
// variables or other runtime trickery causes shared libraries
|
|
|
|
// to be loaded from alternate paths
|
|
|
|
module_spec.GetFileSpec().GetDirectory().Clear();
|
|
|
|
module_sp = target.GetImages().FindFirstModule(module_spec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (module_sp)
|
|
|
|
{
|
|
|
|
lldb_private::SymbolContextList sc_list;
|
|
|
|
module_sp->FindSymbolsWithNameAndType(reexport_name, eSymbolTypeAny, sc_list);
|
|
|
|
const size_t num_scs = sc_list.GetSize();
|
|
|
|
if (num_scs > 0)
|
|
|
|
{
|
|
|
|
for (size_t i=0; i<num_scs; ++i)
|
|
|
|
{
|
|
|
|
lldb_private::SymbolContext sc;
|
|
|
|
if (sc_list.GetContextAtIndex(i, sc))
|
|
|
|
{
|
|
|
|
if (sc.symbol->IsExternal())
|
|
|
|
return sc.symbol;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-01-28 07:43:24 +08:00
|
|
|
|
|
|
|
|
|
|
|
lldb::DisassemblerSP
|
|
|
|
Symbol::GetInstructions (const ExecutionContext &exe_ctx,
|
|
|
|
const char *flavor,
|
|
|
|
bool prefer_file_cache)
|
|
|
|
{
|
|
|
|
ModuleSP module_sp (m_addr_range.GetBaseAddress().GetModule());
|
|
|
|
if (module_sp)
|
|
|
|
{
|
|
|
|
const bool prefer_file_cache = false;
|
|
|
|
return Disassembler::DisassembleRange (module_sp->GetArchitecture(),
|
|
|
|
NULL,
|
|
|
|
flavor,
|
|
|
|
exe_ctx,
|
|
|
|
m_addr_range,
|
|
|
|
prefer_file_cache);
|
|
|
|
}
|
|
|
|
return lldb::DisassemblerSP();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Symbol::GetDisassembly (const ExecutionContext &exe_ctx,
|
|
|
|
const char *flavor,
|
|
|
|
bool prefer_file_cache,
|
|
|
|
Stream &strm)
|
|
|
|
{
|
|
|
|
lldb::DisassemblerSP disassembler_sp = GetInstructions (exe_ctx, flavor, prefer_file_cache);
|
|
|
|
if (disassembler_sp)
|
|
|
|
{
|
|
|
|
const bool show_address = true;
|
|
|
|
const bool show_bytes = false;
|
|
|
|
disassembler_sp->GetInstructionList().Dump (&strm, show_address, show_bytes, &exe_ctx);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|