2012-08-10 07:09:42 +08:00
|
|
|
//===-- WatchpointOptions.cpp -----------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2012-08-10 07:09:42 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-10-31 02:50:12 +08:00
|
|
|
#include "lldb/Breakpoint/WatchpointOptions.h"
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
#include "lldb/Breakpoint/StoppointCallbackContext.h"
|
2012-08-10 07:09:42 +08:00
|
|
|
#include "lldb/Core/Value.h"
|
|
|
|
#include "lldb/Target/Process.h"
|
|
|
|
#include "lldb/Target/Target.h"
|
|
|
|
#include "lldb/Target/ThreadSpec.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/Stream.h"
|
2017-03-22 02:25:04 +08:00
|
|
|
#include "lldb/Utility/StringList.h"
|
2012-08-10 07:09:42 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool WatchpointOptions::NullCallback(void *baton,
|
|
|
|
StoppointCallbackContext *context,
|
|
|
|
lldb::user_id_t watch_id) {
|
|
|
|
return true;
|
2012-08-10 07:09:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// WatchpointOptions constructor
|
2016-09-07 04:57:50 +08:00
|
|
|
WatchpointOptions::WatchpointOptions()
|
|
|
|
: m_callback(WatchpointOptions::NullCallback), m_callback_baton_sp(),
|
2019-02-13 14:25:41 +08:00
|
|
|
m_callback_is_synchronous(false), m_thread_spec_up() {}
|
2012-08-10 07:09:42 +08:00
|
|
|
|
|
|
|
// WatchpointOptions copy constructor
|
2016-09-07 04:57:50 +08:00
|
|
|
WatchpointOptions::WatchpointOptions(const WatchpointOptions &rhs)
|
|
|
|
: m_callback(rhs.m_callback), m_callback_baton_sp(rhs.m_callback_baton_sp),
|
|
|
|
m_callback_is_synchronous(rhs.m_callback_is_synchronous),
|
2019-02-13 14:25:41 +08:00
|
|
|
m_thread_spec_up() {
|
|
|
|
if (rhs.m_thread_spec_up != nullptr)
|
|
|
|
m_thread_spec_up.reset(new ThreadSpec(*rhs.m_thread_spec_up));
|
2012-08-10 07:09:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// WatchpointOptions assignment operator
|
2016-09-07 04:57:50 +08:00
|
|
|
const WatchpointOptions &WatchpointOptions::
|
|
|
|
operator=(const WatchpointOptions &rhs) {
|
|
|
|
m_callback = rhs.m_callback;
|
|
|
|
m_callback_baton_sp = rhs.m_callback_baton_sp;
|
|
|
|
m_callback_is_synchronous = rhs.m_callback_is_synchronous;
|
2019-02-13 14:25:41 +08:00
|
|
|
if (rhs.m_thread_spec_up != nullptr)
|
|
|
|
m_thread_spec_up.reset(new ThreadSpec(*rhs.m_thread_spec_up));
|
2016-09-07 04:57:50 +08:00
|
|
|
return *this;
|
2012-08-10 07:09:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
WatchpointOptions *
|
2016-09-07 04:57:50 +08:00
|
|
|
WatchpointOptions::CopyOptionsNoCallback(WatchpointOptions &orig) {
|
|
|
|
WatchpointHitCallback orig_callback = orig.m_callback;
|
|
|
|
lldb::BatonSP orig_callback_baton_sp = orig.m_callback_baton_sp;
|
|
|
|
bool orig_is_sync = orig.m_callback_is_synchronous;
|
|
|
|
|
|
|
|
orig.ClearCallback();
|
|
|
|
WatchpointOptions *ret_val = new WatchpointOptions(orig);
|
|
|
|
|
|
|
|
orig.SetCallback(orig_callback, orig_callback_baton_sp, orig_is_sync);
|
|
|
|
|
|
|
|
return ret_val;
|
2012-08-10 07:09:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Destructor
|
2015-10-31 02:50:12 +08:00
|
|
|
WatchpointOptions::~WatchpointOptions() = default;
|
2012-08-10 07:09:42 +08:00
|
|
|
|
|
|
|
// Callbacks
|
2016-09-07 04:57:50 +08:00
|
|
|
void WatchpointOptions::SetCallback(WatchpointHitCallback callback,
|
|
|
|
const BatonSP &callback_baton_sp,
|
|
|
|
bool callback_is_synchronous) {
|
|
|
|
m_callback_is_synchronous = callback_is_synchronous;
|
|
|
|
m_callback = callback;
|
|
|
|
m_callback_baton_sp = callback_baton_sp;
|
2012-08-10 07:09:42 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void WatchpointOptions::ClearCallback() {
|
|
|
|
m_callback = WatchpointOptions::NullCallback;
|
|
|
|
m_callback_is_synchronous = false;
|
|
|
|
m_callback_baton_sp.reset();
|
2012-08-10 07:09:42 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
Baton *WatchpointOptions::GetBaton() { return m_callback_baton_sp.get(); }
|
2012-08-10 07:09:42 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const Baton *WatchpointOptions::GetBaton() const {
|
|
|
|
return m_callback_baton_sp.get();
|
2012-08-10 07:09:42 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool WatchpointOptions::InvokeCallback(StoppointCallbackContext *context,
|
|
|
|
lldb::user_id_t watch_id) {
|
|
|
|
if (m_callback && context->is_synchronous == IsCallbackSynchronous()) {
|
2016-09-14 01:53:38 +08:00
|
|
|
return m_callback(m_callback_baton_sp ? m_callback_baton_sp->data()
|
2016-09-07 04:57:50 +08:00
|
|
|
: nullptr,
|
|
|
|
context, watch_id);
|
|
|
|
} else
|
|
|
|
return true;
|
2012-08-10 07:09:42 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool WatchpointOptions::HasCallback() {
|
|
|
|
return m_callback != WatchpointOptions::NullCallback;
|
2012-08-10 07:09:42 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const ThreadSpec *WatchpointOptions::GetThreadSpecNoCreate() const {
|
2019-02-13 14:25:41 +08:00
|
|
|
return m_thread_spec_up.get();
|
2012-08-10 07:09:42 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
ThreadSpec *WatchpointOptions::GetThreadSpec() {
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_thread_spec_up == nullptr)
|
|
|
|
m_thread_spec_up.reset(new ThreadSpec());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
return m_thread_spec_up.get();
|
2012-08-10 07:09:42 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void WatchpointOptions::SetThreadID(lldb::tid_t thread_id) {
|
|
|
|
GetThreadSpec()->SetTID(thread_id);
|
2012-08-10 07:09:42 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void WatchpointOptions::GetCallbackDescription(
|
|
|
|
Stream *s, lldb::DescriptionLevel level) const {
|
|
|
|
if (m_callback_baton_sp.get()) {
|
|
|
|
s->EOL();
|
|
|
|
m_callback_baton_sp->GetDescription(s, level);
|
|
|
|
}
|
2012-08-10 07:09:42 +08:00
|
|
|
}
|
2015-10-31 02:50:12 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void WatchpointOptions::GetDescription(Stream *s,
|
|
|
|
lldb::DescriptionLevel level) const {
|
|
|
|
// Figure out if there are any options not at their default value, and only
|
2018-05-01 00:49:04 +08:00
|
|
|
// print anything if there are:
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
if ((GetThreadSpecNoCreate() != nullptr &&
|
|
|
|
GetThreadSpecNoCreate()->HasSpecification())) {
|
|
|
|
if (level == lldb::eDescriptionLevelVerbose) {
|
|
|
|
s->EOL();
|
|
|
|
s->IndentMore();
|
|
|
|
s->Indent();
|
|
|
|
s->PutCString("Watchpoint Options:\n");
|
|
|
|
s->IndentMore();
|
|
|
|
s->Indent();
|
|
|
|
} else
|
|
|
|
s->PutCString(" Options: ");
|
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_thread_spec_up)
|
|
|
|
m_thread_spec_up->GetDescription(s, level);
|
2016-09-07 04:57:50 +08:00
|
|
|
else if (level == eDescriptionLevelBrief)
|
|
|
|
s->PutCString("thread spec: no ");
|
|
|
|
if (level == lldb::eDescriptionLevelFull) {
|
|
|
|
s->IndentLess();
|
|
|
|
s->IndentMore();
|
2012-08-10 07:09:42 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GetCallbackDescription(s, level);
|
2012-08-10 07:09:42 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void WatchpointOptions::CommandBaton::GetDescription(
|
|
|
|
Stream *s, lldb::DescriptionLevel level) const {
|
2016-09-14 01:53:38 +08:00
|
|
|
const CommandData *data = getItem();
|
2012-08-10 07:09:42 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (level == eDescriptionLevelBrief) {
|
|
|
|
s->Printf(", commands = %s",
|
|
|
|
(data && data->user_source.GetSize() > 0) ? "yes" : "no");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
s->IndentMore();
|
|
|
|
s->Indent("watchpoint commands:\n");
|
|
|
|
|
|
|
|
s->IndentMore();
|
|
|
|
if (data && data->user_source.GetSize() > 0) {
|
|
|
|
const size_t num_strings = data->user_source.GetSize();
|
|
|
|
for (size_t i = 0; i < num_strings; ++i) {
|
|
|
|
s->Indent(data->user_source.GetStringAtIndex(i));
|
|
|
|
s->EOL();
|
2012-08-10 07:09:42 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
|
|
|
s->PutCString("No commands.\n");
|
|
|
|
}
|
|
|
|
s->IndentLess();
|
|
|
|
s->IndentLess();
|
2012-08-10 07:09:42 +08:00
|
|
|
}
|