<commit_before>//===-- ValueObject.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/Core/ValueObject.h"

// C Includes
// C++ Includes
// Other libraries and framework includes
#include "llvm/Support/raw_ostream.h"

// Project includes
#include "lldb/Core/DataBufferHeap.h"
#include "lldb/Core/StreamString.h"
#include "lldb/Core/ValueObjectChild.h"
#include "lldb/Core/ValueObjectList.h"

#include "lldb/Symbol/ClangASTType.h"
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Symbol/Type.h"

#include "lldb/Target/Process.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Target/Thread.h"
#include <stdlib.h>

using namespace lldb;
using namespace lldb_private;

static lldb::user_id_t g_value_obj_uid = 0;

//----------------------------------------------------------------------
// ValueObject constructor
//----------------------------------------------------------------------
ValueObject::ValueObject () :
    UserID (++g_value_obj_uid), // Unique identifier for every value object
    m_update_id (0),    // Value object lists always start at 1, value objects start at zero
    m_name (),
    m_data (),
    m_value (),
    m_error (),
    m_flags (),
    m_value_str(),
    m_location_str(),
    m_summary_str(),
    m_children(),
    m_synthetic_children()
{
}

//----------------------------------------------------------------------
// Destructor
//----------------------------------------------------------------------
ValueObject::~ValueObject ()
{
}

user_id_t
ValueObject::GetUpdateID() const
{
    return m_update_id;
}

bool
ValueObject::UpdateValueIfNeeded (ExecutionContextScope *exe_scope)
{
    if (exe_scope)
    {
        Process *process = exe_scope->CalculateProcess();
        if (process)
        {
            const user_id_t stop_id = process->GetStopID();
            if (m_update_id != stop_id)
            {
                m_value_str.clear();
                m_location_str.clear();
                m_summary_str.clear();

                UpdateValue (exe_scope);
                if (m_error.Success())
                    m_update_id = stop_id;
            }
        }
    }
    return m_error.Success();
}

const DataExtractor &
ValueObject::GetDataExtractor () const
{
    return m_data;
}

DataExtractor &
ValueObject::GetDataExtractor ()
{
    return m_data;
}

const Error &
ValueObject::GetError() const<commit_msg>Detect when ValueObject values change each time they are evaluated.<commit_after>//===-- ValueObject.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/Core/ValueObject.h"

// C Includes
// C++ Includes
// Other libraries and framework includes
#include "llvm/Support/raw_ostream.h"

// Project includes
#include "lldb/Core/DataBufferHeap.h"
#include "lldb/Core/StreamString.h"
#include "lldb/Core/ValueObjectChild.h"
#include "lldb/Core/ValueObjectList.h"

#include "lldb/Symbol/ClangASTType.h"
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Symbol/Type.h"

#include "lldb/Target/Process.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Target/Thread.h"
#include <stdlib.h>

using namespace lldb;
using namespace lldb_private;

static lldb::user_id_t g_value_obj_uid = 0;

//----------------------------------------------------------------------
// ValueObject constructor
//----------------------------------------------------------------------
ValueObject::ValueObject () :
    UserID (++g_value_obj_uid), // Unique identifier for every value object
    m_update_id (0),    // Value object lists always start at 1, value objects start at zero
    m_name (),
    m_data (),
    m_value (),
    m_error (),
    m_flags (),
    m_value_str(),
    m_location_str(),
    m_summary_str(),
    m_children(),
    m_synthetic_children()
{
}

//----------------------------------------------------------------------
// Destructor
//----------------------------------------------------------------------
ValueObject::~ValueObject ()
{
}

user_id_t
ValueObject::GetUpdateID() const
{
    return m_update_id;
}

bool
ValueObject::UpdateValueIfNeeded (ExecutionContextScope *exe_scope)
{
    if (exe_scope)
    {
        Process *process = exe_scope->CalculateProcess();
        if (process)
        {
            const user_id_t stop_id = process->GetStopID();
            if (m_update_id != stop_id)
            {
                // Save the old value using swap to avoid a string copy which
                // also will clear our m_value_str
                std::string old_value_str;
                old_value_str.swap (m_value_str);
                m_location_str.clear();
                m_summary_str.clear();

                const bool value_was_valid = GetValueIsValid();
                SetValueDidChange (false);

                m_error.Clear();

                // Call the pure virtual function to update the value
                UpdateValue (exe_scope);
                
                // Update the fact that we tried to update the value for this
                // value object wether or not we succeed
                m_update_id = stop_id;
                bool success = m_error.Success();
                SetValueIsValid (success);
                // If the variable hasn't already been marked as changed do it
                // by comparing the old any new value
                if (!GetValueDidChange())
                {
                    if (success)
                    {
                        // The value was gotten successfully, so we consider the
                        // value as changed if the value string differs
                        SetValueDidChange (old_value_str != m_value_str);
                    }
                    else
                    {
                        // The value wasn't gotten successfully, so we mark this
                        // as changed if the value used to be valid and now isn't
                        SetValueDidChange (value_was_valid);
                    }
                }
            }
        }
    }
    return m_error.Success();
}

const DataExtractor &
ValueObject::GetDataExtractor () const
{
    return m_data;
}

DataExtractor &
ValueObject::GetDataExtractor ()
{
    return m_data;
}

const Error &
ValueObject::GetError() const
{'fraction_non_alphanumeric': 0.21235805928329154, 'fraction_numerical': 0.0008848252470137148, 'mean_word_length': 1.5277674245247856, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '2199987', 'n_tokens_mistral': 1872, 'n_tokens_neox': 1797, 'n_words': 442}