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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
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-06-23 09:19:29 +08:00
|
|
|
m_opaque (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-06-23 09:19:29 +08:00
|
|
|
m_opaque (m_event_sp.get())
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-10-27 07:49:36 +08:00
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
if (log)
|
|
|
|
{
|
2010-10-29 12:59:35 +08:00
|
|
|
log->Printf ("SBEvent::SBEvent (event_type=0x%8.8x, cstr='%s', cstr_len=%d) => SBEvent(%p)",
|
|
|
|
event_type,
|
|
|
|
cstr,
|
|
|
|
cstr_len,
|
|
|
|
m_opaque);
|
2010-10-26 11:11:13 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SBEvent::SBEvent (EventSP &event_sp) :
|
|
|
|
m_event_sp (event_sp),
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque (event_sp.get())
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-10-27 07:49:36 +08:00
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
if (log)
|
2010-10-29 12:59:35 +08:00
|
|
|
log->Printf ("SBEvent::SBEvent (event_sp=%p) => SBEvent(%p)", event_sp.get(), m_opaque);
|
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)
|
|
|
|
return lldb_event->GetData()->GetFlavor().AsCString();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
SBEvent::GetType () const
|
|
|
|
{
|
2010-10-26 11:11:13 +08:00
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
|
|
|
|
|
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-29 12:59:35 +08:00
|
|
|
log->Printf ("SBEvent(%p)::GetType () => 0x%8.8x", get(), event_type);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBEvent::BroadcasterMatchesPtr (const SBBroadcaster *broadcaster)
|
|
|
|
{
|
|
|
|
if (broadcaster)
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
Event *lldb_event = get();
|
2010-06-09 00:52:24 +08:00
|
|
|
if (lldb_event)
|
2010-06-23 09:19:29 +08:00
|
|
|
return lldb_event->BroadcasterIs (broadcaster->get());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBEvent::BroadcasterMatchesRef (const SBBroadcaster &broadcaster)
|
|
|
|
{
|
2010-10-26 11:11:13 +08:00
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
if (log)
|
2010-10-30 12:51:46 +08:00
|
|
|
log->Printf ("SBEvent(%p)::BroadcasterMatchesRef (SBBroadcaster(%p)) => %i",
|
2010-10-29 12:59:35 +08:00
|
|
|
get(),
|
|
|
|
broadcaster.get(),
|
2010-10-30 12:51:46 +08:00
|
|
|
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-06-23 09:19:29 +08:00
|
|
|
// m_opaque...
|
2010-06-09 00:52:24 +08:00
|
|
|
if (m_event_sp)
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque = m_event_sp.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
return m_opaque;
|
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-06-23 09:19:29 +08:00
|
|
|
m_opaque = 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-06-23 09:19:29 +08:00
|
|
|
m_opaque = event_ptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
m_event_sp.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBEvent::IsValid() const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
// Do NOT use m_opaque directly!!! Must use the SBEvent::get()
|
|
|
|
// 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)
|
|
|
|
{
|
2010-10-26 11:11:13 +08:00
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
|
|
|
|
|
|
|
|
if (log)
|
2010-10-29 12:59:35 +08:00
|
|
|
log->Printf ("SBEvent(%p)::GetCStringFromEvent () => '%s'",
|
|
|
|
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)
|
|
|
|
{
|
2010-10-29 12:59:35 +08:00
|
|
|
if (get())
|
2010-09-21 00:21:41 +08:00
|
|
|
{
|
2010-09-23 07:01:29 +08:00
|
|
|
description.ref();
|
2010-09-20 13:20:02 +08:00
|
|
|
m_opaque->Dump (description.get());
|
2010-09-21 00:21:41 +08:00
|
|
|
}
|
2010-09-20 13:20:02 +08:00
|
|
|
else
|
2010-09-21 00:21:41 +08:00
|
|
|
description.Printf ("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
|
|
|
|
{
|
2010-10-29 12:59:35 +08:00
|
|
|
if (get())
|
2010-10-26 11:11:13 +08:00
|
|
|
{
|
|
|
|
description.ref();
|
|
|
|
m_opaque->Dump (description.get());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
description.Printf ("No value");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|