2010-06-09 00:52:24 +08:00
|
|
|
//===-- Function.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/Function.h"
|
|
|
|
#include "lldb/Core/Module.h"
|
|
|
|
#include "lldb/Core/Section.h"
|
2010-07-22 06:12:05 +08:00
|
|
|
#include "lldb/Symbol/ClangASTType.h"
|
|
|
|
#include "lldb/Symbol/ClangASTContext.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Symbol/CompileUnit.h"
|
|
|
|
#include "lldb/Symbol/LineTable.h"
|
2011-08-06 07:43:37 +08:00
|
|
|
#include "lldb/Symbol/SymbolFile.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Symbol/SymbolVendor.h"
|
|
|
|
#include "clang/AST/Type.h"
|
|
|
|
#include "clang/AST/CanonicalType.h"
|
2011-07-30 10:42:06 +08:00
|
|
|
#include "llvm/Support/Casting.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-09-10 09:30:46 +08:00
|
|
|
using namespace lldb;
|
2010-06-09 00:52:24 +08:00
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Basic function information is contained in the FunctionInfo class.
|
|
|
|
// It is designed to contain the name, linkage name, and declaration
|
|
|
|
// location.
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FunctionInfo::FunctionInfo (const char *name, const Declaration *decl_ptr) :
|
|
|
|
m_name(name),
|
|
|
|
m_declaration(decl_ptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FunctionInfo::FunctionInfo (const ConstString& name, const Declaration *decl_ptr) :
|
|
|
|
m_name(name),
|
|
|
|
m_declaration(decl_ptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FunctionInfo::~FunctionInfo()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-09-15 13:51:24 +08:00
|
|
|
FunctionInfo::Dump(Stream *s, bool show_fullpaths) const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
if (m_name)
|
|
|
|
*s << ", name = \"" << m_name << "\"";
|
2010-09-15 13:51:24 +08:00
|
|
|
m_declaration.Dump(s, show_fullpaths);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
FunctionInfo::Compare(const FunctionInfo& a, const FunctionInfo& b)
|
|
|
|
{
|
|
|
|
int result = ConstString::Compare(a.GetName(), b.GetName());
|
|
|
|
if (result)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
return Declaration::Compare(a.m_declaration, b.m_declaration);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Declaration&
|
|
|
|
FunctionInfo::GetDeclaration()
|
|
|
|
{
|
|
|
|
return m_declaration;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Declaration&
|
|
|
|
FunctionInfo::GetDeclaration() const
|
|
|
|
{
|
|
|
|
return m_declaration;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ConstString&
|
|
|
|
FunctionInfo::GetName() const
|
|
|
|
{
|
|
|
|
return m_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
FunctionInfo::MemorySize() const
|
|
|
|
{
|
|
|
|
return m_name.MemorySize() + m_declaration.MemorySize();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
InlineFunctionInfo::InlineFunctionInfo
|
|
|
|
(
|
|
|
|
const char *name,
|
|
|
|
const char *mangled,
|
|
|
|
const Declaration *decl_ptr,
|
|
|
|
const Declaration *call_decl_ptr
|
|
|
|
) :
|
|
|
|
FunctionInfo(name, decl_ptr),
|
|
|
|
m_mangled(mangled, true),
|
|
|
|
m_call_decl (call_decl_ptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
InlineFunctionInfo::InlineFunctionInfo
|
|
|
|
(
|
|
|
|
const ConstString& name,
|
|
|
|
const Mangled &mangled,
|
|
|
|
const Declaration *decl_ptr,
|
|
|
|
const Declaration *call_decl_ptr
|
|
|
|
) :
|
|
|
|
FunctionInfo(name, decl_ptr),
|
|
|
|
m_mangled(mangled),
|
|
|
|
m_call_decl (call_decl_ptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
InlineFunctionInfo::~InlineFunctionInfo()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
InlineFunctionInfo::Compare(const InlineFunctionInfo& a, const InlineFunctionInfo& b)
|
|
|
|
{
|
|
|
|
|
|
|
|
int result = FunctionInfo::Compare(a, b);
|
|
|
|
if (result)
|
|
|
|
return result;
|
|
|
|
// only compare the mangled names if both have them
|
|
|
|
return Mangled::Compare(a.m_mangled, a.m_mangled);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-09-15 13:51:24 +08:00
|
|
|
InlineFunctionInfo::Dump(Stream *s, bool show_fullpaths) const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-09-15 13:51:24 +08:00
|
|
|
FunctionInfo::Dump(s, show_fullpaths);
|
2010-06-09 00:52:24 +08:00
|
|
|
if (m_mangled)
|
|
|
|
m_mangled.Dump(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
InlineFunctionInfo::DumpStopContext (Stream *s) const
|
|
|
|
{
|
|
|
|
// s->Indent("[inlined] ");
|
|
|
|
s->Indent();
|
|
|
|
if (m_mangled)
|
|
|
|
s->PutCString (m_mangled.GetName().AsCString());
|
|
|
|
else
|
|
|
|
s->PutCString (m_name.AsCString());
|
|
|
|
}
|
|
|
|
|
Added support for inlined stack frames being represented as real stack frames
which is now on by default. Frames are gotten from the unwinder as concrete
frames, then if inline frames are to be shown, extra information to track
and reconstruct these frames is cached with each Thread and exanded as needed.
I added an inline height as part of the lldb_private::StackID class, the class
that helps us uniquely identify stack frames. This allows for two frames to
shared the same call frame address, yet differ only in inline height.
Fixed setting breakpoint by address to not require addresses to resolve.
A quick example:
% cat main.cpp
% ./build/Debug/lldb test/stl/a.out
Current executable set to 'test/stl/a.out' (x86_64).
(lldb) breakpoint set --address 0x0000000100000d31
Breakpoint created: 1: address = 0x0000000100000d31, locations = 1
(lldb) r
Launching 'a.out' (x86_64)
(lldb) Process 38031 Stopped
* thread #1: tid = 0x2e03, pc = 0x0000000100000d31, where = a.out`main [inlined] std::string::_M_data() const at /usr/include/c++/4.2.1/bits/basic_string.h:280, stop reason = breakpoint 1.1, queue = com.apple.main-thread
277
278 _CharT*
279 _M_data() const
280 -> { return _M_dataplus._M_p; }
281
282 _CharT*
283 _M_data(_CharT* __p)
(lldb) bt
thread #1: tid = 0x2e03, stop reason = breakpoint 1.1, queue = com.apple.main-thread
frame #0: pc = 0x0000000100000d31, where = a.out`main [inlined] std::string::_M_data() const at /usr/include/c++/4.2.1/bits/basic_string.h:280
frame #1: pc = 0x0000000100000d31, where = a.out`main [inlined] std::string::_M_rep() const at /usr/include/c++/4.2.1/bits/basic_string.h:288
frame #2: pc = 0x0000000100000d31, where = a.out`main [inlined] std::string::size() const at /usr/include/c++/4.2.1/bits/basic_string.h:606
frame #3: pc = 0x0000000100000d31, where = a.out`main [inlined] operator<< <char, std::char_traits<char>, std::allocator<char> > at /usr/include/c++/4.2.1/bits/basic_string.h:2414
frame #4: pc = 0x0000000100000d31, where = a.out`main + 33 at /Volumes/work/gclayton/Documents/src/lldb/test/stl/main.cpp:14
frame #5: pc = 0x0000000100000d08, where = a.out`start + 52
Each inline frame contains only the variables that they contain and each inlined
stack frame is treated as a single entity.
llvm-svn: 111877
2010-08-24 08:45:41 +08:00
|
|
|
|
|
|
|
const ConstString &
|
|
|
|
InlineFunctionInfo::GetName () const
|
|
|
|
{
|
|
|
|
if (m_mangled)
|
|
|
|
return m_mangled.GetName();
|
|
|
|
return m_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
Declaration &
|
|
|
|
InlineFunctionInfo::GetCallSite ()
|
|
|
|
{
|
|
|
|
return m_call_decl;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Declaration &
|
|
|
|
InlineFunctionInfo::GetCallSite () const
|
|
|
|
{
|
|
|
|
return m_call_decl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Mangled&
|
|
|
|
InlineFunctionInfo::GetMangled()
|
|
|
|
{
|
|
|
|
return m_mangled;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Mangled&
|
|
|
|
InlineFunctionInfo::GetMangled() const
|
|
|
|
{
|
|
|
|
return m_mangled;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
InlineFunctionInfo::MemorySize() const
|
|
|
|
{
|
|
|
|
return FunctionInfo::MemorySize() + m_mangled.MemorySize();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
Function::Function
|
|
|
|
(
|
|
|
|
CompileUnit *comp_unit,
|
|
|
|
lldb::user_id_t func_uid,
|
|
|
|
lldb::user_id_t type_uid,
|
|
|
|
const Mangled &mangled,
|
|
|
|
Type * type,
|
|
|
|
const AddressRange& range
|
|
|
|
) :
|
2010-08-21 10:22:51 +08:00
|
|
|
UserID (func_uid),
|
|
|
|
m_comp_unit (comp_unit),
|
|
|
|
m_type_uid (type_uid),
|
|
|
|
m_type (type),
|
|
|
|
m_mangled (mangled),
|
|
|
|
m_block (func_uid),
|
|
|
|
m_range (range),
|
|
|
|
m_frame_base (),
|
|
|
|
m_flags (),
|
|
|
|
m_prologue_byte_size (0)
|
|
|
|
{
|
|
|
|
m_block.SetParentScope(this);
|
2010-06-09 00:52:24 +08:00
|
|
|
assert(comp_unit != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
Function::Function
|
|
|
|
(
|
|
|
|
CompileUnit *comp_unit,
|
|
|
|
lldb::user_id_t func_uid,
|
|
|
|
lldb::user_id_t type_uid,
|
|
|
|
const char *mangled,
|
|
|
|
Type *type,
|
|
|
|
const AddressRange &range
|
|
|
|
) :
|
2010-08-21 10:22:51 +08:00
|
|
|
UserID (func_uid),
|
|
|
|
m_comp_unit (comp_unit),
|
|
|
|
m_type_uid (type_uid),
|
|
|
|
m_type (type),
|
|
|
|
m_mangled (mangled, true),
|
|
|
|
m_block (func_uid),
|
|
|
|
m_range (range),
|
|
|
|
m_frame_base (),
|
|
|
|
m_flags (),
|
|
|
|
m_prologue_byte_size (0)
|
|
|
|
{
|
|
|
|
m_block.SetParentScope(this);
|
2010-06-09 00:52:24 +08:00
|
|
|
assert(comp_unit != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Function::~Function()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-08-20 09:15:01 +08:00
|
|
|
void
|
|
|
|
Function::GetStartLineSourceInfo (FileSpec &source_file, uint32_t &line_no)
|
|
|
|
{
|
|
|
|
line_no = 0;
|
|
|
|
source_file.Clear();
|
|
|
|
|
|
|
|
if (m_comp_unit == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (m_type != NULL && m_type->GetDeclaration().GetLine() != 0)
|
|
|
|
{
|
|
|
|
source_file = m_type->GetDeclaration().GetFile();
|
|
|
|
line_no = m_type->GetDeclaration().GetLine();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LineTable *line_table = m_comp_unit->GetLineTable();
|
|
|
|
if (line_table == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
LineEntry line_entry;
|
|
|
|
if (line_table->FindLineEntryByAddress (GetAddressRange().GetBaseAddress(), line_entry, NULL))
|
|
|
|
{
|
|
|
|
line_no = line_entry.line;
|
|
|
|
source_file = line_entry.file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Function::GetEndLineSourceInfo (FileSpec &source_file, uint32_t &line_no)
|
|
|
|
{
|
|
|
|
line_no = 0;
|
|
|
|
source_file.Clear();
|
|
|
|
|
|
|
|
// The -1 is kind of cheesy, but I want to get the last line entry for the given function, not the
|
|
|
|
// first entry of the next.
|
|
|
|
Address scratch_addr(GetAddressRange().GetBaseAddress());
|
|
|
|
scratch_addr.SetOffset (scratch_addr.GetOffset() + GetAddressRange().GetByteSize() - 1);
|
|
|
|
|
|
|
|
LineTable *line_table = m_comp_unit->GetLineTable();
|
|
|
|
if (line_table == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
LineEntry line_entry;
|
|
|
|
if (line_table->FindLineEntryByAddress (scratch_addr, line_entry, NULL))
|
|
|
|
{
|
|
|
|
line_no = line_entry.line;
|
|
|
|
source_file = line_entry.file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-21 10:22:51 +08:00
|
|
|
Block &
|
|
|
|
Function::GetBlock (bool can_create)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-08-21 10:22:51 +08:00
|
|
|
if (!m_block.BlockInfoHasBeenParsed() && can_create)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
SymbolContext sc;
|
|
|
|
CalculateSymbolContext(&sc);
|
2011-06-24 11:47:23 +08:00
|
|
|
if (sc.module_sp)
|
|
|
|
{
|
|
|
|
sc.module_sp->GetSymbolVendor()->ParseFunctionBlocks(sc);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
::fprintf (stderr,
|
|
|
|
"unable to find module shared pointer for function '%s' in %s%s%s\n",
|
|
|
|
GetName().GetCString(),
|
|
|
|
m_comp_unit->GetDirectory().GetCString(),
|
|
|
|
m_comp_unit->GetDirectory() ? "/" : "",
|
|
|
|
m_comp_unit->GetFilename().GetCString());
|
|
|
|
}
|
2010-08-21 10:22:51 +08:00
|
|
|
m_block.SetBlockInfoHasBeenParsed (true, true);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2010-08-21 10:22:51 +08:00
|
|
|
return m_block;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CompileUnit*
|
|
|
|
Function::GetCompileUnit()
|
|
|
|
{
|
|
|
|
return m_comp_unit;
|
|
|
|
}
|
|
|
|
|
|
|
|
const CompileUnit*
|
|
|
|
Function::GetCompileUnit() const
|
|
|
|
{
|
|
|
|
return m_comp_unit;
|
|
|
|
}
|
|
|
|
|
2010-06-29 05:30:43 +08:00
|
|
|
|
|
|
|
void
|
2010-09-15 07:36:40 +08:00
|
|
|
Function::GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target)
|
2010-06-29 05:30:43 +08:00
|
|
|
{
|
|
|
|
Type* func_type = GetType();
|
2010-09-10 09:30:46 +08:00
|
|
|
*s << "id = " << (const UserID&)*this << ", name = \"" << func_type->GetName() << "\", range = ";
|
|
|
|
|
|
|
|
Address::DumpStyle fallback_style;
|
|
|
|
if (level == eDescriptionLevelVerbose)
|
|
|
|
fallback_style = Address::DumpStyleModuleWithFileAddress;
|
|
|
|
else
|
|
|
|
fallback_style = Address::DumpStyleFileAddress;
|
2010-09-15 07:36:40 +08:00
|
|
|
GetAddressRange().Dump(s, target, Address::DumpStyleLoadAddress, fallback_style);
|
2010-06-29 05:30:43 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void
|
|
|
|
Function::Dump(Stream *s, bool show_context) const
|
|
|
|
{
|
2011-09-21 05:44:10 +08:00
|
|
|
s->Printf("%p: ", this);
|
2010-06-09 00:52:24 +08:00
|
|
|
s->Indent();
|
|
|
|
*s << "Function" << (const UserID&)*this;
|
|
|
|
|
|
|
|
m_mangled.Dump(s);
|
|
|
|
|
|
|
|
if (m_type)
|
|
|
|
{
|
2011-09-21 05:44:10 +08:00
|
|
|
s->Printf(", type = %p", m_type);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
else if (m_type_uid != LLDB_INVALID_UID)
|
2011-08-17 02:19:31 +08:00
|
|
|
{
|
|
|
|
s->Printf(", type_uid = 0x%8.8x", m_type_uid);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
s->EOL();
|
|
|
|
// Dump the root object
|
2010-08-21 10:22:51 +08:00
|
|
|
if (m_block.BlockInfoHasBeenParsed ())
|
|
|
|
m_block.Dump(s, m_range.GetBaseAddress().GetFileAddress(), INT_MAX, show_context);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
Function::CalculateSymbolContext(SymbolContext* sc)
|
|
|
|
{
|
|
|
|
sc->function = this;
|
|
|
|
m_comp_unit->CalculateSymbolContext(sc);
|
|
|
|
}
|
|
|
|
|
2011-08-13 05:40:01 +08:00
|
|
|
Module *
|
|
|
|
Function::CalculateSymbolContextModule ()
|
|
|
|
{
|
2011-10-08 06:20:35 +08:00
|
|
|
const Section *section = m_range.GetBaseAddress().GetSection();
|
|
|
|
if (section)
|
|
|
|
{
|
|
|
|
const Section *linked_section = section->GetLinkedSection();
|
|
|
|
if (linked_section)
|
|
|
|
return linked_section->GetModule();
|
|
|
|
else
|
|
|
|
return section->GetModule();
|
|
|
|
}
|
|
|
|
|
2011-08-13 05:40:01 +08:00
|
|
|
return this->GetCompileUnit()->GetModule();
|
|
|
|
}
|
|
|
|
|
|
|
|
CompileUnit *
|
|
|
|
Function::CalculateSymbolContextCompileUnit ()
|
|
|
|
{
|
|
|
|
return this->GetCompileUnit();
|
|
|
|
}
|
|
|
|
|
|
|
|
Function *
|
|
|
|
Function::CalculateSymbolContextFunction ()
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Symbol *
|
|
|
|
//Function::CalculateSymbolContextSymbol ()
|
|
|
|
//{
|
|
|
|
// return // TODO: find the symbol for the function???
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void
|
|
|
|
Function::DumpSymbolContext(Stream *s)
|
|
|
|
{
|
|
|
|
m_comp_unit->DumpSymbolContext(s);
|
|
|
|
s->Printf(", Function{0x%8.8x}", GetID());
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
Function::MemorySize () const
|
|
|
|
{
|
2010-08-21 10:22:51 +08:00
|
|
|
size_t mem_size = sizeof(Function) + m_block.MemorySize();
|
2010-06-09 00:52:24 +08:00
|
|
|
return mem_size;
|
|
|
|
}
|
|
|
|
|
2011-08-06 07:43:37 +08:00
|
|
|
clang::DeclContext *
|
|
|
|
Function::GetClangDeclContext()
|
|
|
|
{
|
|
|
|
SymbolContext sc;
|
|
|
|
|
|
|
|
CalculateSymbolContext (&sc);
|
|
|
|
|
|
|
|
if (!sc.module_sp)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
SymbolVendor *sym_vendor = sc.module_sp->GetSymbolVendor();
|
|
|
|
|
|
|
|
if (!sym_vendor)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
SymbolFile *sym_file = sym_vendor->GetSymbolFile();
|
|
|
|
|
|
|
|
if (!sym_file)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return sym_file->GetClangDeclContextForTypeUID (sc, m_uid);
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
Type*
|
|
|
|
Function::GetType()
|
|
|
|
{
|
2011-09-30 11:20:47 +08:00
|
|
|
if (m_type == NULL)
|
|
|
|
{
|
|
|
|
SymbolContext sc;
|
|
|
|
|
|
|
|
CalculateSymbolContext (&sc);
|
|
|
|
|
|
|
|
if (!sc.module_sp)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
SymbolVendor *sym_vendor = sc.module_sp->GetSymbolVendor();
|
|
|
|
|
|
|
|
if (sym_vendor == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
SymbolFile *sym_file = sym_vendor->GetSymbolFile();
|
|
|
|
|
|
|
|
if (sym_file == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2011-10-06 06:22:08 +08:00
|
|
|
m_type = sym_file->ResolveTypeUID(m_type_uid);
|
2011-09-30 11:20:47 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
return m_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Type*
|
|
|
|
Function::GetType() const
|
|
|
|
{
|
|
|
|
return m_type;
|
|
|
|
}
|
|
|
|
|
2011-02-17 07:00:21 +08:00
|
|
|
clang_type_t
|
|
|
|
Function::GetReturnClangType ()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-02-17 07:00:21 +08:00
|
|
|
clang::QualType clang_type (clang::QualType::getFromOpaquePtr(GetType()->GetClangFullType()));
|
2011-07-30 10:42:06 +08:00
|
|
|
const clang::FunctionType *function_type = llvm::dyn_cast<clang::FunctionType> (clang_type);
|
2011-02-17 07:00:21 +08:00
|
|
|
if (function_type)
|
|
|
|
return function_type->getResultType().getAsOpaquePtr();
|
|
|
|
return NULL;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
Function::GetArgumentCount ()
|
|
|
|
{
|
2011-02-17 07:00:21 +08:00
|
|
|
clang::QualType clang_type (clang::QualType::getFromOpaquePtr(GetType()->GetClangFullType()));
|
2010-06-09 00:52:24 +08:00
|
|
|
assert (clang_type->isFunctionType());
|
|
|
|
if (!clang_type->isFunctionProtoType())
|
|
|
|
return -1;
|
|
|
|
|
2011-07-30 10:42:06 +08:00
|
|
|
const clang::FunctionProtoType *function_proto_type = llvm::dyn_cast<clang::FunctionProtoType>(clang_type);
|
2010-06-09 00:52:24 +08:00
|
|
|
if (function_proto_type != NULL)
|
|
|
|
return function_proto_type->getNumArgs();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-02-17 07:00:21 +08:00
|
|
|
clang_type_t
|
2010-06-09 00:52:24 +08:00
|
|
|
Function::GetArgumentTypeAtIndex (size_t idx)
|
|
|
|
{
|
2011-02-17 07:00:21 +08:00
|
|
|
clang::QualType clang_type (clang::QualType::getFromOpaquePtr(GetType()->GetClangFullType()));
|
2011-07-30 10:42:06 +08:00
|
|
|
const clang::FunctionProtoType *function_proto_type = llvm::dyn_cast<clang::FunctionProtoType>(clang_type);
|
2011-02-17 07:00:21 +08:00
|
|
|
if (function_proto_type)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
unsigned num_args = function_proto_type->getNumArgs();
|
|
|
|
if (idx >= num_args)
|
2011-02-17 07:00:21 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return (function_proto_type->arg_type_begin())[idx].getAsOpaquePtr();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Function::IsVariadic ()
|
|
|
|
{
|
2011-02-17 07:00:21 +08:00
|
|
|
const clang::Type *clang_type = static_cast<clang::QualType *>(GetType()->GetClangFullType())->getTypePtr();
|
2010-06-09 00:52:24 +08:00
|
|
|
assert (clang_type->isFunctionType());
|
|
|
|
if (!clang_type->isFunctionProtoType())
|
|
|
|
return false;
|
|
|
|
|
2011-07-30 10:42:06 +08:00
|
|
|
const clang::FunctionProtoType *function_proto_type = llvm::dyn_cast<clang::FunctionProtoType>(clang_type);
|
2011-02-17 07:00:21 +08:00
|
|
|
if (function_proto_type)
|
2010-06-09 00:52:24 +08:00
|
|
|
return function_proto_type->isVariadic();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
Function::GetPrologueByteSize ()
|
|
|
|
{
|
|
|
|
if (m_prologue_byte_size == 0 && m_flags.IsClear(flagsCalculatedPrologueSize))
|
|
|
|
{
|
|
|
|
m_flags.Set(flagsCalculatedPrologueSize);
|
|
|
|
LineTable* line_table = m_comp_unit->GetLineTable ();
|
|
|
|
if (line_table)
|
|
|
|
{
|
|
|
|
LineEntry line_entry;
|
|
|
|
if (line_table->FindLineEntryByAddress(GetAddressRange().GetBaseAddress(), line_entry))
|
2010-11-12 04:13:30 +08:00
|
|
|
{
|
|
|
|
// We need to take the delta of the end of the first line entry
|
|
|
|
// as a file address and the start file address of the function
|
|
|
|
// in case the first line entry doesn't start at the beginning
|
|
|
|
// of the function.
|
|
|
|
const addr_t func_start_file_addr = m_range.GetBaseAddress().GetFileAddress();
|
|
|
|
const addr_t line_entry_end_file_addr = line_entry.range.GetBaseAddress().GetFileAddress() + line_entry.range.GetByteSize();
|
|
|
|
if (line_entry_end_file_addr > func_start_file_addr)
|
|
|
|
m_prologue_byte_size = line_entry_end_file_addr - func_start_file_addr;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return m_prologue_byte_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|