From 2a66884f7846aa93acfbab2cba89145c7d67ed46 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Thu, 22 Sep 2016 15:26:43 +0000 Subject: [PATCH] Fix TestBreakpointSerialization on windows The test exposed a bug in the StructuredData Serialization code, which did not escape the backslash properly. This manifested itself as windows breakpoint serialization roundtrip test not succeeding (as windows paths included backslashes). llvm-svn: 282167 --- lldb/source/Core/StructuredData.cpp | 2 +- lldb/unittests/Core/CMakeLists.txt | 1 + lldb/unittests/Core/StructuredDataTest.cpp | 32 ++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 lldb/unittests/Core/StructuredDataTest.cpp diff --git a/lldb/source/Core/StructuredData.cpp b/lldb/source/Core/StructuredData.cpp index 3866861..46be782 100644 --- a/lldb/source/Core/StructuredData.cpp +++ b/lldb/source/Core/StructuredData.cpp @@ -264,7 +264,7 @@ void StructuredData::String::Dump(Stream &s, bool pretty_print) const { const size_t strsize = m_value.size(); for (size_t i = 0; i < strsize; ++i) { char ch = m_value[i]; - if (ch == '"') + if (ch == '"' || ch == '\\') quoted.push_back('\\'); quoted.push_back(ch); } diff --git a/lldb/unittests/Core/CMakeLists.txt b/lldb/unittests/Core/CMakeLists.txt index 8ab43d66..9ec5175 100644 --- a/lldb/unittests/Core/CMakeLists.txt +++ b/lldb/unittests/Core/CMakeLists.txt @@ -3,4 +3,5 @@ add_lldb_unittest(LLDBCoreTests BroadcasterTest.cpp DataExtractorTest.cpp ScalarTest.cpp + StructuredDataTest.cpp ) diff --git a/lldb/unittests/Core/StructuredDataTest.cpp b/lldb/unittests/Core/StructuredDataTest.cpp new file mode 100644 index 0000000..8e10d57 --- /dev/null +++ b/lldb/unittests/Core/StructuredDataTest.cpp @@ -0,0 +1,32 @@ +//===-- StructuredDataTest.cpp ----------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "gtest/gtest.h" + +#include "lldb/Core/StructuredData.h" +#include "lldb/Core/StreamString.h" + +#include "llvm/Support/MachO.h" + +using namespace lldb; +using namespace lldb_private; + +TEST(StructuredDataTest, StringDump) { + std::pair TestCases[] = { + { R"(asdfg)", R"("asdfg")" }, + { R"(as"df)", R"("as\"df")" }, + { R"(as\df)", R"("as\\df")" }, + }; + for(auto P : TestCases) { + StreamString S; + const bool pretty_print = false; + StructuredData::String(P.first).Dump(S, pretty_print); + EXPECT_EQ(P.second, S.GetString()); + } +} -- 2.7.4