Skip to content
SymbolContext.cpp 38.4 KiB
Newer Older
//===-- SymbolContext.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/SymbolContext.h"
#include "lldb/Core/Log.h"
#include "lldb/Core/Module.h"
Greg Clayton's avatar
Greg Clayton committed
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Host/StringConvert.h"
Greg Clayton's avatar
Greg Clayton committed
#include "lldb/Symbol/Block.h"
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Symbol/Symbol.h"
#include "lldb/Symbol/SymbolFile.h"
#include "lldb/Symbol/SymbolVendor.h"
#include "lldb/Symbol/Variable.h"
#include "lldb/Target/Target.h"

using namespace lldb;
using namespace lldb_private;

SymbolContext::SymbolContext() :
    target_sp   (),
    module_sp   (),
    comp_unit   (nullptr),
    function    (nullptr),
    block       (nullptr),
    symbol      (nullptr),
    variable    (nullptr)
{
}

SymbolContext::SymbolContext(const ModuleSP& m, CompileUnit *cu, Function *f, Block *b, LineEntry *le, Symbol *s) :
    target_sp   (),
    module_sp   (m),
    comp_unit   (cu),
    function    (f),
    block       (b),
    line_entry  (),
{
    if (le)
        line_entry = *le;
}

SymbolContext::SymbolContext(const TargetSP &t, const ModuleSP& m, CompileUnit *cu, Function *f, Block *b, LineEntry *le, Symbol *s) :
    target_sp   (t),
    module_sp   (m),
    comp_unit   (cu),
    function    (f),
    block       (b),
    line_entry  (),
{
    if (le)
        line_entry = *le;
}

SymbolContext::SymbolContext(const SymbolContext& rhs) :
    target_sp   (rhs.target_sp),
    module_sp   (rhs.module_sp),
    comp_unit   (rhs.comp_unit),
    function    (rhs.function),
    block       (rhs.block),
    line_entry  (rhs.line_entry),
    symbol      (rhs.symbol),
    variable    (rhs.variable)
{
}


SymbolContext::SymbolContext (SymbolContextScope *sc_scope) :
    target_sp   (),
    module_sp   (),
    comp_unit   (nullptr),
    function    (nullptr),
    block       (nullptr),
    symbol      (nullptr),
    variable    (nullptr)
{
    sc_scope->CalculateSymbolContext (this);
}

const SymbolContext&
SymbolContext::operator= (const SymbolContext& rhs)
{
    if (this != &rhs)
    {
        target_sp   = rhs.target_sp;
        module_sp   = rhs.module_sp;
        comp_unit   = rhs.comp_unit;
        function    = rhs.function;
        block       = rhs.block;
        line_entry  = rhs.line_entry;
        symbol      = rhs.symbol;
SymbolContext::Clear(bool clear_target)
    if (clear_target)
        target_sp.reset();
    comp_unit   = nullptr;
    function    = nullptr;
    block       = nullptr;
SymbolContext::DumpStopContext (
    Stream *s,
    ExecutionContextScope *exe_scope,
    const Address &addr,
    bool show_function_arguments,
    bool show_function_name
    bool dumped_something = false;
    if (show_module && module_sp)
    {
        if (show_fullpaths)
            *s << module_sp->GetFileSpec();
        else
            *s << module_sp->GetFileSpec().GetFilename();
        s->PutChar('`');
        SymbolContext inline_parent_sc;
        Address inline_parent_addr;
        if (show_function_name == false)
        {
            s->Printf("<");
            dumped_something = true;
        }
            ConstString name;
            if (show_function_arguments == false)
                name = function->GetNameNoArguments();
            if (!name)
                name = function->GetName();
            if (name)
                name.Dump(s);
        if (addr.IsValid())
        {
            const addr_t function_offset = addr.GetOffset() - function->GetAddressRange().GetBaseAddress().GetOffset();
            if (show_function_name == false)
            {
                // Print +offset even if offset is 0
                dumped_something = true;
                s->Printf("+%" PRIu64 ">", function_offset);
            }
            else if (function_offset)
                s->Printf(" + %" PRIu64, function_offset);
        if (GetParentOfInlinedScope (addr, inline_parent_sc, inline_parent_addr))
            Block *inlined_block = block->GetContainingInlinedBlock();
            const InlineFunctionInfo* inlined_block_info = inlined_block->GetInlinedFunctionInfo();
            s->Printf (" [inlined] %s", inlined_block_info->GetName(function->GetLanguage()).GetCString());
            
            lldb_private::AddressRange block_range;
            if (inlined_block->GetRangeContainingAddress(addr, block_range))
            {
                const addr_t inlined_function_offset = addr.GetOffset() - block_range.GetBaseAddress().GetOffset();
Loading
Loading full blame...