forked from OSchip/llvm-project
Reimplement EventDataBytes::Dump to avoid DumpDataExtractor
This is the only external non-trivial dependency of the Event classes. llvm-svn: 337819
This commit is contained in:
parent
6698f9b7db
commit
082bab1cff
|
@ -10,7 +10,6 @@
|
|||
#include "lldb/Core/Event.h"
|
||||
|
||||
#include "lldb/Core/Broadcaster.h"
|
||||
#include "lldb/Core/DumpDataExtractor.h"
|
||||
#include "lldb/Utility/DataExtractor.h"
|
||||
#include "lldb/Utility/Endian.h"
|
||||
#include "lldb/Utility/Stream.h"
|
||||
|
@ -134,14 +133,13 @@ const ConstString &EventDataBytes::GetFlavor() const {
|
|||
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());
|
||||
} else if (!m_bytes.empty()) {
|
||||
DataExtractor data;
|
||||
data.SetData(m_bytes.data(), m_bytes.size(), endian::InlHostByteOrder());
|
||||
DumpDataExtractor(data, s, 0, eFormatBytes, 1, m_bytes.size(), 32,
|
||||
LLDB_INVALID_ADDRESS, 0, 0);
|
||||
}
|
||||
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())));
|
||||
}
|
||||
|
||||
const void *EventDataBytes::GetBytes() const {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
add_lldb_unittest(LLDBCoreTests
|
||||
BroadcasterTest.cpp
|
||||
DataExtractorTest.cpp
|
||||
EventTest.cpp
|
||||
ListenerTest.cpp
|
||||
ScalarTest.cpp
|
||||
StateTest.cpp
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
//===-- EventTest.cpp -------------------------------------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "lldb/Core/Event.h"
|
||||
#include "lldb/Utility/StreamString.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace lldb_private;
|
||||
|
||||
static std::string to_string(const EventDataBytes &E) {
|
||||
StreamString S;
|
||||
E.Dump(&S);
|
||||
return S.GetString();
|
||||
}
|
||||
|
||||
TEST(EventTest, DumpEventDataBytes) {
|
||||
EXPECT_EQ(R"("foo")", to_string(EventDataBytes("foo")));
|
||||
EXPECT_EQ("01 02 03", to_string(EventDataBytes("\x01\x02\x03")));
|
||||
}
|
Loading…
Reference in New Issue