[Lldb-commits] [lldb] r337819 - Reimplement EventDataBytes::Dump to avoid DumpDataExtractor
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Tue Jul 24 03:49:15 PDT 2018
Author: labath
Date: Tue Jul 24 03:49:14 2018
New Revision: 337819
URL: http://llvm.org/viewvc/llvm-project?rev=337819&view=rev
Log:
Reimplement EventDataBytes::Dump to avoid DumpDataExtractor
This is the only external non-trivial dependency of the Event classes.
Added:
lldb/trunk/unittests/Core/EventTest.cpp
Modified:
lldb/trunk/source/Core/Event.cpp
lldb/trunk/unittests/Core/CMakeLists.txt
Modified: lldb/trunk/source/Core/Event.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Event.cpp?rev=337819&r1=337818&r2=337819&view=diff
==============================================================================
--- lldb/trunk/source/Core/Event.cpp (original)
+++ lldb/trunk/source/Core/Event.cpp Tue Jul 24 03:49:14 2018
@@ -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::GetFl
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 {
Modified: lldb/trunk/unittests/Core/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Core/CMakeLists.txt?rev=337819&r1=337818&r2=337819&view=diff
==============================================================================
--- lldb/trunk/unittests/Core/CMakeLists.txt (original)
+++ lldb/trunk/unittests/Core/CMakeLists.txt Tue Jul 24 03:49:14 2018
@@ -1,6 +1,7 @@
add_lldb_unittest(LLDBCoreTests
BroadcasterTest.cpp
DataExtractorTest.cpp
+ EventTest.cpp
ListenerTest.cpp
ScalarTest.cpp
StateTest.cpp
Added: lldb/trunk/unittests/Core/EventTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Core/EventTest.cpp?rev=337819&view=auto
==============================================================================
--- lldb/trunk/unittests/Core/EventTest.cpp (added)
+++ lldb/trunk/unittests/Core/EventTest.cpp Tue Jul 24 03:49:14 2018
@@ -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")));
+}
More information about the lldb-commits
mailing list