[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 15:23:27 +08:00
|
|
|
//===-- Event.cpp ---------------------------------------------------------===//
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2018-12-14 23:59:49 +08:00
|
|
|
#include "lldb/Utility/Event.h"
|
2016-03-11 07:57:12 +08:00
|
|
|
|
2018-12-14 23:59:49 +08:00
|
|
|
#include "lldb/Utility/Broadcaster.h"
|
2017-03-04 09:30:05 +08:00
|
|
|
#include "lldb/Utility/DataExtractor.h"
|
2017-02-15 03:06:07 +08:00
|
|
|
#include "lldb/Utility/Endian.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/Stream.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/Utility/StreamString.h"
|
|
|
|
#include "lldb/lldb-enumerations.h"
|
2017-04-07 05:28:29 +08:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
2021-05-26 18:19:37 +08:00
|
|
|
#include <cctype>
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2016-08-19 12:21:48 +08:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Event
|
|
|
|
|
|
|
|
// Event functions
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
Event::Event(Broadcaster *broadcaster, uint32_t event_type, EventData *data)
|
2016-05-13 06:58:52 +08:00
|
|
|
: m_broadcaster_wp(broadcaster->GetBroadcasterImpl()), m_type(event_type),
|
|
|
|
m_data_sp(data) {}
|
|
|
|
|
|
|
|
Event::Event(Broadcaster *broadcaster, uint32_t event_type,
|
|
|
|
const EventDataSP &event_data_sp)
|
|
|
|
: m_broadcaster_wp(broadcaster->GetBroadcasterImpl()), m_type(event_type),
|
|
|
|
m_data_sp(event_data_sp) {}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
Event::Event(uint32_t event_type, EventData *data)
|
2016-05-13 06:58:52 +08:00
|
|
|
: m_broadcaster_wp(), m_type(event_type), m_data_sp(data) {}
|
|
|
|
|
|
|
|
Event::Event(uint32_t event_type, const EventDataSP &event_data_sp)
|
|
|
|
: m_broadcaster_wp(), m_type(event_type), m_data_sp(event_data_sp) {}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-03-11 07:57:12 +08:00
|
|
|
Event::~Event() = default;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
void Event::Dump(Stream *s) const {
|
2016-03-08 05:50:25 +08:00
|
|
|
Broadcaster *broadcaster;
|
|
|
|
Broadcaster::BroadcasterImplSP broadcaster_impl_sp(m_broadcaster_wp.lock());
|
|
|
|
if (broadcaster_impl_sp)
|
|
|
|
broadcaster = broadcaster_impl_sp->GetBroadcaster();
|
|
|
|
else
|
|
|
|
broadcaster = nullptr;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-03-08 05:50:25 +08:00
|
|
|
if (broadcaster) {
|
2012-10-30 02:08:18 +08:00
|
|
|
StreamString event_name;
|
2016-03-08 05:50:25 +08:00
|
|
|
if (broadcaster->GetEventNames(event_name, m_type, false))
|
2012-10-30 02:08:18 +08:00
|
|
|
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),
|
2016-03-08 05:50:25 +08:00
|
|
|
static_cast<void *>(broadcaster),
|
|
|
|
broadcaster->GetBroadcasterName().GetCString(), m_type,
|
2016-11-17 05:15:24 +08:00
|
|
|
event_name.GetData());
|
2016-03-11 07:57:12 +08:00
|
|
|
else
|
2012-10-30 02:08:18 +08:00
|
|
|
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),
|
2016-03-08 05:50:25 +08:00
|
|
|
static_cast<void *>(broadcaster),
|
|
|
|
broadcaster->GetBroadcasterName().GetCString(), m_type);
|
2016-09-07 04:57:50 +08:00
|
|
|
} else
|
2012-10-30 02:08:18 +08:00
|
|
|
s->Printf("%p Event: broadcaster = NULL, type = 0x%8.8x, data = ",
|
2014-04-04 12:06:10 +08:00
|
|
|
static_cast<const void *>(this), m_type);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-03-11 07:57:12 +08:00
|
|
|
if (m_data_sp) {
|
2010-06-09 00:52:24 +08:00
|
|
|
s->PutChar('{');
|
2016-05-13 06:58:52 +08:00
|
|
|
m_data_sp->Dump(s);
|
2010-06-09 00:52:24 +08:00
|
|
|
s->PutChar('}');
|
2016-09-07 04:57:50 +08:00
|
|
|
} else
|
2016-03-11 07:57:12 +08:00
|
|
|
s->Printf("<NULL>");
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Event::DoOnRemoval() {
|
2016-05-13 06:58:52 +08:00
|
|
|
if (m_data_sp)
|
|
|
|
m_data_sp->DoOnRemoval(this);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-08-19 12:21:48 +08:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark EventData
|
|
|
|
|
|
|
|
// EventData functions
|
|
|
|
|
2016-03-11 07:57:12 +08:00
|
|
|
EventData::EventData() = default;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-03-11 07:57:12 +08:00
|
|
|
EventData::~EventData() = default;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
void EventData::Dump(Stream *s) const { s->PutCString("Generic Event Data"); }
|
|
|
|
|
2016-08-19 12:21:48 +08:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark EventDataBytes
|
|
|
|
|
|
|
|
// EventDataBytes functions
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
EventDataBytes::EventDataBytes() : m_bytes() {}
|
2016-08-19 12:21:48 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
EventDataBytes::EventDataBytes(const char *cstr) : m_bytes() {
|
|
|
|
SetBytesFromCString(cstr);
|
|
|
|
}
|
|
|
|
|
2016-09-24 02:06:53 +08:00
|
|
|
EventDataBytes::EventDataBytes(llvm::StringRef str) : m_bytes() {
|
|
|
|
SetBytes(str.data(), str.size());
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
EventDataBytes::EventDataBytes(const void *src, size_t src_len) : m_bytes() {
|
|
|
|
SetBytes(src, src_len);
|
|
|
|
}
|
|
|
|
|
2016-03-11 07:57:12 +08:00
|
|
|
EventDataBytes::~EventDataBytes() = default;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2019-03-07 05:22:25 +08:00
|
|
|
ConstString EventDataBytes::GetFlavorString() {
|
2010-06-09 00:52:24 +08:00
|
|
|
static ConstString g_flavor("EventDataBytes");
|
|
|
|
return g_flavor;
|
|
|
|
}
|
|
|
|
|
2019-03-07 05:22:25 +08:00
|
|
|
ConstString EventDataBytes::GetFlavor() const {
|
2010-06-09 00:52:24 +08:00
|
|
|
return EventDataBytes::GetFlavorString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventDataBytes::Dump(Stream *s) const {
|
|
|
|
size_t num_printable_chars =
|
2020-06-20 01:17:24 +08:00
|
|
|
std::count_if(m_bytes.begin(), m_bytes.end(), llvm::isPrint);
|
2018-07-24 18:49:14 +08:00
|
|
|
if (num_printable_chars == m_bytes.size())
|
|
|
|
s->Format("\"{0}\"", m_bytes);
|
|
|
|
else
|
|
|
|
s->Format("{0:$[ ]@[x-2]}", llvm::make_range(
|
|
|
|
reinterpret_cast<const uint8_t *>(m_bytes.data()),
|
|
|
|
reinterpret_cast<const uint8_t *>(m_bytes.data() +
|
|
|
|
m_bytes.size())));
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const void *EventDataBytes::GetBytes() const {
|
2016-03-11 07:57:12 +08:00
|
|
|
return (m_bytes.empty() ? nullptr : m_bytes.data());
|
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) {
|
2016-03-11 07:57:12 +08:00
|
|
|
if (src != nullptr && src_len > 0)
|
2019-05-23 13:12:11 +08:00
|
|
|
m_bytes.assign(static_cast<const char *>(src), src_len);
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
|
|
|
m_bytes.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventDataBytes::SetBytesFromCString(const char *cstr) {
|
2016-03-11 07:57:12 +08:00
|
|
|
if (cstr != nullptr && cstr[0])
|
2010-06-09 00:52:24 +08:00
|
|
|
m_bytes.assign(cstr);
|
|
|
|
else
|
|
|
|
m_bytes.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
const void *EventDataBytes::GetBytesFromEvent(const Event *event_ptr) {
|
|
|
|
const EventDataBytes *e = GetEventDataFromEvent(event_ptr);
|
2016-03-11 07:57:12 +08:00
|
|
|
if (e != nullptr)
|
2010-06-09 00:52:24 +08:00
|
|
|
return e->GetBytes();
|
2016-03-11 07:57:12 +08:00
|
|
|
return nullptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t EventDataBytes::GetByteSizeFromEvent(const Event *event_ptr) {
|
|
|
|
const EventDataBytes *e = GetEventDataFromEvent(event_ptr);
|
2016-03-11 07:57:12 +08:00
|
|
|
if (e != nullptr)
|
2010-06-09 00:52:24 +08:00
|
|
|
return e->GetByteSize();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const EventDataBytes *
|
|
|
|
EventDataBytes::GetEventDataFromEvent(const Event *event_ptr) {
|
2016-03-11 07:57:12 +08:00
|
|
|
if (event_ptr != nullptr) {
|
2010-06-09 00:52:24 +08:00
|
|
|
const EventData *event_data = event_ptr->GetData();
|
|
|
|
if (event_data &&
|
|
|
|
event_data->GetFlavor() == EventDataBytes::GetFlavorString())
|
|
|
|
return static_cast<const EventDataBytes *>(event_data);
|
|
|
|
}
|
2016-03-11 07:57:12 +08:00
|
|
|
return nullptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
2016-08-19 12:21:48 +08:00
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark EventStructuredData
|
|
|
|
|
|
|
|
// EventDataStructuredData definitions
|
|
|
|
|
|
|
|
EventDataStructuredData::EventDataStructuredData()
|
|
|
|
: EventData(), m_process_sp(), m_object_sp(), m_plugin_sp() {}
|
|
|
|
|
|
|
|
EventDataStructuredData::EventDataStructuredData(
|
|
|
|
const ProcessSP &process_sp, const StructuredData::ObjectSP &object_sp,
|
|
|
|
const lldb::StructuredDataPluginSP &plugin_sp)
|
|
|
|
: EventData(), m_process_sp(process_sp), m_object_sp(object_sp),
|
|
|
|
m_plugin_sp(plugin_sp) {}
|
|
|
|
|
|
|
|
EventDataStructuredData::~EventDataStructuredData() {}
|
|
|
|
|
|
|
|
// EventDataStructuredData member functions
|
|
|
|
|
2019-03-07 05:22:25 +08:00
|
|
|
ConstString EventDataStructuredData::GetFlavor() const {
|
2016-08-19 12:21:48 +08:00
|
|
|
return EventDataStructuredData::GetFlavorString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventDataStructuredData::Dump(Stream *s) const {
|
|
|
|
if (!s)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (m_object_sp)
|
|
|
|
m_object_sp->Dump(*s);
|
|
|
|
}
|
|
|
|
|
|
|
|
const ProcessSP &EventDataStructuredData::GetProcess() const {
|
|
|
|
return m_process_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
const StructuredData::ObjectSP &EventDataStructuredData::GetObject() const {
|
|
|
|
return m_object_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
const lldb::StructuredDataPluginSP &
|
|
|
|
EventDataStructuredData::GetStructuredDataPlugin() const {
|
|
|
|
return m_plugin_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventDataStructuredData::SetProcess(const ProcessSP &process_sp) {
|
|
|
|
m_process_sp = process_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventDataStructuredData::SetObject(
|
|
|
|
const StructuredData::ObjectSP &object_sp) {
|
|
|
|
m_object_sp = object_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventDataStructuredData::SetStructuredDataPlugin(
|
|
|
|
const lldb::StructuredDataPluginSP &plugin_sp) {
|
|
|
|
m_plugin_sp = plugin_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
// EventDataStructuredData static functions
|
|
|
|
|
|
|
|
const EventDataStructuredData *
|
|
|
|
EventDataStructuredData::GetEventDataFromEvent(const Event *event_ptr) {
|
|
|
|
if (event_ptr == nullptr)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
const EventData *event_data = event_ptr->GetData();
|
|
|
|
if (!event_data ||
|
|
|
|
event_data->GetFlavor() != EventDataStructuredData::GetFlavorString())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return static_cast<const EventDataStructuredData *>(event_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcessSP EventDataStructuredData::GetProcessFromEvent(const Event *event_ptr) {
|
|
|
|
auto event_data = EventDataStructuredData::GetEventDataFromEvent(event_ptr);
|
|
|
|
if (event_data)
|
|
|
|
return event_data->GetProcess();
|
|
|
|
else
|
|
|
|
return ProcessSP();
|
|
|
|
}
|
|
|
|
|
|
|
|
StructuredData::ObjectSP
|
|
|
|
EventDataStructuredData::GetObjectFromEvent(const Event *event_ptr) {
|
|
|
|
auto event_data = EventDataStructuredData::GetEventDataFromEvent(event_ptr);
|
|
|
|
if (event_data)
|
|
|
|
return event_data->GetObject();
|
|
|
|
else
|
|
|
|
return StructuredData::ObjectSP();
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb::StructuredDataPluginSP
|
|
|
|
EventDataStructuredData::GetPluginFromEvent(const Event *event_ptr) {
|
|
|
|
auto event_data = EventDataStructuredData::GetEventDataFromEvent(event_ptr);
|
|
|
|
if (event_data)
|
|
|
|
return event_data->GetStructuredDataPlugin();
|
|
|
|
else
|
|
|
|
return StructuredDataPluginSP();
|
|
|
|
}
|
|
|
|
|
2019-03-07 05:22:25 +08:00
|
|
|
ConstString EventDataStructuredData::GetFlavorString() {
|
2016-08-19 12:21:48 +08:00
|
|
|
static ConstString s_flavor("EventDataStructuredData");
|
|
|
|
return s_flavor;
|
|
|
|
}
|