2010-06-09 00:52:24 +08:00
|
|
|
//===-- Event.cpp -----------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// C Includes
|
|
|
|
// C++ Includes
|
|
|
|
// Other libraries and framework includes
|
|
|
|
// Project includes
|
|
|
|
#include "lldb/Core/Event.h"
|
|
|
|
#include "lldb/Core/Broadcaster.h"
|
|
|
|
#include "lldb/Core/DataExtractor.h"
|
|
|
|
#include "lldb/Core/Log.h"
|
|
|
|
#include "lldb/Core/State.h"
|
|
|
|
#include "lldb/Core/Stream.h"
|
2011-02-01 09:31:41 +08:00
|
|
|
#include "lldb/Host/Endian.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Target/Process.h"
|
2010-06-09 16:50:27 +08:00
|
|
|
#include <algorithm>
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Event constructor
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
Event::Event (Broadcaster *broadcaster, uint32_t event_type, EventData *data) :
|
|
|
|
m_broadcaster (broadcaster),
|
|
|
|
m_type (event_type),
|
|
|
|
m_data_ap (data)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Event::Event(uint32_t event_type, EventData *data) :
|
|
|
|
m_broadcaster (NULL), // Set by the broadcaster when this event gets broadcast
|
|
|
|
m_type (event_type),
|
|
|
|
m_data_ap (data)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Event destructor
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
Event::~Event ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Event::Dump (Stream *s) const
|
|
|
|
{
|
2012-10-30 02:08:18 +08:00
|
|
|
if (m_broadcaster)
|
|
|
|
{
|
|
|
|
StreamString event_name;
|
|
|
|
if (m_broadcaster->GetEventNames (event_name, m_type, false))
|
|
|
|
s->Printf("%p Event: broadcaster = %p (%s), type = 0x%8.8x (%s), data = ",
|
2014-04-04 12:06:10 +08:00
|
|
|
static_cast<const void*>(this),
|
|
|
|
static_cast<void*>(m_broadcaster),
|
2012-10-30 02:08:18 +08:00
|
|
|
m_broadcaster->GetBroadcasterName().GetCString(),
|
2014-04-04 12:06:10 +08:00
|
|
|
m_type, event_name.GetString().c_str());
|
2012-10-30 02:08:18 +08:00
|
|
|
else
|
|
|
|
s->Printf("%p Event: broadcaster = %p (%s), type = 0x%8.8x, data = ",
|
2014-04-04 12:06:10 +08:00
|
|
|
static_cast<const void*>(this),
|
|
|
|
static_cast<void*>(m_broadcaster),
|
|
|
|
m_broadcaster->GetBroadcasterName().GetCString(), m_type);
|
2012-10-30 02:08:18 +08:00
|
|
|
}
|
|
|
|
else
|
2014-04-04 12:06:10 +08:00
|
|
|
s->Printf("%p Event: broadcaster = NULL, type = 0x%8.8x, data = ",
|
|
|
|
static_cast<const void*>(this), m_type);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
if (m_data_ap.get() == NULL)
|
|
|
|
s->Printf ("<NULL>");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s->PutChar('{');
|
|
|
|
m_data_ap->Dump (s);
|
|
|
|
s->PutChar('}');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Event::DoOnRemoval ()
|
|
|
|
{
|
|
|
|
if (m_data_ap.get())
|
|
|
|
m_data_ap->DoOnRemoval (this);
|
|
|
|
}
|
|
|
|
|
|
|
|
EventData::EventData()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
EventData::~EventData()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
EventData::Dump (Stream *s) const
|
|
|
|
{
|
|
|
|
s->PutCString ("Generic Event Data");
|
|
|
|
}
|
|
|
|
|
|
|
|
EventDataBytes::EventDataBytes () :
|
|
|
|
m_bytes()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
EventDataBytes::EventDataBytes (const char *cstr) :
|
|
|
|
m_bytes()
|
|
|
|
{
|
|
|
|
SetBytesFromCString (cstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
EventDataBytes::EventDataBytes (const void *src, size_t src_len) :
|
|
|
|
m_bytes()
|
|
|
|
{
|
|
|
|
SetBytes (src, src_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
EventDataBytes::~EventDataBytes()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const ConstString &
|
|
|
|
EventDataBytes::GetFlavorString ()
|
|
|
|
{
|
|
|
|
static ConstString g_flavor ("EventDataBytes");
|
|
|
|
return g_flavor;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ConstString &
|
|
|
|
EventDataBytes::GetFlavor () const
|
|
|
|
{
|
|
|
|
return EventDataBytes::GetFlavorString ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
EventDataBytes::Dump (Stream *s) const
|
|
|
|
{
|
|
|
|
size_t num_printable_chars = std::count_if (m_bytes.begin(), m_bytes.end(), isprint);
|
|
|
|
if (num_printable_chars == m_bytes.size())
|
|
|
|
{
|
|
|
|
s->Printf("\"%s\"", m_bytes.c_str());
|
|
|
|
}
|
2010-07-21 06:52:08 +08:00
|
|
|
else if (m_bytes.size() > 0)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
DataExtractor data;
|
2015-11-07 12:40:13 +08:00
|
|
|
data.SetData(&m_bytes[0], m_bytes.size(), endian::InlHostByteOrder());
|
2010-06-09 00:52:24 +08:00
|
|
|
data.Dump(s, 0, eFormatBytes, 1, m_bytes.size(), 32, LLDB_INVALID_ADDRESS, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const void *
|
|
|
|
EventDataBytes::GetBytes() const
|
|
|
|
{
|
|
|
|
if (m_bytes.empty())
|
|
|
|
return NULL;
|
2010-07-21 06:52:08 +08:00
|
|
|
return &m_bytes[0];
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
EventDataBytes::GetByteSize() const
|
|
|
|
{
|
|
|
|
return m_bytes.size ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
EventDataBytes::SetBytes (const void *src, size_t src_len)
|
|
|
|
{
|
|
|
|
if (src && src_len > 0)
|
|
|
|
m_bytes.assign ((const char *)src, src_len);
|
|
|
|
else
|
|
|
|
m_bytes.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
EventDataBytes::SetBytesFromCString (const char *cstr)
|
|
|
|
{
|
|
|
|
if (cstr && cstr[0])
|
|
|
|
m_bytes.assign (cstr);
|
|
|
|
else
|
|
|
|
m_bytes.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const void *
|
|
|
|
EventDataBytes::GetBytesFromEvent (const Event *event_ptr)
|
|
|
|
{
|
|
|
|
const EventDataBytes *e = GetEventDataFromEvent (event_ptr);
|
|
|
|
if (e)
|
|
|
|
return e->GetBytes();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
EventDataBytes::GetByteSizeFromEvent (const Event *event_ptr)
|
|
|
|
{
|
|
|
|
const EventDataBytes *e = GetEventDataFromEvent (event_ptr);
|
|
|
|
if (e)
|
|
|
|
return e->GetByteSize();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const EventDataBytes *
|
|
|
|
EventDataBytes::GetEventDataFromEvent (const Event *event_ptr)
|
|
|
|
{
|
|
|
|
if (event_ptr)
|
|
|
|
{
|
|
|
|
const EventData *event_data = event_ptr->GetData();
|
|
|
|
if (event_data && event_data->GetFlavor() == EventDataBytes::GetFlavorString())
|
|
|
|
return static_cast <const EventDataBytes *> (event_data);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
This patch captures and serializes all output being written by the
command line driver, including the lldb prompt being output by
editline, the asynchronous process output & error messages, and
asynchronous messages written by target stop-hooks.
As part of this it introduces a new Stream class,
StreamAsynchronousIO. A StreamAsynchronousIO object is created with a
broadcaster, who will eventually broadcast the stream's data for a
listener to handle, and an event type indicating what type of event
the broadcaster will broadcast. When the Write method is called on a
StreamAsynchronousIO object, the data is appended to an internal
string. When the Flush method is called on a StreamAsynchronousIO
object, it broadcasts it's data string and clears the string.
Anything in lldb-core that needs to generate asynchronous output for
the end-user should use the StreamAsynchronousIO objects.
I have also added a new notification type for InputReaders, to let
them know that a asynchronous output has been written. This is to
allow the input readers to, for example, refresh their prompts and
lines, if desired. I added the case statements to all the input
readers to catch this notification, but I haven't added any code for
handling them yet (except to the IOChannel input reader).
llvm-svn: 130721
2011-05-03 04:41:46 +08:00
|
|
|
void
|
|
|
|
EventDataBytes::SwapBytes (std::string &new_bytes)
|
|
|
|
{
|
|
|
|
m_bytes.swap (new_bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
|