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/SBDefines.h"
|
|
|
|
#include "lldb/API/SBAddress.h"
|
|
|
|
#include "lldb/API/SBDebugger.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"
|
|
|
|
|
|
|
|
#include "lldb/lldb-types.h"
|
|
|
|
#include "lldb/lldb-defines.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/Log.h"
|
|
|
|
#include "lldb/Core/Stream.h"
|
|
|
|
#include "lldb/Core/StreamFile.h"
|
|
|
|
#include "lldb/Target/Target.h"
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
|
2011-10-14 02:08:26 +08:00
|
|
|
SBWatchpoint::SBWatchpoint () :
|
2011-09-27 06:40:50 +08:00
|
|
|
m_opaque_sp ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:42:25 +08:00
|
|
|
SBWatchpoint::SBWatchpoint (const lldb::WatchpointSP &wp_sp) :
|
|
|
|
m_opaque_sp (wp_sp)
|
2011-09-27 06:40:50 +08:00
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2011-09-27 06:40:50 +08:00
|
|
|
|
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
SBStream sstr;
|
|
|
|
GetDescription (sstr, lldb::eDescriptionLevelBrief);
|
2011-10-14 08:42:25 +08:00
|
|
|
log->Printf ("SBWatchpoint::SBWatchpoint (const lldb::WatchpointSP &wp_sp"
|
2014-04-04 12:06:10 +08:00
|
|
|
"=%p) => this.sp = %p (%s)",
|
|
|
|
static_cast<void*>(wp_sp.get()),
|
|
|
|
static_cast<void*>(m_opaque_sp.get()), sstr.GetData());
|
2011-09-27 06:40:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-14 02:08:26 +08:00
|
|
|
SBWatchpoint::SBWatchpoint(const SBWatchpoint &rhs) :
|
2011-09-27 06:40:50 +08:00
|
|
|
m_opaque_sp (rhs.m_opaque_sp)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-10-14 02:08:26 +08:00
|
|
|
const SBWatchpoint &
|
|
|
|
SBWatchpoint::operator = (const SBWatchpoint &rhs)
|
2011-09-27 06:40:50 +08:00
|
|
|
{
|
|
|
|
if (this != &rhs)
|
|
|
|
m_opaque_sp = rhs.m_opaque_sp;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-14 02:08:26 +08:00
|
|
|
SBWatchpoint::~SBWatchpoint ()
|
2011-09-27 06:40:50 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-09-27 09:19:20 +08:00
|
|
|
watch_id_t
|
2011-10-14 02:08:26 +08:00
|
|
|
SBWatchpoint::GetID ()
|
2011-09-27 09:19:20 +08:00
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2011-09-27 09:19:20 +08:00
|
|
|
|
|
|
|
watch_id_t watch_id = LLDB_INVALID_WATCH_ID;
|
2012-02-04 10:27:34 +08:00
|
|
|
lldb::WatchpointSP watchpoint_sp(GetSP());
|
|
|
|
if (watchpoint_sp)
|
|
|
|
watch_id = watchpoint_sp->GetID();
|
2011-09-27 09:19:20 +08:00
|
|
|
|
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
if (watch_id == LLDB_INVALID_WATCH_ID)
|
2014-04-04 12:06:10 +08:00
|
|
|
log->Printf ("SBWatchpoint(%p)::GetID () => LLDB_INVALID_WATCH_ID",
|
|
|
|
static_cast<void*>(watchpoint_sp.get()));
|
2011-09-27 09:19:20 +08:00
|
|
|
else
|
2014-04-04 12:06:10 +08:00
|
|
|
log->Printf ("SBWatchpoint(%p)::GetID () => %u",
|
|
|
|
static_cast<void*>(watchpoint_sp.get()), watch_id);
|
2011-09-27 09:19:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return watch_id;
|
|
|
|
}
|
|
|
|
|
2011-09-27 06:40:50 +08:00
|
|
|
bool
|
2011-10-14 02:08:26 +08:00
|
|
|
SBWatchpoint::IsValid() const
|
2011-09-27 06:40:50 +08:00
|
|
|
{
|
2012-08-11 08:35:26 +08:00
|
|
|
return (bool) m_opaque_sp;
|
2011-09-27 06:40:50 +08:00
|
|
|
}
|
|
|
|
|
2012-06-07 02:46:25 +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;
|
|
|
|
}
|
|
|
|
|
2011-09-27 09:19:20 +08:00
|
|
|
int32_t
|
2011-10-14 02:08:26 +08:00
|
|
|
SBWatchpoint::GetHardwareIndex ()
|
2011-09-27 09:19:20 +08:00
|
|
|
{
|
|
|
|
int32_t hw_index = -1;
|
|
|
|
|
2012-02-04 10:27:34 +08:00
|
|
|
lldb::WatchpointSP watchpoint_sp(GetSP());
|
|
|
|
if (watchpoint_sp)
|
2011-09-27 09:19:20 +08:00
|
|
|
{
|
2012-02-04 10:27:34 +08:00
|
|
|
Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
|
|
|
|
hw_index = watchpoint_sp->GetHardwareIndex();
|
2011-09-27 09:19:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return hw_index;
|
|
|
|
}
|
|
|
|
|
2011-09-27 06:40:50 +08:00
|
|
|
addr_t
|
2011-10-14 02:08:26 +08:00
|
|
|
SBWatchpoint::GetWatchAddress ()
|
2011-09-27 06:40:50 +08:00
|
|
|
{
|
|
|
|
addr_t ret_addr = LLDB_INVALID_ADDRESS;
|
|
|
|
|
2012-02-04 10:27:34 +08:00
|
|
|
lldb::WatchpointSP watchpoint_sp(GetSP());
|
|
|
|
if (watchpoint_sp)
|
2011-09-27 06:40:50 +08:00
|
|
|
{
|
2012-02-04 10:27:34 +08:00
|
|
|
Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
|
|
|
|
ret_addr = watchpoint_sp->GetLoadAddress();
|
2011-09-27 06:40:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret_addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
2011-10-14 02:08:26 +08:00
|
|
|
SBWatchpoint::GetWatchSize ()
|
2011-09-27 06:40:50 +08:00
|
|
|
{
|
|
|
|
size_t watch_size = 0;
|
|
|
|
|
2012-02-04 10:27:34 +08:00
|
|
|
lldb::WatchpointSP watchpoint_sp(GetSP());
|
|
|
|
if (watchpoint_sp)
|
2011-09-27 06:40:50 +08:00
|
|
|
{
|
2012-02-04 10:27:34 +08:00
|
|
|
Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
|
|
|
|
watch_size = watchpoint_sp->GetByteSize();
|
2011-09-27 06:40:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return watch_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-10-14 02:08:26 +08:00
|
|
|
SBWatchpoint::SetEnabled (bool enabled)
|
2011-09-27 06:40:50 +08:00
|
|
|
{
|
2012-02-04 10:27:34 +08:00
|
|
|
lldb::WatchpointSP watchpoint_sp(GetSP());
|
|
|
|
if (watchpoint_sp)
|
2011-09-27 06:40:50 +08:00
|
|
|
{
|
2012-02-04 10:27:34 +08:00
|
|
|
Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
|
|
|
|
watchpoint_sp->GetTarget().DisableWatchpointByID(watchpoint_sp->GetID());
|
2011-09-27 06:40:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-10-14 02:08:26 +08:00
|
|
|
SBWatchpoint::IsEnabled ()
|
2011-09-27 06:40:50 +08:00
|
|
|
{
|
2012-02-04 10:27:34 +08:00
|
|
|
lldb::WatchpointSP watchpoint_sp(GetSP());
|
|
|
|
if (watchpoint_sp)
|
2011-09-27 06:40:50 +08:00
|
|
|
{
|
2012-02-04 10:27:34 +08:00
|
|
|
Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
|
|
|
|
return watchpoint_sp->IsEnabled();
|
2011-09-27 06:40:50 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-09-27 09:19:20 +08:00
|
|
|
uint32_t
|
2011-10-14 02:08:26 +08:00
|
|
|
SBWatchpoint::GetHitCount ()
|
2011-09-27 09:19:20 +08:00
|
|
|
{
|
|
|
|
uint32_t count = 0;
|
2012-02-04 10:27:34 +08:00
|
|
|
lldb::WatchpointSP watchpoint_sp(GetSP());
|
|
|
|
if (watchpoint_sp)
|
2011-09-27 09:19:20 +08:00
|
|
|
{
|
2012-02-04 10:27:34 +08:00
|
|
|
Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
|
|
|
|
count = watchpoint_sp->GetHitCount();
|
2011-09-27 09:19:20 +08:00
|
|
|
}
|
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2011-09-27 09:19:20 +08:00
|
|
|
if (log)
|
2014-04-04 12:06:10 +08:00
|
|
|
log->Printf ("SBWatchpoint(%p)::GetHitCount () => %u",
|
|
|
|
static_cast<void*>(watchpoint_sp.get()), count);
|
2011-09-27 09:19:20 +08:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2011-09-27 06:40:50 +08:00
|
|
|
uint32_t
|
2011-10-14 02:08:26 +08:00
|
|
|
SBWatchpoint::GetIgnoreCount ()
|
2011-09-27 06:40:50 +08:00
|
|
|
{
|
2012-02-04 10:27:34 +08:00
|
|
|
lldb::WatchpointSP watchpoint_sp(GetSP());
|
|
|
|
if (watchpoint_sp)
|
2011-09-27 06:40:50 +08:00
|
|
|
{
|
2012-02-04 10:27:34 +08:00
|
|
|
Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
|
|
|
|
return watchpoint_sp->GetIgnoreCount();
|
2011-09-27 06:40:50 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-10-14 02:08:26 +08:00
|
|
|
SBWatchpoint::SetIgnoreCount (uint32_t n)
|
2011-09-27 06:40:50 +08:00
|
|
|
{
|
2012-02-04 10:27:34 +08:00
|
|
|
lldb::WatchpointSP watchpoint_sp(GetSP());
|
|
|
|
if (watchpoint_sp)
|
2011-09-27 06:40:50 +08:00
|
|
|
{
|
2012-02-04 10:27:34 +08:00
|
|
|
Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
|
|
|
|
watchpoint_sp->SetIgnoreCount (n);
|
2011-09-27 06:40:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-18 02:58:00 +08:00
|
|
|
const char *
|
|
|
|
SBWatchpoint::GetCondition ()
|
|
|
|
{
|
2012-02-04 10:27:34 +08:00
|
|
|
lldb::WatchpointSP watchpoint_sp(GetSP());
|
|
|
|
if (watchpoint_sp)
|
2011-10-18 02:58:00 +08:00
|
|
|
{
|
2012-02-04 10:27:34 +08:00
|
|
|
Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
|
|
|
|
return watchpoint_sp->GetConditionText ();
|
2011-10-18 02:58:00 +08:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SBWatchpoint::SetCondition (const char *condition)
|
|
|
|
{
|
2012-02-04 10:27:34 +08:00
|
|
|
lldb::WatchpointSP watchpoint_sp(GetSP());
|
|
|
|
if (watchpoint_sp)
|
2011-10-18 02:58:00 +08:00
|
|
|
{
|
2012-02-04 10:27:34 +08:00
|
|
|
Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
|
|
|
|
watchpoint_sp->SetCondition (condition);
|
2011-10-18 02:58:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-27 06:40:50 +08:00
|
|
|
bool
|
2011-10-14 02:08:26 +08:00
|
|
|
SBWatchpoint::GetDescription (SBStream &description, DescriptionLevel level)
|
2011-09-27 06:40:50 +08:00
|
|
|
{
|
2011-11-13 14:57:31 +08:00
|
|
|
Stream &strm = description.ref();
|
|
|
|
|
2012-02-04 10:27:34 +08:00
|
|
|
lldb::WatchpointSP watchpoint_sp(GetSP());
|
|
|
|
if (watchpoint_sp)
|
2011-09-27 06:40:50 +08:00
|
|
|
{
|
2012-02-04 10:27:34 +08:00
|
|
|
Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
|
|
|
|
watchpoint_sp->GetDescription (&strm, level);
|
2011-11-13 14:57:31 +08:00
|
|
|
strm.EOL();
|
2011-09-27 06:40:50 +08:00
|
|
|
}
|
|
|
|
else
|
2011-11-13 14:57:31 +08:00
|
|
|
strm.PutCString ("No value");
|
2011-09-27 06:40:50 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-02-04 10:27:34 +08:00
|
|
|
void
|
|
|
|
SBWatchpoint::Clear ()
|
2011-09-27 06:40:50 +08:00
|
|
|
{
|
2012-02-04 10:27:34 +08:00
|
|
|
m_opaque_sp.reset();
|
2011-09-27 06:40:50 +08:00
|
|
|
}
|
|
|
|
|
2012-02-04 10:27:34 +08:00
|
|
|
lldb::WatchpointSP
|
|
|
|
SBWatchpoint::GetSP () const
|
2011-09-27 06:40:50 +08:00
|
|
|
{
|
2012-02-04 10:27:34 +08:00
|
|
|
return m_opaque_sp;
|
2011-09-27 06:40:50 +08:00
|
|
|
}
|
|
|
|
|
2012-02-04 10:27:34 +08:00
|
|
|
void
|
|
|
|
SBWatchpoint::SetSP (const lldb::WatchpointSP &sp)
|
2011-09-27 06:40:50 +08:00
|
|
|
{
|
2012-02-04 10:27:34 +08:00
|
|
|
m_opaque_sp = sp;
|
2011-09-27 06:40:50 +08:00
|
|
|
}
|
2012-12-18 10:03:49 +08:00
|
|
|
|
|
|
|
bool
|
|
|
|
SBWatchpoint::EventIsWatchpointEvent (const lldb::SBEvent &event)
|
|
|
|
{
|
|
|
|
return Watchpoint::WatchpointEventData::GetEventDataFromEvent(event.get()) != NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
WatchpointEventType
|
|
|
|
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())
|
|
|
|
sb_watchpoint.m_opaque_sp = Watchpoint::WatchpointEventData::GetWatchpointFromEvent (event.GetSP());
|
|
|
|
return sb_watchpoint;
|
|
|
|
}
|