diff options
-rw-r--r-- | lldb/source/Core/Event.cpp | 16 | ||||
-rw-r--r-- | lldb/unittests/Core/CMakeLists.txt | 1 | ||||
-rw-r--r-- | lldb/unittests/Core/EventTest.cpp | 25 |
3 files changed, 33 insertions, 9 deletions
diff --git a/lldb/source/Core/Event.cpp b/lldb/source/Core/Event.cpp index 8d351d8ba1a..3ebad7acdef 100644 --- a/lldb/source/Core/Event.cpp +++ b/lldb/source/Core/Event.cpp @@ -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 { diff --git a/lldb/unittests/Core/CMakeLists.txt b/lldb/unittests/Core/CMakeLists.txt index 34c022c3430..f427845c20c 100644 --- a/lldb/unittests/Core/CMakeLists.txt +++ b/lldb/unittests/Core/CMakeLists.txt @@ -1,6 +1,7 @@ add_lldb_unittest(LLDBCoreTests BroadcasterTest.cpp DataExtractorTest.cpp + EventTest.cpp ListenerTest.cpp ScalarTest.cpp StateTest.cpp diff --git a/lldb/unittests/Core/EventTest.cpp b/lldb/unittests/Core/EventTest.cpp new file mode 100644 index 00000000000..32c6f4b1ce4 --- /dev/null +++ b/lldb/unittests/Core/EventTest.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"))); +} |