<commit_before>//===-- 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/Module.h"
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Symbol/Symbol.h"
#include "lldb/Symbol/SymbolVendor.h"
#include "lldb/Target/Target.h"

using namespace lldb;
using namespace lldb_private;

SymbolContext::SymbolContext() :
    target_sp   (),
    module_sp   (),
    comp_unit   (NULL),
    function    (NULL),
    block       (NULL),
    line_entry  (),
    symbol      (NULL)
{
}

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  (),
    symbol      (s)
{
    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  (),
    symbol      (s)
{
    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)
{
}


SymbolContext::SymbolContext (SymbolContextScope *sc_scope) :
    target_sp   (),
    module_sp   (),
    comp_unit   (NULL),
    function    (NULL),
    block       (NULL),
    line_entry  (),
    symbol      (NULL)
{
    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;
    }
    return *this;
}

void
SymbolContext::Clear()
{
    target_sp.reset();
    module_sp.reset();
    comp_unit   = NULL;
    function    = NULL;
    block       = NULL;
    line_entry.Clear();
    symbol      = NULL;
}

void
SymbolContext::DumpStopContext
(
    Stream *s,
    ExecutionContextScope *exe_scope,
    const Address &addr,
    bool show_fullpaths,
    bool show_module,
    bool show_inlined_frames
) const
{
    if (show_module && module_sp)
    {
        if (show_fullpaths)
            *s << module_sp->GetFileSpec();
        else
            *s << module_sp->GetFileSpec().GetFilename();
        s->PutChar('`');
    }

    if (function != NULL)
    {
        if (function->GetMangled().GetName())
            function->GetMangled().GetName().Dump(s);

        if (show_inlined_frames && block)
        {
            const InlineFunctionInfo *inline_info = block->GetInlinedFunctionInfo();
            if (inline_info == NULL)
            {
                const Block *parent_inline_block = block->GetInlinedParent();
                if (parent_inline_block)
                    inline_info = parent_inline_block->GetInlinedFunctionInfo();
            }

            if (inline_info)
            {
                s->PutCString(" [inlined] ");
                inline_info->GetName().Dump(s);
                
                if (line_entry.IsValid())
                {
                    s->PutCString(" at ");
                    line_entry.DumpStopContext(s, show_fullpaths);
                }
                return;
            }
        }
        const addr_t function_offset = addr.GetOffset() - function->GetAddressRange().GetBaseAddress().GetOffset();
        if (function_offset)
            s->Printf(" + %llu", function_offset);

        if (block != NULL)
        {
            s->IndentMore();
            block->DumpStopContext (s, this, NULL, show_fullpaths, show_inlined_frames);
            s->IndentLess();
        }
        else
        {
            if (line_entry.IsValid())
            {
                s->PutCString(" at ");
                if (line_entry.DumpStopContext(s, show_fullpaths))
                    return;
            }
        }
    }
    else if (symbol != NULL)
    {
        symbol->GetMangled().GetName().Dump(s);

        if (symbol->GetAddressRangePtr())
        {
            const addr_t symbol_offset = addr.GetOffset() - symbol->GetAddressRangePtr()->GetBaseAddress().GetOffset();
            if (symbol_offset)
                s->Printf(" + %llu", symbol_offset);
        }
    }
    else
    {
        addr.Dump(s, exe_scope, Address::DumpStyleModuleWithFileAddress);
    }
}<commit_msg>Make sure the address passed into SymbolContext::DumpStopContext() is valid before trying to calculate any offsets.<commit_after>//===-- 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/Module.h"
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Symbol/Symbol.h"
#include "lldb/Symbol/SymbolVendor.h"
#include "lldb/Target/Target.h"

using namespace lldb;
using namespace lldb_private;

SymbolContext::SymbolContext() :
    target_sp   (),
    module_sp   (),
    comp_unit   (NULL),
    function    (NULL),
    block       (NULL),
    line_entry  (),
    symbol      (NULL)
{
}

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  (),
    symbol      (s)
{
    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  (),
    symbol      (s)
{
    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)
{
}


SymbolContext::SymbolContext (SymbolContextScope *sc_scope) :
    target_sp   (),
    module_sp   (),
    comp_unit   (NULL),
    function    (NULL),
    block       (NULL),
    line_entry  (),
    symbol      (NULL)
{
    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;
    }
    return *this;
}

void
SymbolContext::Clear()
{
    target_sp.reset();
    module_sp.reset();
    comp_unit   = NULL;
    function    = NULL;
    block       = NULL;
    line_entry.Clear();
    symbol      = NULL;
}

void
SymbolContext::DumpStopContext
(
    Stream *s,
    ExecutionContextScope *exe_scope,
    const Address &addr,
    bool show_fullpaths,
    bool show_module,
    bool show_inlined_frames
) const
{
    if (show_module && module_sp)
    {
        if (show_fullpaths)
            *s << module_sp->GetFileSpec();
        else
            *s << module_sp->GetFileSpec().GetFilename();
        s->PutChar('`');
    }

    if (function != NULL)
    {
        if (function->GetMangled().GetName())
            function->GetMangled().GetName().Dump(s);

        if (show_inlined_frames && block)
        {
            const InlineFunctionInfo *inline_info = block->GetInlinedFunctionInfo();
            if (inline_info == NULL)
            {
                const Block *parent_inline_block = block->GetInlinedParent();
                if (parent_inline_block)
                    inline_info = parent_inline_block->GetInlinedFunctionInfo();
            }

            if (inline_info)
            {
                s->PutCString(" [inlined] ");
                inline_info->GetName().Dump(s);
                
                if (line_entry.IsValid())
                {
                    s->PutCString(" at ");
                    line_entry.DumpStopContext(s, show_fullpaths);
                }
                return;
            }
        }
        if (addr.IsValid())
        {
            const addr_t function_offset = addr.GetOffset() - function->GetAddressRange().GetBaseAddress().GetOffset();
            if (function_offset)
                s->Printf(" + %llu", function_offset);
        }

        if (block != NULL)
        {
            s->IndentMore();
            block->DumpStopContext (s, this, NULL, show_fullpaths, show_inlined_frames);
            s->IndentLess();
        }
        else
        {
            if (line_entry.IsValid())
            {
                s->PutCString(" at ");
                if (line_entry.DumpStopContext(s, show_fullpaths))
                    return;
            }
        }
    }
    else if (symbol != NULL)
    {
        symbol->GetMangled().GetName().Dump(s);

        if (addr.IsValid() && symbol->GetAddressRangePtr())
        {
            const addr_t symbol_offset = addr.GetOffset() - symbol->GetAddressRangePtr()->GetBaseAddress().GetOffset();
            if (symbol_offset)
                s->Printf(" + %llu", symbol_offset);
        }
    }
    else if (addr.IsValid())
    {
        addr.Dump(s, exe_scope, Address::DumpStyleModuleWithFileAddress);
    }
}
{'fraction_non_alphanumeric': 0.1456876456876457, 'fraction_numerical': 0.0, 'mean_word_length': 1.811083811083811, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '222553', 'n_tokens_mistral': 3178, 'n_tokens_neox': 3122, 'n_words': 623}