2011-10-14 02:08:26 +08:00
|
|
|
//===-- SBWatchpoint.cpp --------------------------------*- C++ -*-===//
|
2011-09-27 06:40:50 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-10-14 02:08:26 +08:00
|
|
|
#include "lldb/API/SBWatchpoint.h"
|
2011-09-27 06:40:50 +08:00
|
|
|
#include "lldb/API/SBAddress.h"
|
|
|
|
#include "lldb/API/SBDebugger.h"
|
2016-09-07 04:57:50 +08:00
|
|
|
#include "lldb/API/SBDefines.h"
|
2012-12-18 10:03:49 +08:00
|
|
|
#include "lldb/API/SBEvent.h"
|
2011-09-27 06:40:50 +08:00
|
|
|
#include "lldb/API/SBStream.h"
|
|
|
|
|
2011-10-14 08:42:25 +08:00
|
|
|
#include "lldb/Breakpoint/Watchpoint.h"
|
|
|
|
#include "lldb/Breakpoint/WatchpointList.h"
|
2011-09-27 06:40:50 +08:00
|
|
|
#include "lldb/Core/StreamFile.h"
|
2016-11-02 04:37:02 +08:00
|
|
|
#include "lldb/Target/Process.h"
|
2011-09-27 06:40:50 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2017-03-04 04:56:28 +08:00
|
|
|
#include "lldb/Utility/Log.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/Stream.h"
|
2016-09-07 04:57:50 +08:00
|
|
|
#include "lldb/lldb-defines.h"
|
|
|
|
#include "lldb/lldb-types.h"
|
2011-09-27 06:40:50 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2017-02-28 20:32:45 +08:00
|
|
|
SBWatchpoint::SBWatchpoint() {}
|
2011-09-27 06:40:50 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBWatchpoint::SBWatchpoint(const lldb::WatchpointSP &wp_sp)
|
2017-02-28 20:32:45 +08:00
|
|
|
: m_opaque_wp(wp_sp) {
|
2016-09-07 04:57:50 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
|
2011-09-27 06:40:50 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (log) {
|
|
|
|
SBStream sstr;
|
|
|
|
GetDescription(sstr, lldb::eDescriptionLevelBrief);
|
2017-02-28 20:32:45 +08:00
|
|
|
LLDB_LOG(log, "watchpoint = {0} ({1})", wp_sp.get(), sstr.GetData());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-09-27 06:40:50 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBWatchpoint::SBWatchpoint(const SBWatchpoint &rhs)
|
2017-02-28 20:32:45 +08:00
|
|
|
: m_opaque_wp(rhs.m_opaque_wp) {}
|
2011-09-27 06:40:50 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const SBWatchpoint &SBWatchpoint::operator=(const SBWatchpoint &rhs) {
|
2017-02-28 20:32:45 +08:00
|
|
|
m_opaque_wp = rhs.m_opaque_wp;
|
2016-09-07 04:57:50 +08:00
|
|
|
return *this;
|
2011-09-27 06:40:50 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBWatchpoint::~SBWatchpoint() {}
|
2011-09-27 06:40:50 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
watch_id_t SBWatchpoint::GetID() {
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
|
2011-09-27 06:40:50 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
watch_id_t watch_id = LLDB_INVALID_WATCH_ID;
|
|
|
|
lldb::WatchpointSP watchpoint_sp(GetSP());
|
|
|
|
if (watchpoint_sp)
|
|
|
|
watch_id = watchpoint_sp->GetID();
|
|
|
|
|
|
|
|
if (log) {
|
|
|
|
if (watch_id == LLDB_INVALID_WATCH_ID)
|
|
|
|
log->Printf("SBWatchpoint(%p)::GetID () => LLDB_INVALID_WATCH_ID",
|
|
|
|
static_cast<void *>(watchpoint_sp.get()));
|
|
|
|
else
|
|
|
|
log->Printf("SBWatchpoint(%p)::GetID () => %u",
|
|
|
|
static_cast<void *>(watchpoint_sp.get()), watch_id);
|
|
|
|
}
|
2011-09-27 09:19:20 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return watch_id;
|
2011-09-27 06:40:50 +08:00
|
|
|
}
|
|
|
|
|
2017-02-28 20:32:45 +08:00
|
|
|
bool SBWatchpoint::IsValid() const { return bool(m_opaque_wp.lock()); }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
SBError SBWatchpoint::GetError() {
|
|
|
|
SBError sb_error;
|
|
|
|
lldb::WatchpointSP watchpoint_sp(GetSP());
|
|
|
|
if (watchpoint_sp) {
|
|
|
|
sb_error.SetError(watchpoint_sp->GetError());
|
|
|
|
}
|
|
|
|
return sb_error;
|
2012-06-07 02:46:25 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
int32_t SBWatchpoint::GetHardwareIndex() {
|
|
|
|
int32_t hw_index = -1;
|
2011-09-27 09:19:20 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb::WatchpointSP watchpoint_sp(GetSP());
|
|
|
|
if (watchpoint_sp) {
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(
|
|
|
|
watchpoint_sp->GetTarget().GetAPIMutex());
|
|
|
|
hw_index = watchpoint_sp->GetHardwareIndex();
|
|
|
|
}
|
2011-09-27 09:19:20 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return hw_index;
|
2011-09-27 09:19:20 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
addr_t SBWatchpoint::GetWatchAddress() {
|
|
|
|
addr_t ret_addr = LLDB_INVALID_ADDRESS;
|
2011-09-27 06:40:50 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb::WatchpointSP watchpoint_sp(GetSP());
|
|
|
|
if (watchpoint_sp) {
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(
|
|
|
|
watchpoint_sp->GetTarget().GetAPIMutex());
|
|
|
|
ret_addr = watchpoint_sp->GetLoadAddress();
|
|
|
|
}
|
2011-09-27 06:40:50 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return ret_addr;
|
2011-09-27 06:40:50 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
size_t SBWatchpoint::GetWatchSize() {
|
|
|
|
size_t watch_size = 0;
|
2011-09-27 06:40:50 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb::WatchpointSP watchpoint_sp(GetSP());
|
|
|
|
if (watchpoint_sp) {
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(
|
|
|
|
watchpoint_sp->GetTarget().GetAPIMutex());
|
|
|
|
watch_size = watchpoint_sp->GetByteSize();
|
|
|
|
}
|
2011-09-27 06:40:50 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return watch_size;
|
2011-09-27 06:40:50 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBWatchpoint::SetEnabled(bool enabled) {
|
|
|
|
lldb::WatchpointSP watchpoint_sp(GetSP());
|
|
|
|
if (watchpoint_sp) {
|
2016-11-02 04:37:02 +08:00
|
|
|
Target &target = watchpoint_sp->GetTarget();
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(target.GetAPIMutex());
|
|
|
|
ProcessSP process_sp = target.GetProcessSP();
|
2016-11-02 09:06:42 +08:00
|
|
|
const bool notify = true;
|
2016-11-02 04:37:02 +08:00
|
|
|
if (process_sp) {
|
|
|
|
if (enabled)
|
2016-11-02 09:06:42 +08:00
|
|
|
process_sp->EnableWatchpoint(watchpoint_sp.get(), notify);
|
2016-11-02 04:37:02 +08:00
|
|
|
else
|
2016-11-02 09:06:42 +08:00
|
|
|
process_sp->DisableWatchpoint(watchpoint_sp.get(), notify);
|
2016-11-02 04:37:02 +08:00
|
|
|
} else {
|
2016-11-02 09:06:42 +08:00
|
|
|
watchpoint_sp->SetEnabled(enabled, notify);
|
2016-11-02 04:37:02 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-09-27 06:40:50 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool SBWatchpoint::IsEnabled() {
|
|
|
|
lldb::WatchpointSP watchpoint_sp(GetSP());
|
|
|
|
if (watchpoint_sp) {
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(
|
|
|
|
watchpoint_sp->GetTarget().GetAPIMutex());
|
|
|
|
return watchpoint_sp->IsEnabled();
|
|
|
|
} else
|
|
|
|
return false;
|
2011-09-27 06:40:50 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
uint32_t SBWatchpoint::GetHitCount() {
|
|
|
|
uint32_t count = 0;
|
|
|
|
lldb::WatchpointSP watchpoint_sp(GetSP());
|
|
|
|
if (watchpoint_sp) {
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(
|
|
|
|
watchpoint_sp->GetTarget().GetAPIMutex());
|
|
|
|
count = watchpoint_sp->GetHitCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
|
|
|
|
if (log)
|
|
|
|
log->Printf("SBWatchpoint(%p)::GetHitCount () => %u",
|
|
|
|
static_cast<void *>(watchpoint_sp.get()), count);
|
|
|
|
|
|
|
|
return count;
|
2011-09-27 09:19:20 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
uint32_t SBWatchpoint::GetIgnoreCount() {
|
|
|
|
lldb::WatchpointSP watchpoint_sp(GetSP());
|
|
|
|
if (watchpoint_sp) {
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(
|
|
|
|
watchpoint_sp->GetTarget().GetAPIMutex());
|
|
|
|
return watchpoint_sp->GetIgnoreCount();
|
|
|
|
} else
|
|
|
|
return 0;
|
2011-09-27 06:40:50 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBWatchpoint::SetIgnoreCount(uint32_t n) {
|
|
|
|
lldb::WatchpointSP watchpoint_sp(GetSP());
|
|
|
|
if (watchpoint_sp) {
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(
|
|
|
|
watchpoint_sp->GetTarget().GetAPIMutex());
|
|
|
|
watchpoint_sp->SetIgnoreCount(n);
|
|
|
|
}
|
2011-09-27 06:40:50 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const char *SBWatchpoint::GetCondition() {
|
|
|
|
lldb::WatchpointSP watchpoint_sp(GetSP());
|
|
|
|
if (watchpoint_sp) {
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(
|
|
|
|
watchpoint_sp->GetTarget().GetAPIMutex());
|
|
|
|
return watchpoint_sp->GetConditionText();
|
|
|
|
}
|
|
|
|
return NULL;
|
2011-10-18 02:58:00 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBWatchpoint::SetCondition(const char *condition) {
|
|
|
|
lldb::WatchpointSP watchpoint_sp(GetSP());
|
|
|
|
if (watchpoint_sp) {
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(
|
|
|
|
watchpoint_sp->GetTarget().GetAPIMutex());
|
|
|
|
watchpoint_sp->SetCondition(condition);
|
|
|
|
}
|
2011-10-18 02:58:00 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool SBWatchpoint::GetDescription(SBStream &description,
|
|
|
|
DescriptionLevel level) {
|
|
|
|
Stream &strm = description.ref();
|
2011-09-27 06:40:50 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb::WatchpointSP watchpoint_sp(GetSP());
|
|
|
|
if (watchpoint_sp) {
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(
|
|
|
|
watchpoint_sp->GetTarget().GetAPIMutex());
|
|
|
|
watchpoint_sp->GetDescription(&strm, level);
|
|
|
|
strm.EOL();
|
|
|
|
} else
|
|
|
|
strm.PutCString("No value");
|
2011-09-27 06:40:50 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return true;
|
2011-09-27 06:40:50 +08:00
|
|
|
}
|
|
|
|
|
2017-02-28 20:32:45 +08:00
|
|
|
void SBWatchpoint::Clear() { m_opaque_wp.reset(); }
|
2011-09-27 06:40:50 +08:00
|
|
|
|
2017-02-28 20:32:45 +08:00
|
|
|
lldb::WatchpointSP SBWatchpoint::GetSP() const { return m_opaque_wp.lock(); }
|
2012-12-18 10:03:49 +08:00
|
|
|
|
2017-02-28 20:32:45 +08:00
|
|
|
void SBWatchpoint::SetSP(const lldb::WatchpointSP &sp) { m_opaque_wp = sp; }
|
2012-12-18 10:03:49 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool SBWatchpoint::EventIsWatchpointEvent(const lldb::SBEvent &event) {
|
|
|
|
return Watchpoint::WatchpointEventData::GetEventDataFromEvent(event.get()) !=
|
|
|
|
NULL;
|
2012-12-18 10:03:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
WatchpointEventType
|
2016-09-07 04:57:50 +08:00
|
|
|
SBWatchpoint::GetWatchpointEventTypeFromEvent(const SBEvent &event) {
|
|
|
|
if (event.IsValid())
|
|
|
|
return Watchpoint::WatchpointEventData::GetWatchpointEventTypeFromEvent(
|
|
|
|
event.GetSP());
|
|
|
|
return eWatchpointEventTypeInvalidType;
|
|
|
|
}
|
|
|
|
|
|
|
|
SBWatchpoint SBWatchpoint::GetWatchpointFromEvent(const lldb::SBEvent &event) {
|
|
|
|
SBWatchpoint sb_watchpoint;
|
|
|
|
if (event.IsValid())
|
2017-02-28 20:32:45 +08:00
|
|
|
sb_watchpoint =
|
2016-09-07 04:57:50 +08:00
|
|
|
Watchpoint::WatchpointEventData::GetWatchpointFromEvent(event.GetSP());
|
|
|
|
return sb_watchpoint;
|
2012-12-18 10:03:49 +08:00
|
|
|
}
|