<commit_before>//===-- Watchpoint.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/Breakpoint/Watchpoint.h"

// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
#include "lldb/Breakpoint/StoppointCallbackContext.h"
#include "lldb/Core/Stream.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/ThreadSpec.h"
#include "lldb/Expression/ClangUserExpression.h"

using namespace lldb;
using namespace lldb_private;

Watchpoint::Watchpoint (lldb::addr_t addr, size_t size, bool hardware) :
    StoppointLocation (0, addr, size, hardware),
    m_target(NULL),
    m_enabled(false),
    m_is_hardware(hardware),
    m_is_watch_variable(false),
    m_watch_read(0),
    m_watch_write(0),
    m_watch_was_read(0),
    m_watch_was_written(0),
    m_ignore_count(0),
    m_false_alarms(0),
    m_decl_str(),
    m_watch_spec_str(),
    m_snapshot_old_str(),
    m_snapshot_new_str(),
    m_snapshot_old_val(0),
    m_snapshot_new_val(0),
    m_error(),
    m_options ()
{
}

Watchpoint::~Watchpoint()
{
}

// This function is used when "baton" doesn't need to be freed
void
Watchpoint::SetCallback (WatchpointHitCallback callback, void *baton, bool is_synchronous)
{
    // The default "Baton" class will keep a copy of "baton" and won't free
    // or delete it when it goes goes out of scope.
    m_options.SetCallback(callback, BatonSP (new Baton(baton)), is_synchronous);
    
    //SendWatchpointChangedEvent (eWatchpointEventTypeCommandChanged);
}

// This function is used when a baton needs to be freed and therefore is 
// contained in a "Baton" subclass.
void
Watchpoint::SetCallback (WatchpointHitCallback callback, const BatonSP &callback_baton_sp, bool is_synchronous)
{
    m_options.SetCallback(callback, callback_baton_sp, is_synchronous);
}

void
Watchpoint::ClearCallback ()
{
    m_options.ClearCallback ();
}

void
Watchpoint::SetDeclInfo (const std::string &str)
{
    m_decl_str = str;
    return;
}

std::string
Watchpoint::GetWatchSpec()
{
    return m_watch_spec_str;
}

void
Watchpoint::SetWatchSpec (const std::string &str)
{
    m_watch_spec_str = str;
    return;
}

std::string
Watchpoint::GetOldSnapshot() const
{
    return m_snapshot_old_str;
}

void
Watchpoint::SetOldSnapshot (const std::string &str)
{
    size_t len = str.length();
    m_snapshot_old_str = str;
    if (len && str.at(len - 1) == '\n')
        m_snapshot_old_str.resize(len - 1);
    return;
}

std::string
Watchpoint::GetNewSnapshot() const
{
    return m_snapshot_new_str;
}

void
Watchpoint::SetNewSnapshot (const std::string &str)
{
    m_snapshot_old_str = m_snapshot_new_str;
    size_t len = str.length();
    m_snapshot_new_str = str;
    if (len && str.at(len - 1) == '\n')
        m_snapshot_new_str.resize(len - 1);
    return;
}

uint64_t
Watchpoint::GetOldSnapshotVal() const
{
    return m_snapshot_old_val;
}

void
Watchpoint::SetOldSnapshotVal (uint64_t val)
{
    m_snapshot_old_val = val;
    return;
}

uint64_t
Watchpoint::GetNewSnapshotVal() const
{
    return m_snapshot_new_val;
}

void
Watchpoint::SetNewSnapshotVal (uint64_t val)
{
    m_snapshot_old_val = m_snapshot_new_val;
    m_snapshot_new_val = val;
    return;
}

void<commit_msg>A little bit of refactoring.<commit_after>//===-- Watchpoint.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/Breakpoint/Watchpoint.h"

// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
#include "lldb/Breakpoint/StoppointCallbackContext.h"
#include "lldb/Core/Stream.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/ThreadSpec.h"
#include "lldb/Expression/ClangUserExpression.h"

using namespace lldb;
using namespace lldb_private;

Watchpoint::Watchpoint (lldb::addr_t addr, size_t size, bool hardware) :
    StoppointLocation (0, addr, size, hardware),
    m_target(NULL),
    m_enabled(false),
    m_is_hardware(hardware),
    m_is_watch_variable(false),
    m_watch_read(0),
    m_watch_write(0),
    m_watch_was_read(0),
    m_watch_was_written(0),
    m_ignore_count(0),
    m_false_alarms(0),
    m_decl_str(),
    m_watch_spec_str(),
    m_snapshot_old_str(),
    m_snapshot_new_str(),
    m_snapshot_old_val(0),
    m_snapshot_new_val(0),
    m_error(),
    m_options ()
{
}

Watchpoint::~Watchpoint()
{
}

// This function is used when "baton" doesn't need to be freed
void
Watchpoint::SetCallback (WatchpointHitCallback callback, void *baton, bool is_synchronous)
{
    // The default "Baton" class will keep a copy of "baton" and won't free
    // or delete it when it goes goes out of scope.
    m_options.SetCallback(callback, BatonSP (new Baton(baton)), is_synchronous);
    
    //SendWatchpointChangedEvent (eWatchpointEventTypeCommandChanged);
}

// This function is used when a baton needs to be freed and therefore is 
// contained in a "Baton" subclass.
void
Watchpoint::SetCallback (WatchpointHitCallback callback, const BatonSP &callback_baton_sp, bool is_synchronous)
{
    m_options.SetCallback(callback, callback_baton_sp, is_synchronous);
}

void
Watchpoint::ClearCallback ()
{
    m_options.ClearCallback ();
}

void
Watchpoint::SetDeclInfo (const std::string &str)
{
    m_decl_str = str;
    return;
}

std::string
Watchpoint::GetWatchSpec()
{
    return m_watch_spec_str;
}

void
Watchpoint::SetWatchSpec (const std::string &str)
{
    m_watch_spec_str = str;
    return;
}

// Strip at most one character from the end of the string.
static inline std::string
RStripOnce(const std::string &str, const char c)
{
    std::string res = str;
    size_t len = res.length();
    if (len && res.at(len - 1) == '\n')
        res.resize(len - 1);
    return res;
}

std::string
Watchpoint::GetOldSnapshot() const
{
    return m_snapshot_old_str;
}

void
Watchpoint::SetOldSnapshot (const std::string &str)
{
    m_snapshot_old_str = RStripOnce(str, '\n');
}

std::string
Watchpoint::GetNewSnapshot() const
{
    return m_snapshot_new_str;
}

void
Watchpoint::SetNewSnapshot (const std::string &str)
{
    m_snapshot_old_str = m_snapshot_new_str;
    m_snapshot_new_str = RStripOnce(str, '\n');
}

uint64_t
Watchpoint::GetOldSnapshotVal() const
{
    return m_snapshot_old_val;
}

void
Watchpoint::SetOldSnapshotVal (uint64_t val)
{
    m_snapshot_old_val = val;
    return;
}

uint64_t
Watchpoint::GetNewSnapshotVal() const
{
    return m_snapshot_new_val;
}

void
Watchpoint::SetNewSnapshotVal (uint64_t val)
{
    m_snapshot_old_val = m_snapshot_new_val;
    m_snapshot_new_val = val;
    return;
}

void
{'fraction_non_alphanumeric': 0.14660862238449657, 'fraction_numerical': 0.005617188597107148, 'mean_word_length': 3.5133079847908744, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2469121', 'n_tokens_mistral': 2446, 'n_tokens_neox': 2463, 'n_words': 544}