2010-06-09 00:52:24 +08:00
|
|
|
//===-- SBEvent.cpp ---------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-12-05 08:20:57 +08:00
|
|
|
#include "lldb/lldb-python.h"
|
|
|
|
|
2010-06-09 15:44:37 +08:00
|
|
|
#include "lldb/API/SBEvent.h"
|
|
|
|
#include "lldb/API/SBBroadcaster.h"
|
2010-09-20 13:20:02 +08:00
|
|
|
#include "lldb/API/SBStream.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
#include "lldb/Core/Event.h"
|
|
|
|
#include "lldb/Core/Stream.h"
|
|
|
|
#include "lldb/Core/StreamFile.h"
|
|
|
|
#include "lldb/Core/ConstString.h"
|
|
|
|
#include "lldb/Target/Process.h"
|
|
|
|
#include "lldb/Breakpoint/Breakpoint.h"
|
|
|
|
#include "lldb/Interpreter/CommandInterpreter.h"
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
|
|
|
|
SBEvent::SBEvent () :
|
|
|
|
m_event_sp (),
|
2010-11-06 07:17:00 +08:00
|
|
|
m_opaque_ptr (NULL)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SBEvent::SBEvent (uint32_t event_type, const char *cstr, uint32_t cstr_len) :
|
|
|
|
m_event_sp (new Event (event_type, new EventDataBytes (cstr, cstr_len))),
|
2010-11-06 07:17:00 +08:00
|
|
|
m_opaque_ptr (m_event_sp.get())
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SBEvent::SBEvent (EventSP &event_sp) :
|
|
|
|
m_event_sp (event_sp),
|
2010-11-06 07:17:00 +08:00
|
|
|
m_opaque_ptr (event_sp.get())
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-09-30 07:17:18 +08:00
|
|
|
SBEvent::SBEvent (Event *event_ptr) :
|
|
|
|
m_event_sp (),
|
|
|
|
m_opaque_ptr (event_ptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-11-06 07:17:00 +08:00
|
|
|
SBEvent::SBEvent (const SBEvent &rhs) :
|
|
|
|
m_event_sp (rhs.m_event_sp),
|
|
|
|
m_opaque_ptr (rhs.m_opaque_ptr)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const SBEvent &
|
|
|
|
SBEvent::operator = (const SBEvent &rhs)
|
|
|
|
{
|
|
|
|
if (this != &rhs)
|
|
|
|
{
|
|
|
|
m_event_sp = rhs.m_event_sp;
|
|
|
|
m_opaque_ptr = rhs.m_opaque_ptr;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
SBEvent::~SBEvent()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
SBEvent::GetDataFlavor ()
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
Event *lldb_event = get();
|
2010-06-09 00:52:24 +08:00
|
|
|
if (lldb_event)
|
2010-12-06 03:21:02 +08:00
|
|
|
{
|
|
|
|
EventData *event_data = lldb_event->GetData();
|
|
|
|
if (event_data)
|
|
|
|
return lldb_event->GetData()->GetFlavor().AsCString();
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
SBEvent::GetType () const
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
const Event *lldb_event = get();
|
2010-10-26 11:11:13 +08:00
|
|
|
uint32_t event_type = 0;
|
2010-06-09 00:52:24 +08:00
|
|
|
if (lldb_event)
|
2010-10-26 11:11:13 +08:00
|
|
|
event_type = lldb_event->GetType();
|
|
|
|
|
|
|
|
if (log)
|
2010-10-31 11:01:06 +08:00
|
|
|
{
|
|
|
|
StreamString sstr;
|
|
|
|
if (lldb_event && lldb_event->GetBroadcaster() && lldb_event->GetBroadcaster()->GetEventNames(sstr, event_type, true))
|
2014-04-04 12:06:10 +08:00
|
|
|
log->Printf ("SBEvent(%p)::GetType () => 0x%8.8x (%s)",
|
|
|
|
static_cast<void*>(get()), event_type, sstr.GetData());
|
2010-10-31 11:01:06 +08:00
|
|
|
else
|
2014-04-04 12:06:10 +08:00
|
|
|
log->Printf ("SBEvent(%p)::GetType () => 0x%8.8x",
|
|
|
|
static_cast<void*>(get()), event_type);
|
2010-10-31 11:01:06 +08:00
|
|
|
|
|
|
|
}
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
return event_type;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SBBroadcaster
|
|
|
|
SBEvent::GetBroadcaster () const
|
|
|
|
{
|
|
|
|
SBBroadcaster broadcaster;
|
2010-06-23 09:19:29 +08:00
|
|
|
const Event *lldb_event = get();
|
2010-06-09 00:52:24 +08:00
|
|
|
if (lldb_event)
|
2010-06-23 09:19:29 +08:00
|
|
|
broadcaster.reset (lldb_event->GetBroadcaster(), false);
|
2010-06-09 00:52:24 +08:00
|
|
|
return broadcaster;
|
|
|
|
}
|
|
|
|
|
2012-02-16 14:50:00 +08:00
|
|
|
const char *
|
|
|
|
SBEvent::GetBroadcasterClass () const
|
|
|
|
{
|
|
|
|
const Event *lldb_event = get();
|
|
|
|
if (lldb_event)
|
|
|
|
return lldb_event->GetBroadcaster()->GetBroadcasterClass().AsCString();
|
|
|
|
else
|
|
|
|
return "unknown class";
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
bool
|
|
|
|
SBEvent::BroadcasterMatchesPtr (const SBBroadcaster *broadcaster)
|
|
|
|
{
|
|
|
|
if (broadcaster)
|
2010-10-31 11:01:06 +08:00
|
|
|
return BroadcasterMatchesRef (*broadcaster);
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBEvent::BroadcasterMatchesRef (const SBBroadcaster &broadcaster)
|
|
|
|
{
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
Event *lldb_event = get();
|
2010-10-26 11:11:13 +08:00
|
|
|
bool success = false;
|
2010-06-09 00:52:24 +08:00
|
|
|
if (lldb_event)
|
2010-10-26 11:11:13 +08:00
|
|
|
success = lldb_event->BroadcasterIs (broadcaster.get());
|
|
|
|
|
2010-10-31 11:01:06 +08:00
|
|
|
// For logging, this gets a little chatty so only enable this when verbose logging is on
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API | LIBLLDB_LOG_VERBOSE));
|
2010-10-26 11:11:13 +08:00
|
|
|
if (log)
|
2014-04-04 12:06:10 +08:00
|
|
|
log->Printf ("SBEvent(%p)::BroadcasterMatchesRef (SBBroadcaster(%p): %s) => %i",
|
|
|
|
static_cast<void*>(get()),
|
|
|
|
static_cast<void*>(broadcaster.get()),
|
|
|
|
broadcaster.GetName(), success);
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
return success;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SBEvent::Clear()
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
Event *lldb_event = get();
|
2010-06-09 00:52:24 +08:00
|
|
|
if (lldb_event)
|
|
|
|
lldb_event->Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
EventSP &
|
2010-06-23 09:19:29 +08:00
|
|
|
SBEvent::GetSP () const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
return m_event_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
Event *
|
2010-06-23 09:19:29 +08:00
|
|
|
SBEvent::get() const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
// There is a dangerous accessor call GetSharedPtr which can be used, so if
|
|
|
|
// we have anything valid in m_event_sp, we must use that since if it gets
|
|
|
|
// used by a function that puts something in there, then it won't update
|
2010-11-06 07:17:00 +08:00
|
|
|
// m_opaque_ptr...
|
2010-06-09 00:52:24 +08:00
|
|
|
if (m_event_sp)
|
2010-11-06 07:17:00 +08:00
|
|
|
m_opaque_ptr = m_event_sp.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-11-06 07:17:00 +08:00
|
|
|
return m_opaque_ptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-23 09:19:29 +08:00
|
|
|
SBEvent::reset (EventSP &event_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
m_event_sp = event_sp;
|
2010-11-06 07:17:00 +08:00
|
|
|
m_opaque_ptr = m_event_sp.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-23 09:19:29 +08:00
|
|
|
SBEvent::reset (Event* event_ptr)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-11-06 07:17:00 +08:00
|
|
|
m_opaque_ptr = event_ptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
m_event_sp.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBEvent::IsValid() const
|
|
|
|
{
|
2010-11-06 07:17:00 +08:00
|
|
|
// Do NOT use m_opaque_ptr directly!!! Must use the SBEvent::get()
|
2010-06-23 09:19:29 +08:00
|
|
|
// accessor. See comments in SBEvent::get()....
|
|
|
|
return SBEvent::get() != NULL;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
SBEvent::GetCStringFromEvent (const SBEvent &event)
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
if (log)
|
2014-04-04 12:06:10 +08:00
|
|
|
log->Printf ("SBEvent(%p)::GetCStringFromEvent () => \"%s\"",
|
|
|
|
static_cast<void*>(event.get()),
|
2010-10-26 11:11:13 +08:00
|
|
|
reinterpret_cast<const char *>(EventDataBytes::GetBytesFromEvent (event.get())));
|
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
return reinterpret_cast<const char *>(EventDataBytes::GetBytesFromEvent (event.get()));
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-20 13:20:02 +08:00
|
|
|
bool
|
|
|
|
SBEvent::GetDescription (SBStream &description)
|
|
|
|
{
|
2011-11-13 14:57:31 +08:00
|
|
|
Stream &strm = description.ref();
|
|
|
|
|
2010-10-29 12:59:35 +08:00
|
|
|
if (get())
|
2010-09-21 00:21:41 +08:00
|
|
|
{
|
2011-11-13 14:57:31 +08:00
|
|
|
m_opaque_ptr->Dump (&strm);
|
2010-09-21 00:21:41 +08:00
|
|
|
}
|
2010-09-20 13:20:02 +08:00
|
|
|
else
|
2011-11-13 14:57:31 +08:00
|
|
|
strm.PutCString ("No value");
|
2010-09-20 13:20:02 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
bool
|
|
|
|
SBEvent::GetDescription (SBStream &description) const
|
|
|
|
{
|
2011-11-13 14:57:31 +08:00
|
|
|
Stream &strm = description.ref();
|
|
|
|
|
2010-10-29 12:59:35 +08:00
|
|
|
if (get())
|
2010-10-26 11:11:13 +08:00
|
|
|
{
|
2011-11-13 14:57:31 +08:00
|
|
|
m_opaque_ptr->Dump (&strm);
|
2010-10-26 11:11:13 +08:00
|
|
|
}
|
|
|
|
else
|
2011-11-13 14:57:31 +08:00
|
|
|
strm.PutCString ("No value");
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|