summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
Diffstat (limited to 'unittests')
-rw-r--r--unittests/Core/CMakeLists.txt2
-rw-r--r--unittests/Core/StructuredDataTest.cpp32
-rw-r--r--unittests/Interpreter/CMakeLists.txt2
-rw-r--r--unittests/Interpreter/TestCompletion.cpp3
-rw-r--r--unittests/ObjectFile/ELF/CMakeLists.txt1
-rw-r--r--unittests/ObjectFile/ELF/TestObjectFileELF.cpp16
-rw-r--r--unittests/Process/CMakeLists.txt3
-rw-r--r--unittests/Process/Linux/CMakeLists.txt8
-rw-r--r--unittests/Process/Linux/ProcessorTraceTest.cpp152
-rw-r--r--unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp4
-rw-r--r--unittests/Process/minidump/CMakeLists.txt1
-rw-r--r--unittests/Process/minidump/MinidumpParserTest.cpp15
-rw-r--r--unittests/Symbol/CMakeLists.txt9
-rw-r--r--unittests/Symbol/Inputs/basic-call-frame-info.yaml138
-rw-r--r--unittests/Symbol/TestDWARFCallFrameInfo.cpp142
-rw-r--r--unittests/SymbolFile/DWARF/CMakeLists.txt1
-rw-r--r--unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp21
-rw-r--r--unittests/SymbolFile/PDB/CMakeLists.txt1
-rw-r--r--unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp24
-rw-r--r--unittests/Target/CMakeLists.txt1
-rw-r--r--unittests/Target/ModuleCacheTest.cpp12
-rw-r--r--unittests/UnwindAssembly/x86/Testx86AssemblyInspectionEngine.cpp78
-rw-r--r--unittests/Utility/CMakeLists.txt10
-rw-r--r--unittests/Utility/Helpers/CMakeLists.txt (renamed from unittests/Utility/Mocks/CMakeLists.txt)4
-rw-r--r--unittests/Utility/Helpers/MockTildeExpressionResolver.cpp (renamed from unittests/Utility/Mocks/MockTildeExpressionResolver.cpp)0
-rw-r--r--unittests/Utility/Helpers/MockTildeExpressionResolver.h (renamed from unittests/Utility/Mocks/MockTildeExpressionResolver.h)2
-rw-r--r--unittests/Utility/Helpers/TestUtilities.cpp22
-rw-r--r--unittests/Utility/Helpers/TestUtilities.h20
-rw-r--r--unittests/Utility/Inputs/StructuredData-basic.json1
-rw-r--r--unittests/Utility/StructuredDataTest.cpp48
-rw-r--r--unittests/Utility/TildeExpressionResolverTest.cpp2
-rw-r--r--unittests/Utility/TimerTest.cpp (renamed from unittests/Core/TimerTest.cpp)5
-rw-r--r--unittests/tools/lldb-server/tests/MessageObjects.cpp2
33 files changed, 671 insertions, 111 deletions
diff --git a/unittests/Core/CMakeLists.txt b/unittests/Core/CMakeLists.txt
index 73dd0d83fee3a..426009661b121 100644
--- a/unittests/Core/CMakeLists.txt
+++ b/unittests/Core/CMakeLists.txt
@@ -6,8 +6,6 @@ add_lldb_unittest(LLDBCoreTests
ScalarTest.cpp
StateTest.cpp
StreamCallbackTest.cpp
- StructuredDataTest.cpp
- TimerTest.cpp
LINK_LIBS
lldbCore
diff --git a/unittests/Core/StructuredDataTest.cpp b/unittests/Core/StructuredDataTest.cpp
deleted file mode 100644
index cdcf3236cd774..0000000000000
--- a/unittests/Core/StructuredDataTest.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-//===-- 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/Utility/StreamString.h"
-
-#include "llvm/BinaryFormat/MachO.h"
-
-using namespace lldb;
-using namespace lldb_private;
-
-TEST(StructuredDataTest, StringDump) {
- std::pair<llvm::StringRef, llvm::StringRef> 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());
- }
-}
diff --git a/unittests/Interpreter/CMakeLists.txt b/unittests/Interpreter/CMakeLists.txt
index d884dee62ec55..7be092b24b5e4 100644
--- a/unittests/Interpreter/CMakeLists.txt
+++ b/unittests/Interpreter/CMakeLists.txt
@@ -4,7 +4,7 @@ add_lldb_unittest(InterpreterTests
LINK_LIBS
lldbInterpreter
- lldbUtilityMocks
+ lldbUtilityHelpers
)
target_link_libraries(InterpreterTests
diff --git a/unittests/Interpreter/TestCompletion.cpp b/unittests/Interpreter/TestCompletion.cpp
index 0548b93d6f722..0baf61fdaf34f 100644
--- a/unittests/Interpreter/TestCompletion.cpp
+++ b/unittests/Interpreter/TestCompletion.cpp
@@ -12,13 +12,12 @@
#include "lldb/Utility/StringList.h"
#include "lldb/Utility/TildeExpressionResolver.h"
+#include "unittests/Utility/Helpers/MockTildeExpressionResolver.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
-#include "unittests/Utility/Mocks/MockTildeExpressionResolver.h"
-
namespace fs = llvm::sys::fs;
namespace path = llvm::sys::path;
using namespace llvm;
diff --git a/unittests/ObjectFile/ELF/CMakeLists.txt b/unittests/ObjectFile/ELF/CMakeLists.txt
index a182f4a4244e9..652c221a6d844 100644
--- a/unittests/ObjectFile/ELF/CMakeLists.txt
+++ b/unittests/ObjectFile/ELF/CMakeLists.txt
@@ -6,6 +6,7 @@ add_lldb_unittest(ObjectFileELFTests
lldbPluginObjectFileELF
lldbPluginSymbolVendorELF
lldbCore
+ lldbUtilityHelpers
)
add_dependencies(ObjectFileELFTests yaml2obj)
diff --git a/unittests/ObjectFile/ELF/TestObjectFileELF.cpp b/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
index 6ed9b2357bb17..e9b3e9fcf2377 100644
--- a/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
+++ b/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
@@ -9,20 +9,18 @@
//===----------------------------------------------------------------------===//
#include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
+#include "Plugins/SymbolVendor/ELF/SymbolVendorELF.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/Section.h"
#include "lldb/Host/HostInfo.h"
+#include "unittests/Utility/Helpers/TestUtilities.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/raw_ostream.h"
#include "gtest/gtest.h"
-#include "Plugins/SymbolVendor/ELF/SymbolVendorELF.h"
-
-extern const char *TestMainArgv0;
-
using namespace lldb_private;
using namespace lldb;
@@ -32,10 +30,6 @@ public:
HostInfo::Initialize();
ObjectFileELF::Initialize();
SymbolVendorELF::Initialize();
-
- m_inputs_folder = llvm::sys::path::parent_path(TestMainArgv0);
- llvm::sys::path::append(m_inputs_folder, "Inputs");
- llvm::sys::fs::make_absolute(m_inputs_folder);
}
void TearDown() override {
@@ -45,7 +39,6 @@ public:
}
protected:
- llvm::SmallString<128> m_inputs_folder;
};
#define ASSERT_NO_ERROR(x) \
@@ -60,9 +53,8 @@ protected:
}
TEST_F(ObjectFileELFTest, SectionsResolveConsistently) {
- llvm::SmallString<128> yaml = m_inputs_folder;
- llvm::sys::path::append(yaml, "sections-resolve-consistently.yaml");
- llvm::SmallString<128> obj = m_inputs_folder;
+ std::string yaml = GetInputFilePath("sections-resolve-consistently.yaml");
+ llvm::SmallString<128> obj;
ASSERT_NO_ERROR(llvm::sys::fs::createTemporaryFile(
"sections-resolve-consistently-%%%%%%", "obj", obj));
diff --git a/unittests/Process/CMakeLists.txt b/unittests/Process/CMakeLists.txt
index 70f59382afa18..75db3bec625aa 100644
--- a/unittests/Process/CMakeLists.txt
+++ b/unittests/Process/CMakeLists.txt
@@ -1,2 +1,5 @@
add_subdirectory(gdb-remote)
+if (CMAKE_SYSTEM_NAME MATCHES "Linux|Android")
+ add_subdirectory(Linux)
+endif()
add_subdirectory(minidump)
diff --git a/unittests/Process/Linux/CMakeLists.txt b/unittests/Process/Linux/CMakeLists.txt
new file mode 100644
index 0000000000000..3b55b5c843052
--- /dev/null
+++ b/unittests/Process/Linux/CMakeLists.txt
@@ -0,0 +1,8 @@
+include_directories(${LLDB_SOURCE_DIR}/source/Plugins/Process/Linux)
+
+add_lldb_unittest(ProcessorTraceTest
+ ProcessorTraceTest.cpp
+
+ LINK_LIBS
+ lldbPluginProcessLinux
+ ) \ No newline at end of file
diff --git a/unittests/Process/Linux/ProcessorTraceTest.cpp b/unittests/Process/Linux/ProcessorTraceTest.cpp
new file mode 100644
index 0000000000000..b732934d014d5
--- /dev/null
+++ b/unittests/Process/Linux/ProcessorTraceTest.cpp
@@ -0,0 +1,152 @@
+//===-- ProcessorTraceMonitorTest.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 "ProcessorTrace.h"
+#include "llvm/ADT/ArrayRef.h"
+// C Includes
+
+// C++ Includes
+
+using namespace lldb_private;
+using namespace process_linux;
+
+size_t ReadCylicBufferWrapper(void *buf, size_t buf_size, void *cyc_buf,
+ size_t cyc_buf_size, size_t cyc_start,
+ size_t offset) {
+ llvm::MutableArrayRef<uint8_t> dst(reinterpret_cast<uint8_t *>(buf),
+ buf_size);
+ llvm::MutableArrayRef<uint8_t> src(reinterpret_cast<uint8_t *>(cyc_buf),
+ cyc_buf_size);
+ ProcessorTraceMonitor::ReadCyclicBuffer(dst, src, cyc_start, offset);
+ return dst.size();
+}
+
+TEST(CyclicBuffer, EdgeCases) {
+ size_t bytes_read = 0;
+ uint8_t cyclic_buffer[6] = {'l', 'i', 'c', 'c', 'y', 'c'};
+
+ // We will always leave the last bytes untouched
+ // so that string comparisions work.
+ char bigger_buffer[10] = {};
+ char equal_size_buffer[7] = {};
+ char smaller_buffer[4] = {};
+
+ // empty buffer to read into
+ bytes_read = ReadCylicBufferWrapper(smaller_buffer, 0, cyclic_buffer,
+ sizeof(cyclic_buffer), 3, 0);
+ ASSERT_EQ(0, bytes_read);
+
+ // empty cyclic buffer
+ bytes_read = ReadCylicBufferWrapper(smaller_buffer, sizeof(smaller_buffer),
+ cyclic_buffer, 0, 3, 0);
+ ASSERT_EQ(0, bytes_read);
+
+ // bigger offset
+ bytes_read =
+ ReadCylicBufferWrapper(smaller_buffer, sizeof(smaller_buffer),
+ cyclic_buffer, sizeof(cyclic_buffer), 3, 6);
+ ASSERT_EQ(0, bytes_read);
+
+ // wrong offset
+ bytes_read =
+ ReadCylicBufferWrapper(smaller_buffer, sizeof(smaller_buffer),
+ cyclic_buffer, sizeof(cyclic_buffer), 3, 7);
+ ASSERT_EQ(0, bytes_read);
+
+ // wrong start
+ bytes_read =
+ ReadCylicBufferWrapper(smaller_buffer, sizeof(smaller_buffer),
+ cyclic_buffer, sizeof(cyclic_buffer), 3, 7);
+ ASSERT_EQ(0, bytes_read);
+}
+
+TEST(CyclicBuffer, EqualSizeBuffer) {
+ size_t bytes_read = 0;
+ uint8_t cyclic_buffer[6] = {'l', 'i', 'c', 'c', 'y', 'c'};
+
+ char cyclic[] = "cyclic";
+ for (int i = 0; i < sizeof(cyclic); i++) {
+ // We will always leave the last bytes untouched
+ // so that string comparisions work.
+ char equal_size_buffer[7] = {};
+ bytes_read =
+ ReadCylicBufferWrapper(equal_size_buffer, sizeof(cyclic_buffer),
+ cyclic_buffer, sizeof(cyclic_buffer), 3, i);
+ ASSERT_EQ((sizeof(cyclic) - i - 1), bytes_read);
+ ASSERT_STREQ(equal_size_buffer, (cyclic + i));
+ }
+}
+
+TEST(CyclicBuffer, SmallerSizeBuffer) {
+ size_t bytes_read = 0;
+ uint8_t cyclic_buffer[6] = {'l', 'i', 'c', 'c', 'y', 'c'};
+
+ // We will always leave the last bytes untouched
+ // so that string comparisions work.
+ char smaller_buffer[4] = {};
+ bytes_read =
+ ReadCylicBufferWrapper(smaller_buffer, (sizeof(smaller_buffer) - 1),
+ cyclic_buffer, sizeof(cyclic_buffer), 3, 0);
+ ASSERT_EQ(3, bytes_read);
+ ASSERT_STREQ(smaller_buffer, "cyc");
+
+ bytes_read =
+ ReadCylicBufferWrapper(smaller_buffer, (sizeof(smaller_buffer) - 1),
+ cyclic_buffer, sizeof(cyclic_buffer), 3, 1);
+ ASSERT_EQ(3, bytes_read);
+ ASSERT_STREQ(smaller_buffer, "ycl");
+
+ bytes_read =
+ ReadCylicBufferWrapper(smaller_buffer, (sizeof(smaller_buffer) - 1),
+ cyclic_buffer, sizeof(cyclic_buffer), 3, 2);
+ ASSERT_EQ(3, bytes_read);
+ ASSERT_STREQ(smaller_buffer, "cli");
+
+ bytes_read =
+ ReadCylicBufferWrapper(smaller_buffer, (sizeof(smaller_buffer) - 1),
+ cyclic_buffer, sizeof(cyclic_buffer), 3, 3);
+ ASSERT_EQ(3, bytes_read);
+ ASSERT_STREQ(smaller_buffer, "lic");
+
+ {
+ char smaller_buffer[4] = {};
+ bytes_read =
+ ReadCylicBufferWrapper(smaller_buffer, (sizeof(smaller_buffer) - 1),
+ cyclic_buffer, sizeof(cyclic_buffer), 3, 4);
+ ASSERT_EQ(2, bytes_read);
+ ASSERT_STREQ(smaller_buffer, "ic");
+ }
+ {
+ char smaller_buffer[4] = {};
+ bytes_read =
+ ReadCylicBufferWrapper(smaller_buffer, (sizeof(smaller_buffer) - 1),
+ cyclic_buffer, sizeof(cyclic_buffer), 3, 5);
+ ASSERT_EQ(1, bytes_read);
+ ASSERT_STREQ(smaller_buffer, "c");
+ }
+}
+
+TEST(CyclicBuffer, BiggerSizeBuffer) {
+ size_t bytes_read = 0;
+ uint8_t cyclic_buffer[6] = {'l', 'i', 'c', 'c', 'y', 'c'};
+
+ char cyclic[] = "cyclic";
+ for (int i = 0; i < sizeof(cyclic); i++) {
+ // We will always leave the last bytes untouched
+ // so that string comparisions work.
+ char bigger_buffer[10] = {};
+ bytes_read =
+ ReadCylicBufferWrapper(bigger_buffer, (sizeof(bigger_buffer) - 1),
+ cyclic_buffer, sizeof(cyclic_buffer), 3, i);
+ ASSERT_EQ((sizeof(cyclic) - i - 1), bytes_read);
+ ASSERT_STREQ(bigger_buffer, (cyclic + i));
+ }
+}
diff --git a/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp b/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
index cd2583bb8f547..90a9c7ea7a0fc 100644
--- a/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
+++ b/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
@@ -12,10 +12,10 @@
#include "Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h"
#include "lldb/Core/ModuleSpec.h"
-#include "lldb/Core/StructuredData.h"
-#include "lldb/Core/TraceOptions.h"
#include "lldb/Target/MemoryRegionInfo.h"
#include "lldb/Utility/DataBuffer.h"
+#include "lldb/Utility/StructuredData.h"
+#include "lldb/Utility/TraceOptions.h"
#include "lldb/lldb-enumerations.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/Testing/Support/Error.h"
diff --git a/unittests/Process/minidump/CMakeLists.txt b/unittests/Process/minidump/CMakeLists.txt
index 2b2df6327e9a8..e1b8154e1c319 100644
--- a/unittests/Process/minidump/CMakeLists.txt
+++ b/unittests/Process/minidump/CMakeLists.txt
@@ -7,6 +7,7 @@ add_lldb_unittest(LLDBMinidumpTests
lldbTarget
lldbPluginProcessUtility
lldbPluginProcessMinidump
+ lldbUtilityHelpers
LINK_COMPONENTS
Support
)
diff --git a/unittests/Process/minidump/MinidumpParserTest.cpp b/unittests/Process/minidump/MinidumpParserTest.cpp
index 755095f75918f..a029466fc59e4 100644
--- a/unittests/Process/minidump/MinidumpParserTest.cpp
+++ b/unittests/Process/minidump/MinidumpParserTest.cpp
@@ -23,7 +23,7 @@
#include "lldb/Utility/DataBufferLLVM.h"
#include "lldb/Utility/DataExtractor.h"
#include "lldb/Utility/FileSpec.h"
-
+#include "unittests/Utility/Helpers/TestUtilities.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Optional.h"
#include "llvm/Support/FileSystem.h"
@@ -35,24 +35,14 @@
// C++ includes
#include <memory>
-extern const char *TestMainArgv0;
-
using namespace lldb_private;
using namespace minidump;
class MinidumpParserTest : public testing::Test {
public:
- void SetUp() override {
- llvm::StringRef dmp_folder = llvm::sys::path::parent_path(TestMainArgv0);
- inputs_folder = dmp_folder;
- llvm::sys::path::append(inputs_folder, "Inputs");
- }
-
void SetUpData(const char *minidump_filename,
uint64_t load_size = UINT64_MAX) {
- llvm::SmallString<128> filename = inputs_folder;
- llvm::sys::path::append(filename, minidump_filename);
-
+ std::string filename = GetInputFilePath(minidump_filename);
auto BufferPtr = DataBufferLLVM::CreateSliceFromPath(filename, load_size, 0);
llvm::Optional<MinidumpParser> optional_parser =
@@ -62,7 +52,6 @@ public:
ASSERT_GT(parser->GetData().size(), 0UL);
}
- llvm::SmallString<128> inputs_folder;
std::unique_ptr<MinidumpParser> parser;
};
diff --git a/unittests/Symbol/CMakeLists.txt b/unittests/Symbol/CMakeLists.txt
index dca5f17b15de5..2d042648c4b3b 100644
--- a/unittests/Symbol/CMakeLists.txt
+++ b/unittests/Symbol/CMakeLists.txt
@@ -1,8 +1,17 @@
add_lldb_unittest(SymbolTests
TestClangASTContext.cpp
+ TestDWARFCallFrameInfo.cpp
TestType.cpp
LINK_LIBS
lldbHost
lldbSymbol
+ lldbUtilityHelpers
)
+
+add_dependencies(SymbolTests yaml2obj)
+add_definitions(-DYAML2OBJ="$<TARGET_FILE:yaml2obj>")
+set(test_inputs
+ basic-call-frame-info.yaml
+ )
+add_unittest_inputs(SymbolTests "${test_inputs}")
diff --git a/unittests/Symbol/Inputs/basic-call-frame-info.yaml b/unittests/Symbol/Inputs/basic-call-frame-info.yaml
new file mode 100644
index 0000000000000..7bd8a48b87db0
--- /dev/null
+++ b/unittests/Symbol/Inputs/basic-call-frame-info.yaml
@@ -0,0 +1,138 @@
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+ Entry: 0x0000000000000260
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Address: 0x0000000000000260
+ AddressAlign: 0x0000000000000010
+ Content: 554889E5897DFC8B45FC5DC30F1F4000554889E5897DFC8B45FC5DC30F1F4000554889E5897DFC8B45FC5DC3
+#0000000000000260 <eh_frame>:
+# 260: 55 push %rbp
+# 261: 48 89 e5 mov %rsp,%rbp
+# 264: 89 7d fc mov %edi,-0x4(%rbp)
+# 267: 8b 45 fc mov -0x4(%rbp),%eax
+# 26a: 5d pop %rbp
+# 26b: c3 retq
+# 26c: 0f 1f 40 00 nopl 0x0(%rax)
+#
+#0000000000000270 <debug_frame3>:
+# 270: 55 push %rbp
+# 271: 48 89 e5 mov %rsp,%rbp
+# 274: 89 7d fc mov %edi,-0x4(%rbp)
+# 277: 8b 45 fc mov -0x4(%rbp),%eax
+# 27a: 5d pop %rbp
+# 27b: c3 retq
+# 27c: 0f 1f 40 00 nopl 0x0(%rax)
+#
+#0000000000000280 <debug_frame4>:
+# 280: 55 push %rbp
+# 281: 48 89 e5 mov %rsp,%rbp
+# 284: 89 7d fc mov %edi,-0x4(%rbp)
+# 287: 8b 45 fc mov -0x4(%rbp),%eax
+# 28a: 5d pop %rbp
+# 28b: c3 retq
+ - Name: .eh_frame
+ Type: SHT_X86_64_UNWIND
+ Flags: [ SHF_ALLOC ]
+ Address: 0x0000000000000290
+ AddressAlign: 0x0000000000000008
+ Content: 1400000000000000017A5200017810011B0C0708900100001C0000001C000000B0FFFFFF0C00000000410E108602430D0600000000000000
+#00000000 0000000000000014 00000000 CIE
+# Version: 1
+# Augmentation: "zR"
+# Code alignment factor: 1
+# Data alignment factor: -8
+# Return address column: 16
+# Augmentation data: 1b
+#
+# DW_CFA_def_cfa: r7 (rsp) ofs 8
+# DW_CFA_offset: r16 (rip) at cfa-8
+# DW_CFA_nop
+# DW_CFA_nop
+#
+#00000018 000000000000001c 0000001c FDE cie=00000000 pc=ffffffffffffffd0..ffffffffffffffdc
+# DW_CFA_advance_loc: 1 to ffffffffffffffd1
+# DW_CFA_def_cfa_offset: 16
+# DW_CFA_offset: r6 (rbp) at cfa-16
+# DW_CFA_advance_loc: 3 to ffffffffffffffd4
+# DW_CFA_def_cfa_register: r6 (rbp)
+# DW_CFA_nop
+# DW_CFA_nop
+# DW_CFA_nop
+# DW_CFA_nop
+# DW_CFA_nop
+# DW_CFA_nop
+# DW_CFA_nop
+ - Name: .debug_frame
+ Type: SHT_PROGBITS
+ AddressAlign: 0x0000000000000008
+ Content: 14000000FFFFFFFF03000178100C070890010000000000001C0000000000000070020000000000000C00000000000000410E108602430D0614000000FFFFFFFF040008000178100C07089001000000001C0000003800000080020000000000000C00000000000000410E108602430D06
+#00000000 0000000000000014 ffffffff CIE
+# Version: 3
+# Augmentation: ""
+# Code alignment factor: 1
+# Data alignment factor: -8
+# Return address column: 16
+#
+# DW_CFA_def_cfa: r7 (rsp) ofs 8
+# DW_CFA_offset: r16 (rip) at cfa-8
+# DW_CFA_nop
+# DW_CFA_nop
+# DW_CFA_nop
+# DW_CFA_nop
+# DW_CFA_nop
+# DW_CFA_nop
+#
+#00000018 000000000000001c 00000000 FDE cie=00000000 pc=0000000000000270..000000000000027c
+# DW_CFA_advance_loc: 1 to 0000000000000271
+# DW_CFA_def_cfa_offset: 16
+# DW_CFA_offset: r6 (rbp) at cfa-16
+# DW_CFA_advance_loc: 3 to 0000000000000274
+# DW_CFA_def_cfa_register: r6 (rbp)
+#
+#00000038 0000000000000014 ffffffff CIE
+# Version: 4
+# Augmentation: ""
+# Pointer Size: 8
+# Segment Size: 0
+# Code alignment factor: 1
+# Data alignment factor: -8
+# Return address column: 16
+#
+# DW_CFA_def_cfa: r7 (rsp) ofs 8
+# DW_CFA_offset: r16 (rip) at cfa-8
+# DW_CFA_nop
+# DW_CFA_nop
+# DW_CFA_nop
+# DW_CFA_nop
+#
+#00000050 000000000000001c 00000038 FDE cie=00000038 pc=0000000000000280..000000000000028c
+# DW_CFA_advance_loc: 1 to 0000000000000281
+# DW_CFA_def_cfa_offset: 16
+# DW_CFA_offset: r6 (rbp) at cfa-16
+# DW_CFA_advance_loc: 3 to 0000000000000284
+# DW_CFA_def_cfa_register: r6 (rbp)
+Symbols:
+ Global:
+ - Name: eh_frame
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x0000000000000260
+ Size: 0x000000000000000C
+ - Name: debug_frame3
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x0000000000000270
+ Size: 0x000000000000000C
+ - Name: debug_frame4
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x0000000000000280
+ Size: 0x000000000000000C
+...
diff --git a/unittests/Symbol/TestDWARFCallFrameInfo.cpp b/unittests/Symbol/TestDWARFCallFrameInfo.cpp
new file mode 100644
index 0000000000000..40e3aac5fb378
--- /dev/null
+++ b/unittests/Symbol/TestDWARFCallFrameInfo.cpp
@@ -0,0 +1,142 @@
+//===-- TestDWARFCallFrameInfo.cpp ------------------------------*- C++ -*-===//
+//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
+#include "Plugins/Process/Utility/RegisterContext_x86.h"
+#include "lldb/Core/Module.h"
+#include "lldb/Core/ModuleSpec.h"
+#include "lldb/Core/Section.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Symbol/DWARFCallFrameInfo.h"
+#include "lldb/Utility/StreamString.h"
+#include "unittests/Utility/Helpers/TestUtilities.h"
+#include "llvm/Support/FileUtilities.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Program.h"
+#include "llvm/Support/raw_ostream.h"
+#include "gtest/gtest.h"
+
+using namespace lldb_private;
+using namespace lldb;
+
+class DWARFCallFrameInfoTest : public testing::Test {
+public:
+ void SetUp() override {
+ HostInfo::Initialize();
+ ObjectFileELF::Initialize();
+ }
+
+ void TearDown() override {
+ ObjectFileELF::Terminate();
+ HostInfo::Terminate();
+ }
+
+protected:
+ void TestBasic(DWARFCallFrameInfo::Type type, llvm::StringRef symbol);
+};
+
+#define ASSERT_NO_ERROR(x) \
+ if (std::error_code ASSERT_NO_ERROR_ec = x) { \
+ llvm::SmallString<128> MessageStorage; \
+ llvm::raw_svector_ostream Message(MessageStorage); \
+ Message << #x ": did not return errc::success.\n" \
+ << "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \
+ << "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \
+ GTEST_FATAL_FAILURE_(MessageStorage.c_str()); \
+ } else { \
+ }
+
+namespace lldb_private {
+static std::ostream &operator<<(std::ostream &OS, const UnwindPlan::Row &row) {
+ StreamString SS;
+ row.Dump(SS, nullptr, nullptr, 0);
+ return OS << SS.GetData();
+}
+} // namespace lldb_private
+
+static UnwindPlan::Row GetExpectedRow0() {
+ UnwindPlan::Row row;
+ row.SetOffset(0);
+ row.GetCFAValue().SetIsRegisterPlusOffset(dwarf_rsp_x86_64, 8);
+ row.SetRegisterLocationToAtCFAPlusOffset(dwarf_rip_x86_64, -8, false);
+ return row;
+}
+
+static UnwindPlan::Row GetExpectedRow1() {
+ UnwindPlan::Row row;
+ row.SetOffset(1);
+ row.GetCFAValue().SetIsRegisterPlusOffset(dwarf_rsp_x86_64, 16);
+ row.SetRegisterLocationToAtCFAPlusOffset(dwarf_rip_x86_64, -8, false);
+ row.SetRegisterLocationToAtCFAPlusOffset(dwarf_rbp_x86_64, -16, false);
+ return row;
+}
+
+static UnwindPlan::Row GetExpectedRow2() {
+ UnwindPlan::Row row;
+ row.SetOffset(4);
+ row.GetCFAValue().SetIsRegisterPlusOffset(dwarf_rbp_x86_64, 16);
+ row.SetRegisterLocationToAtCFAPlusOffset(dwarf_rip_x86_64, -8, false);
+ row.SetRegisterLocationToAtCFAPlusOffset(dwarf_rbp_x86_64, -16, false);
+ return row;
+}
+
+void DWARFCallFrameInfoTest::TestBasic(DWARFCallFrameInfo::Type type,
+ llvm::StringRef symbol) {
+ std::string yaml = GetInputFilePath("basic-call-frame-info.yaml");
+ llvm::SmallString<128> obj;
+
+ ASSERT_NO_ERROR(llvm::sys::fs::createTemporaryFile(
+ "basic-call-frame-info-%%%%%%", "obj", obj));
+ llvm::FileRemover obj_remover(obj);
+
+ const char *args[] = {YAML2OBJ, yaml.c_str(), nullptr};
+ llvm::StringRef obj_ref = obj;
+ const llvm::StringRef *redirects[] = {nullptr, &obj_ref, nullptr};
+ ASSERT_EQ(0, llvm::sys::ExecuteAndWait(YAML2OBJ, args, nullptr, redirects));
+
+ uint64_t size;
+ ASSERT_NO_ERROR(llvm::sys::fs::file_size(obj, size));
+ ASSERT_GT(size, 0u);
+
+ auto module_sp = std::make_shared<Module>(ModuleSpec(FileSpec(obj, false)));
+ SectionList *list = module_sp->GetSectionList();
+ ASSERT_NE(nullptr, list);
+
+ auto section_sp = list->FindSectionByType(type == DWARFCallFrameInfo::EH
+ ? eSectionTypeEHFrame
+ : eSectionTypeDWARFDebugFrame,
+ false);
+ ASSERT_NE(nullptr, section_sp);
+
+ DWARFCallFrameInfo cfi(*module_sp->GetObjectFile(), section_sp, type);
+
+ const Symbol *sym = module_sp->FindFirstSymbolWithNameAndType(
+ ConstString(symbol), eSymbolTypeAny);
+ ASSERT_NE(nullptr, sym);
+
+ UnwindPlan plan(eRegisterKindGeneric);
+ ASSERT_TRUE(cfi.GetUnwindPlan(sym->GetAddress(), plan));
+ ASSERT_EQ(3, plan.GetRowCount());
+ EXPECT_EQ(GetExpectedRow0(), *plan.GetRowAtIndex(0));
+ EXPECT_EQ(GetExpectedRow1(), *plan.GetRowAtIndex(1));
+ EXPECT_EQ(GetExpectedRow2(), *plan.GetRowAtIndex(2));
+}
+
+TEST_F(DWARFCallFrameInfoTest, Basic_dwarf3) {
+ TestBasic(DWARFCallFrameInfo::DWARF, "debug_frame3");
+}
+
+TEST_F(DWARFCallFrameInfoTest, Basic_dwarf4) {
+ TestBasic(DWARFCallFrameInfo::DWARF, "debug_frame4");
+}
+
+TEST_F(DWARFCallFrameInfoTest, Basic_eh) {
+ TestBasic(DWARFCallFrameInfo::EH, "eh_frame");
+}
diff --git a/unittests/SymbolFile/DWARF/CMakeLists.txt b/unittests/SymbolFile/DWARF/CMakeLists.txt
index c764bd477fab6..b2ece4eeaed73 100644
--- a/unittests/SymbolFile/DWARF/CMakeLists.txt
+++ b/unittests/SymbolFile/DWARF/CMakeLists.txt
@@ -8,6 +8,7 @@ add_lldb_unittest(SymbolFileDWARFTests
lldbPluginObjectFilePECOFF
lldbPluginSymbolFileDWARF
lldbPluginSymbolFilePDB
+ lldbUtilityHelpers
LINK_COMPONENTS
Support
DebugInfoPDB
diff --git a/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp b/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
index 8ef6ad05bd540..298bed10f3f81 100644
--- a/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
+++ b/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
@@ -15,6 +15,9 @@
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
+#include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
+#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
+#include "Plugins/SymbolFile/PDB/SymbolFilePDB.h"
#include "lldb/Core/Address.h"
#include "lldb/Core/ArchSpec.h"
#include "lldb/Core/Module.h"
@@ -25,12 +28,7 @@
#include "lldb/Symbol/LineTable.h"
#include "lldb/Symbol/SymbolVendor.h"
#include "lldb/Utility/FileSpec.h"
-
-#include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
-#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
-#include "Plugins/SymbolFile/PDB/SymbolFilePDB.h"
-
-extern const char *TestMainArgv0;
+#include "unittests/Utility/Helpers/TestUtilities.h"
using namespace lldb_private;
@@ -46,12 +44,7 @@ public:
ClangASTContext::Initialize();
SymbolFilePDB::Initialize();
- llvm::StringRef exe_folder = llvm::sys::path::parent_path(TestMainArgv0);
- llvm::SmallString<128> inputs_folder = exe_folder;
- llvm::sys::path::append(inputs_folder, "Inputs");
-
- m_dwarf_test_exe = inputs_folder;
- llvm::sys::path::append(m_dwarf_test_exe, "test-dwarf.exe");
+ m_dwarf_test_exe = GetInputFilePath("test-dwarf.exe");
}
void TearDown() override {
@@ -63,12 +56,12 @@ public:
}
protected:
- llvm::SmallString<128> m_dwarf_test_exe;
+ std::string m_dwarf_test_exe;
};
TEST_F(SymbolFileDWARFTests, TestAbilitiesForDWARF) {
// Test that when we have Dwarf debug info, SymbolFileDWARF is used.
- FileSpec fspec(m_dwarf_test_exe.c_str(), false);
+ FileSpec fspec(m_dwarf_test_exe, false);
ArchSpec aspec("i686-pc-windows");
lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec);
diff --git a/unittests/SymbolFile/PDB/CMakeLists.txt b/unittests/SymbolFile/PDB/CMakeLists.txt
index d9aff4e2eaca4..dd7e2248aed42 100644
--- a/unittests/SymbolFile/PDB/CMakeLists.txt
+++ b/unittests/SymbolFile/PDB/CMakeLists.txt
@@ -8,6 +8,7 @@ add_lldb_unittest(SymbolFilePDBTests
lldbPluginObjectFilePECOFF
lldbPluginSymbolFileDWARF
lldbPluginSymbolFilePDB
+ lldbUtilityHelpers
LINK_COMPONENTS
Support
DebugInfoPDB
diff --git a/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp b/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp
index 226057f893699..0e63a4104234c 100644
--- a/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp
+++ b/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp
@@ -15,6 +15,9 @@
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
+#include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
+#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
+#include "Plugins/SymbolFile/PDB/SymbolFilePDB.h"
#include "lldb/Core/Address.h"
#include "lldb/Core/ArchSpec.h"
#include "lldb/Core/Module.h"
@@ -25,10 +28,7 @@
#include "lldb/Symbol/LineTable.h"
#include "lldb/Symbol/SymbolVendor.h"
#include "lldb/Utility/FileSpec.h"
-
-#include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
-#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
-#include "Plugins/SymbolFile/PDB/SymbolFilePDB.h"
+#include "unittests/Utility/Helpers/TestUtilities.h"
#if defined(_MSC_VER)
#include "lldb/Host/windows/windows.h"
@@ -37,8 +37,6 @@
#include <algorithm>
-extern const char *TestMainArgv0;
-
using namespace lldb_private;
class SymbolFilePDBTests : public testing::Test {
@@ -57,14 +55,8 @@ public:
ClangASTContext::Initialize();
SymbolFilePDB::Initialize();
- llvm::StringRef exe_folder = llvm::sys::path::parent_path(TestMainArgv0);
- llvm::SmallString<128> inputs_folder = exe_folder;
- llvm::sys::path::append(inputs_folder, "Inputs");
-
- m_pdb_test_exe = inputs_folder;
- m_types_test_exe = inputs_folder;
- llvm::sys::path::append(m_pdb_test_exe, "test-pdb.exe");
- llvm::sys::path::append(m_types_test_exe, "test-pdb-types.exe");
+ m_pdb_test_exe = GetInputFilePath("test-pdb.exe");
+ m_types_test_exe = GetInputFilePath("test-pdb-types.exe");
}
void TearDown() override {
@@ -80,8 +72,8 @@ public:
}
protected:
- llvm::SmallString<128> m_pdb_test_exe;
- llvm::SmallString<128> m_types_test_exe;
+ std::string m_pdb_test_exe;
+ std::string m_types_test_exe;
bool FileSpecMatchesAsBaseOrFull(const FileSpec &left,
const FileSpec &right) const {
diff --git a/unittests/Target/CMakeLists.txt b/unittests/Target/CMakeLists.txt
index e4f6e52b06346..ec8f2db2c39f9 100644
--- a/unittests/Target/CMakeLists.txt
+++ b/unittests/Target/CMakeLists.txt
@@ -8,6 +8,7 @@ add_lldb_unittest(TargetTests
lldbSymbol
lldbUtility
lldbPluginObjectFileELF
+ lldbUtilityHelpers
LINK_COMPONENTS
Support
)
diff --git a/unittests/Target/ModuleCacheTest.cpp b/unittests/Target/ModuleCacheTest.cpp
index 8914f8b5eac40..122d789daf570 100644
--- a/unittests/Target/ModuleCacheTest.cpp
+++ b/unittests/Target/ModuleCacheTest.cpp
@@ -10,8 +10,7 @@
#include "lldb/Host/HostInfo.h"
#include "lldb/Symbol/SymbolContext.h"
#include "lldb/Target/ModuleCache.h"
-
-extern const char *TestMainArgv0;
+#include "unittests/Utility/Helpers/TestUtilities.h"
using namespace lldb_private;
using namespace lldb;
@@ -26,7 +25,7 @@ public:
protected:
static FileSpec s_cache_dir;
- static llvm::SmallString<128> s_test_executable;
+ static std::string s_test_executable;
void TryGetAndPut(const FileSpec &cache_dir, const char *hostname,
bool expect_download);
@@ -34,7 +33,7 @@ protected:
}
FileSpec ModuleCacheTest::s_cache_dir;
-llvm::SmallString<128> ModuleCacheTest::s_test_executable;
+std::string ModuleCacheTest::s_test_executable;
static const char dummy_hostname[] = "dummy_hostname";
static const char dummy_remote_dir[] = "bin";
@@ -71,10 +70,7 @@ void ModuleCacheTest::SetUpTestCase() {
FileSpec tmpdir_spec;
HostInfo::GetLLDBPath(lldb::ePathTypeLLDBTempSystemDir, s_cache_dir);
-
- llvm::StringRef exe_folder = llvm::sys::path::parent_path(TestMainArgv0);
- s_test_executable = exe_folder;
- llvm::sys::path::append(s_test_executable, "Inputs", module_name);
+ s_test_executable = GetInputFilePath(module_name);
}
void ModuleCacheTest::TearDownTestCase() {
diff --git a/unittests/UnwindAssembly/x86/Testx86AssemblyInspectionEngine.cpp b/unittests/UnwindAssembly/x86/Testx86AssemblyInspectionEngine.cpp
index e216d4be16fd7..e977609671970 100644
--- a/unittests/UnwindAssembly/x86/Testx86AssemblyInspectionEngine.cpp
+++ b/unittests/UnwindAssembly/x86/Testx86AssemblyInspectionEngine.cpp
@@ -18,6 +18,7 @@
#include "lldb/Core/AddressRange.h"
#include "lldb/Core/ArchSpec.h"
#include "lldb/Symbol/UnwindPlan.h"
+#include "lldb/Utility/StreamString.h"
#include "llvm/Support/TargetSelect.h"
@@ -130,6 +131,15 @@ std::unique_ptr<x86AssemblyInspectionEngine> Geti386Inspector() {
return engine;
}
+namespace lldb_private {
+static std::ostream &operator<<(std::ostream &OS,
+ const UnwindPlan::Row::CFAValue &CFA) {
+ StreamString S;
+ CFA.Dump(S, nullptr, nullptr);
+ return OS << S.GetData();
+}
+} // namespace lldb_private
+
TEST_F(Testx86AssemblyInspectionEngine, TestSimple64bitFrameFunction) {
std::unique_ptr<x86AssemblyInspectionEngine> engine = Getx86_64Inspector();
@@ -2337,3 +2347,71 @@ TEST_F(Testx86AssemblyInspectionEngine, Test32BitOnlyInstruction) {
EXPECT_FALSE(row_sp->GetRegisterInfo(k_rbp, regloc));
}
+
+TEST_F(Testx86AssemblyInspectionEngine, TestStackRealign8BitDisp_i386) {
+ std::unique_ptr<x86AssemblyInspectionEngine> engine = Geti386Inspector();
+
+ uint8_t data[] = {
+ 0x55, // pushl %ebp
+ 0x89, 0xe5, // movl %esp, %ebp
+ 0x53, // pushl %ebx
+ 0x83, 0xe4, 0xf0, // andl $-16, %esp
+ 0x83, 0xec, 0x10, // subl $16, %esp
+ 0x8d, 0x65, 0xfc, // leal -4(%ebp), %esp
+ 0x5b, // popl %ebx
+ 0x5d, // popl %ebp
+ 0xc3, // retl
+ };
+
+ AddressRange sample_range(0x1000, sizeof(data));
+ UnwindPlan plan(eRegisterKindLLDB);
+ ASSERT_TRUE(engine->GetNonCallSiteUnwindPlanFromAssembly(data, sizeof(data),
+ sample_range, plan));
+
+ UnwindPlan::Row::CFAValue esp_plus_4, esp_plus_8, ebp_plus_8;
+ esp_plus_4.SetIsRegisterPlusOffset(k_esp, 4);
+ esp_plus_8.SetIsRegisterPlusOffset(k_esp, 8);
+ ebp_plus_8.SetIsRegisterPlusOffset(k_ebp, 8);
+
+ EXPECT_EQ(esp_plus_4, plan.GetRowForFunctionOffset(0)->GetCFAValue());
+ EXPECT_EQ(esp_plus_8, plan.GetRowForFunctionOffset(1)->GetCFAValue());
+ for (size_t i = 3; i < sizeof(data) - 2; ++i)
+ EXPECT_EQ(ebp_plus_8, plan.GetRowForFunctionOffset(i)->GetCFAValue())
+ << "i: " << i;
+ EXPECT_EQ(esp_plus_4,
+ plan.GetRowForFunctionOffset(sizeof(data) - 1)->GetCFAValue());
+}
+
+TEST_F(Testx86AssemblyInspectionEngine, TestStackRealign32BitDisp_x86_64) {
+ std::unique_ptr<x86AssemblyInspectionEngine> engine = Getx86_64Inspector();
+
+ uint8_t data[] = {
+ 0x55, // pushq %rbp
+ 0x48, 0x89, 0xe5, // movq %rsp, %rbp
+ 0x53, // pushl %rbx
+ 0x48, 0x83, 0xe4, 0xf0, // andq $-16, %rsp
+ 0x48, 0x81, 0xec, 0x00, 0x01, 0x00, 0x00, // subq $256, %rsp
+ 0x48, 0x8d, 0x65, 0xf8, // leaq -8(%rbp), %rsp
+ 0x5b, // popq %rbx
+ 0x5d, // popq %rbp
+ 0xc3, // retq
+ };
+
+ AddressRange sample_range(0x1000, sizeof(data));
+ UnwindPlan plan(eRegisterKindLLDB);
+ ASSERT_TRUE(engine->GetNonCallSiteUnwindPlanFromAssembly(data, sizeof(data),
+ sample_range, plan));
+
+ UnwindPlan::Row::CFAValue rsp_plus_8, rsp_plus_16, rbp_plus_16;
+ rsp_plus_8.SetIsRegisterPlusOffset(k_rsp, 8);
+ rsp_plus_16.SetIsRegisterPlusOffset(k_rsp, 16);
+ rbp_plus_16.SetIsRegisterPlusOffset(k_rbp, 16);
+
+ EXPECT_EQ(rsp_plus_8, plan.GetRowForFunctionOffset(0)->GetCFAValue());
+ EXPECT_EQ(rsp_plus_16, plan.GetRowForFunctionOffset(1)->GetCFAValue());
+ for (size_t i = 4; i < sizeof(data) - 2; ++i)
+ EXPECT_EQ(rbp_plus_16, plan.GetRowForFunctionOffset(i)->GetCFAValue())
+ << "i: " << i;
+ EXPECT_EQ(rsp_plus_8,
+ plan.GetRowForFunctionOffset(sizeof(data) - 1)->GetCFAValue());
+}
diff --git a/unittests/Utility/CMakeLists.txt b/unittests/Utility/CMakeLists.txt
index 86ac3c46d7746..91cdbbda3ec37 100644
--- a/unittests/Utility/CMakeLists.txt
+++ b/unittests/Utility/CMakeLists.txt
@@ -1,4 +1,4 @@
-add_subdirectory(Mocks)
+add_subdirectory(Helpers)
add_lldb_unittest(UtilityTests
ConstStringTest.cpp
@@ -6,15 +6,21 @@ add_lldb_unittest(UtilityTests
NameMatchesTest.cpp
StatusTest.cpp
StringExtractorTest.cpp
+ StructuredDataTest.cpp
TaskPoolTest.cpp
TildeExpressionResolverTest.cpp
TimeoutTest.cpp
+ TimerTest.cpp
UriParserTest.cpp
VASprintfTest.cpp
LINK_LIBS
lldbUtility
- lldbUtilityMocks
+ lldbUtilityHelpers
LINK_COMPONENTS
Support
)
+
+add_unittest_inputs(UtilityTests
+ StructuredData-basic.json
+ )
diff --git a/unittests/Utility/Mocks/CMakeLists.txt b/unittests/Utility/Helpers/CMakeLists.txt
index 57db5bf3b628e..36c774cb68265 100644
--- a/unittests/Utility/Mocks/CMakeLists.txt
+++ b/unittests/Utility/Helpers/CMakeLists.txt
@@ -1,5 +1,7 @@
-add_lldb_library(lldbUtilityMocks
+set(EXCLUDE_FROM_ALL ON)
+add_lldb_library(lldbUtilityHelpers
MockTildeExpressionResolver.cpp
+ TestUtilities.cpp
LINK_LIBS
lldbUtility
diff --git a/unittests/Utility/Mocks/MockTildeExpressionResolver.cpp b/unittests/Utility/Helpers/MockTildeExpressionResolver.cpp
index 832836682b500..832836682b500 100644
--- a/unittests/Utility/Mocks/MockTildeExpressionResolver.cpp
+++ b/unittests/Utility/Helpers/MockTildeExpressionResolver.cpp
diff --git a/unittests/Utility/Mocks/MockTildeExpressionResolver.h b/unittests/Utility/Helpers/MockTildeExpressionResolver.h
index 7ae5623f839a5..18be1102e1fd4 100644
--- a/unittests/Utility/Mocks/MockTildeExpressionResolver.h
+++ b/unittests/Utility/Helpers/MockTildeExpressionResolver.h
@@ -32,6 +32,6 @@ public:
llvm::SmallVectorImpl<char> &Output) override;
bool ResolvePartial(llvm::StringRef Expr, llvm::StringSet<> &Output) override;
};
-}
+} // namespace lldb_private
#endif
diff --git a/unittests/Utility/Helpers/TestUtilities.cpp b/unittests/Utility/Helpers/TestUtilities.cpp
new file mode 100644
index 0000000000000..eacf876614207
--- /dev/null
+++ b/unittests/Utility/Helpers/TestUtilities.cpp
@@ -0,0 +1,22 @@
+//===- TestUtilities.cpp ----------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "TestUtilities.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
+
+extern const char *TestMainArgv0;
+
+std::string lldb_private::GetInputFilePath(const llvm::Twine &name) {
+ llvm::SmallString<128> result = llvm::sys::path::parent_path(TestMainArgv0);
+ llvm::sys::fs::make_absolute(result);
+ llvm::sys::path::append(result, "Inputs", name);
+ return result.str();
+}
diff --git a/unittests/Utility/Helpers/TestUtilities.h b/unittests/Utility/Helpers/TestUtilities.h
new file mode 100644
index 0000000000000..8d848797b7b2e
--- /dev/null
+++ b/unittests/Utility/Helpers/TestUtilities.h
@@ -0,0 +1,20 @@
+//===- TestUtilities.h ------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_UNITTESTS_UTILITY_HELPERS_TESTUTILITIES_H
+#define LLDB_UNITTESTS_UTILITY_HELPERS_TESTUTILITIES_H
+
+#include "llvm/ADT/Twine.h"
+#include <string>
+
+namespace lldb_private {
+std::string GetInputFilePath(const llvm::Twine &name);
+}
+
+#endif
diff --git a/unittests/Utility/Inputs/StructuredData-basic.json b/unittests/Utility/Inputs/StructuredData-basic.json
new file mode 100644
index 0000000000000..b5d8bb58d9bc3
--- /dev/null
+++ b/unittests/Utility/Inputs/StructuredData-basic.json
@@ -0,0 +1 @@
+[1, 2, 3]
diff --git a/unittests/Utility/StructuredDataTest.cpp b/unittests/Utility/StructuredDataTest.cpp
new file mode 100644
index 0000000000000..f346dd9e83223
--- /dev/null
+++ b/unittests/Utility/StructuredDataTest.cpp
@@ -0,0 +1,48 @@
+//===-- 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 "Helpers/TestUtilities.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/Utility/StreamString.h"
+#include "lldb/Utility/StructuredData.h"
+#include "llvm/Support/Path.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+TEST(StructuredDataTest, StringDump) {
+ std::pair<llvm::StringRef, llvm::StringRef> 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());
+ }
+}
+
+TEST(StructuredDataTest, ParseJSONFromFile) {
+ Status status;
+ auto object_sp = StructuredData::ParseJSONFromFile(
+ FileSpec("non-existing-file.json", false), status);
+ EXPECT_EQ(nullptr, object_sp);
+
+ std::string input = GetInputFilePath("StructuredData-basic.json");
+ object_sp = StructuredData::ParseJSONFromFile(FileSpec(input, false), status);
+ ASSERT_NE(nullptr, object_sp);
+
+ StreamString S;
+ object_sp->Dump(S, false);
+ EXPECT_EQ("[1,2,3]", S.GetString());
+}
diff --git a/unittests/Utility/TildeExpressionResolverTest.cpp b/unittests/Utility/TildeExpressionResolverTest.cpp
index fd953390ed5d4..a24e998cb81da 100644
--- a/unittests/Utility/TildeExpressionResolverTest.cpp
+++ b/unittests/Utility/TildeExpressionResolverTest.cpp
@@ -1,6 +1,6 @@
#include "gtest/gtest.h"
-#include "Mocks/MockTildeExpressionResolver.h"
+#include "Helpers/MockTildeExpressionResolver.h"
#include "lldb/Utility/TildeExpressionResolver.h"
#include "llvm/ADT/SmallString.h"
diff --git a/unittests/Core/TimerTest.cpp b/unittests/Utility/TimerTest.cpp
index a35df0d49c8e3..04b715915bff4 100644
--- a/unittests/Core/TimerTest.cpp
+++ b/unittests/Utility/TimerTest.cpp
@@ -7,10 +7,9 @@
//
//===----------------------------------------------------------------------===//
-#include "lldb/Core/Timer.h"
-#include "gtest/gtest.h"
-
#include "lldb/Utility/StreamString.h"
+#include "lldb/Utility/Timer.h"
+#include "gtest/gtest.h"
#include <thread>
using namespace lldb_private;
diff --git a/unittests/tools/lldb-server/tests/MessageObjects.cpp b/unittests/tools/lldb-server/tests/MessageObjects.cpp
index fd44bf6b23a97..9fcb4207675aa 100644
--- a/unittests/tools/lldb-server/tests/MessageObjects.cpp
+++ b/unittests/tools/lldb-server/tests/MessageObjects.cpp
@@ -8,7 +8,7 @@
//===----------------------------------------------------------------------===//
#include "MessageObjects.h"
-#include "lldb/Core/StructuredData.h"
+#include "lldb/Utility/StructuredData.h"
#include "llvm/ADT/StringExtras.h"
#include "gtest/gtest.h"