2011-10-14 08:42:25 +08:00
|
|
|
//===-- Watchpoint.cpp ------------------------------------------*- C++ -*-===//
|
2010-06-09 00:52:24 +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 08:42:25 +08:00
|
|
|
#include "lldb/Breakpoint/Watchpoint.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
// C Includes
|
|
|
|
// C++ Includes
|
|
|
|
// Other libraries and framework includes
|
|
|
|
// Project includes
|
2011-10-18 02:58:00 +08:00
|
|
|
#include "lldb/Breakpoint/StoppointCallbackContext.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/Stream.h"
|
2011-10-18 02:58:00 +08:00
|
|
|
#include "lldb/Target/Process.h"
|
|
|
|
#include "lldb/Target/Target.h"
|
|
|
|
#include "lldb/Target/ThreadSpec.h"
|
|
|
|
#include "lldb/Target/ThreadPlanTestCondition.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2011-10-14 08:42:25 +08:00
|
|
|
Watchpoint::Watchpoint (lldb::addr_t addr, size_t size, bool hardware) :
|
2011-09-06 10:52:28 +08:00
|
|
|
StoppointLocation (GetNextID(), addr, size, hardware),
|
2011-09-27 06:40:50 +08:00
|
|
|
m_target(NULL),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_enabled(0),
|
2011-09-23 02:04:58 +08:00
|
|
|
m_is_hardware(hardware),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_watch_read(0),
|
|
|
|
m_watch_write(0),
|
|
|
|
m_watch_was_read(0),
|
|
|
|
m_watch_was_written(0),
|
|
|
|
m_ignore_count(0),
|
|
|
|
m_callback(NULL),
|
2011-10-15 03:15:48 +08:00
|
|
|
m_callback_baton(NULL),
|
|
|
|
m_decl_str(),
|
|
|
|
m_error()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:42:25 +08:00
|
|
|
Watchpoint::~Watchpoint()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
break_id_t
|
2011-10-14 08:42:25 +08:00
|
|
|
Watchpoint::GetNextID()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
static break_id_t g_next_ID = 0;
|
|
|
|
return ++g_next_ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-10-14 08:42:25 +08:00
|
|
|
Watchpoint::SetCallback (WatchpointHitCallback callback, void *callback_baton)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
m_callback = callback;
|
|
|
|
m_callback_baton = callback_baton;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-17 05:41:42 +08:00
|
|
|
void
|
2011-10-14 08:42:25 +08:00
|
|
|
Watchpoint::SetDeclInfo (std::string &str)
|
2011-09-17 05:41:42 +08:00
|
|
|
{
|
|
|
|
m_decl_str = str;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-24 07:03:59 +08:00
|
|
|
// Override default impl of StoppointLocation::IsHardware() since m_is_hardware
|
|
|
|
// member field is more accurate.
|
2011-09-23 02:04:58 +08:00
|
|
|
bool
|
2011-10-14 08:42:25 +08:00
|
|
|
Watchpoint::IsHardware () const
|
2011-09-23 02:04:58 +08:00
|
|
|
{
|
|
|
|
return m_is_hardware;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// RETURNS - true if we should stop at this breakpoint, false if we
|
|
|
|
// should continue.
|
|
|
|
|
|
|
|
bool
|
2011-10-14 08:42:25 +08:00
|
|
|
Watchpoint::ShouldStop (StoppointCallbackContext *context)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-01-24 07:03:59 +08:00
|
|
|
IncrementHitCount();
|
2011-09-23 02:04:58 +08:00
|
|
|
|
|
|
|
if (!IsEnabled())
|
|
|
|
return false;
|
|
|
|
|
2012-01-24 07:03:59 +08:00
|
|
|
if (GetHitCount() <= GetIgnoreCount())
|
2011-09-23 02:04:58 +08:00
|
|
|
return false;
|
|
|
|
|
2011-10-18 02:58:00 +08:00
|
|
|
return true;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2011-09-13 07:38:44 +08:00
|
|
|
void
|
2011-10-14 08:42:25 +08:00
|
|
|
Watchpoint::GetDescription (Stream *s, lldb::DescriptionLevel level)
|
2011-09-13 07:38:44 +08:00
|
|
|
{
|
2011-09-17 05:41:42 +08:00
|
|
|
DumpWithLevel(s, level);
|
2011-09-13 07:38:44 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void
|
2011-10-14 08:42:25 +08:00
|
|
|
Watchpoint::Dump(Stream *s) const
|
2011-09-17 05:41:42 +08:00
|
|
|
{
|
|
|
|
DumpWithLevel(s, lldb::eDescriptionLevelBrief);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-10-14 08:42:25 +08:00
|
|
|
Watchpoint::DumpWithLevel(Stream *s, lldb::DescriptionLevel description_level) const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
if (s == NULL)
|
|
|
|
return;
|
|
|
|
|
2011-09-17 05:41:42 +08:00
|
|
|
assert(description_level >= lldb::eDescriptionLevelBrief &&
|
|
|
|
description_level <= lldb::eDescriptionLevelVerbose);
|
|
|
|
|
2011-12-03 08:46:21 +08:00
|
|
|
s->Printf("Watchpoint %u: addr = 0x%8.8llx size = %u state = %s type = %s%s",
|
2011-09-17 05:41:42 +08:00
|
|
|
GetID(),
|
2012-01-24 08:11:02 +08:00
|
|
|
GetLoadAddress(),
|
2011-09-17 05:41:42 +08:00
|
|
|
m_byte_size,
|
|
|
|
m_enabled ? "enabled" : "disabled",
|
|
|
|
m_watch_read ? "r" : "",
|
|
|
|
m_watch_write ? "w" : "");
|
|
|
|
|
2011-10-18 02:58:00 +08:00
|
|
|
if (description_level >= lldb::eDescriptionLevelFull) {
|
2012-01-31 05:46:17 +08:00
|
|
|
if (!m_decl_str.empty())
|
2011-10-18 02:58:00 +08:00
|
|
|
s->Printf("\n declare @ '%s'", m_decl_str.c_str());
|
|
|
|
if (GetConditionText())
|
|
|
|
s->Printf("\n condition = '%s'", GetConditionText());
|
|
|
|
}
|
2011-09-17 05:41:42 +08:00
|
|
|
|
|
|
|
if (description_level >= lldb::eDescriptionLevelVerbose)
|
2012-02-24 06:32:13 +08:00
|
|
|
{
|
2011-10-07 04:27:05 +08:00
|
|
|
if (m_callback)
|
2012-02-24 06:32:13 +08:00
|
|
|
{
|
2011-10-07 04:27:05 +08:00
|
|
|
s->Printf("\n hw_index = %i hit_count = %-4u ignore_count = %-4u callback = %8p baton = %8p",
|
|
|
|
GetHardwareIndex(),
|
|
|
|
GetHitCount(),
|
|
|
|
GetIgnoreCount(),
|
|
|
|
m_callback,
|
|
|
|
m_callback_baton);
|
2012-02-24 06:32:13 +08:00
|
|
|
}
|
2011-10-07 04:27:05 +08:00
|
|
|
else
|
2012-02-24 06:32:13 +08:00
|
|
|
{
|
2011-10-07 04:27:05 +08:00
|
|
|
s->Printf("\n hw_index = %i hit_count = %-4u ignore_count = %-4u",
|
|
|
|
GetHardwareIndex(),
|
|
|
|
GetHitCount(),
|
|
|
|
GetIgnoreCount());
|
2012-02-24 06:32:13 +08:00
|
|
|
}
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-10-14 08:42:25 +08:00
|
|
|
Watchpoint::IsEnabled() const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
return m_enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-10-14 08:42:25 +08:00
|
|
|
Watchpoint::SetEnabled(bool enabled)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
if (!enabled)
|
|
|
|
SetHardwareIndex(LLDB_INVALID_INDEX32);
|
|
|
|
m_enabled = enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-10-14 08:42:25 +08:00
|
|
|
Watchpoint::SetWatchpointType (uint32_t type)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
m_watch_read = (type & LLDB_WATCH_TYPE_READ) != 0;
|
|
|
|
m_watch_write = (type & LLDB_WATCH_TYPE_WRITE) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-10-14 08:42:25 +08:00
|
|
|
Watchpoint::WatchpointRead () const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
return m_watch_read != 0;
|
|
|
|
}
|
|
|
|
bool
|
2011-10-14 08:42:25 +08:00
|
|
|
Watchpoint::WatchpointWrite () const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
return m_watch_write != 0;
|
|
|
|
}
|
2010-07-10 04:39:50 +08:00
|
|
|
uint32_t
|
2011-10-14 08:42:25 +08:00
|
|
|
Watchpoint::GetIgnoreCount () const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
return m_ignore_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-10-14 08:42:25 +08:00
|
|
|
Watchpoint::SetIgnoreCount (uint32_t n)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
m_ignore_count = n;
|
|
|
|
}
|
2011-10-18 02:58:00 +08:00
|
|
|
|
|
|
|
bool
|
|
|
|
Watchpoint::InvokeCallback (StoppointCallbackContext *context)
|
|
|
|
{
|
|
|
|
if (m_callback && context->is_synchronous)
|
|
|
|
{
|
|
|
|
uint32_t access = 0;
|
|
|
|
if (m_watch_was_read)
|
|
|
|
access |= LLDB_WATCH_TYPE_READ;
|
|
|
|
if (m_watch_was_written)
|
|
|
|
access |= LLDB_WATCH_TYPE_WRITE;
|
|
|
|
return m_callback(m_callback_baton, context, GetID(), access);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Watchpoint::SetCondition (const char *condition)
|
|
|
|
{
|
|
|
|
if (condition == NULL || condition[0] == '\0')
|
|
|
|
{
|
|
|
|
if (m_condition_ap.get())
|
|
|
|
m_condition_ap.reset();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Pass NULL for expr_prefix (no translation-unit level definitions).
|
2011-12-22 06:22:58 +08:00
|
|
|
m_condition_ap.reset(new ClangUserExpression (condition, NULL, lldb::eLanguageTypeUnknown, ClangUserExpression::eResultTypeAny));
|
2011-10-18 02:58:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
Watchpoint::GetConditionText () const
|
|
|
|
{
|
|
|
|
if (m_condition_ap.get())
|
|
|
|
return m_condition_ap->GetUserText();
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|