diff options
author | 2020-08-03 14:33:06 +0000 | |
---|---|---|
committer | 2020-08-03 14:33:06 +0000 | |
commit | 061da546b983eb767bad15e67af1174fb0bcf31c (patch) | |
tree | 83c78b820819d70aa40c36d90447978b300078c5 /gnu/llvm/lldb/unittests/Process/minidump | |
parent | Import LLVM 10.0.0 release including clang, lld and lldb. (diff) | |
download | wireguard-openbsd-061da546b983eb767bad15e67af1174fb0bcf31c.tar.xz wireguard-openbsd-061da546b983eb767bad15e67af1174fb0bcf31c.zip |
Import LLVM 10.0.0 release including clang, lld and lldb.
ok hackroom
tested by plenty
Diffstat (limited to 'gnu/llvm/lldb/unittests/Process/minidump')
-rw-r--r-- | gnu/llvm/lldb/unittests/Process/minidump/CMakeLists.txt | 25 | ||||
-rw-r--r-- | gnu/llvm/lldb/unittests/Process/minidump/Inputs/fizzbuzz_no_heap.dmp | bin | 0 -> 6297 bytes | |||
-rw-r--r-- | gnu/llvm/lldb/unittests/Process/minidump/Inputs/fizzbuzz_wow64.dmp | bin | 0 -> 9280561 bytes | |||
-rw-r--r-- | gnu/llvm/lldb/unittests/Process/minidump/Inputs/linux-x86_64.cpp | 28 | ||||
-rw-r--r-- | gnu/llvm/lldb/unittests/Process/minidump/Inputs/linux-x86_64.dmp | bin | 0 -> 38320 bytes | |||
-rw-r--r-- | gnu/llvm/lldb/unittests/Process/minidump/Inputs/regions-memlist64.dmp | bin | 0 -> 260 bytes | |||
-rw-r--r-- | gnu/llvm/lldb/unittests/Process/minidump/MinidumpParserTest.cpp | 724 | ||||
-rw-r--r-- | gnu/llvm/lldb/unittests/Process/minidump/RegisterContextMinidumpTest.cpp | 201 |
8 files changed, 978 insertions, 0 deletions
diff --git a/gnu/llvm/lldb/unittests/Process/minidump/CMakeLists.txt b/gnu/llvm/lldb/unittests/Process/minidump/CMakeLists.txt new file mode 100644 index 00000000000..ad5f1883147 --- /dev/null +++ b/gnu/llvm/lldb/unittests/Process/minidump/CMakeLists.txt @@ -0,0 +1,25 @@ +add_lldb_unittest(LLDBMinidumpTests + MinidumpParserTest.cpp + RegisterContextMinidumpTest.cpp + + LINK_LIBS + lldbCore + lldbHost + lldbTarget + lldbPluginProcessUtility + lldbPluginProcessMinidump + lldbUtilityHelpers + LLVMTestingSupport + LINK_COMPONENTS + ObjectYAML + Support + ) + +set(test_inputs + fizzbuzz_no_heap.dmp + fizzbuzz_wow64.dmp + linux-x86_64.dmp + regions-memlist64.dmp + ) + +add_unittest_inputs(LLDBMinidumpTests "${test_inputs}") diff --git a/gnu/llvm/lldb/unittests/Process/minidump/Inputs/fizzbuzz_no_heap.dmp b/gnu/llvm/lldb/unittests/Process/minidump/Inputs/fizzbuzz_no_heap.dmp Binary files differnew file mode 100644 index 00000000000..19008c91fc3 --- /dev/null +++ b/gnu/llvm/lldb/unittests/Process/minidump/Inputs/fizzbuzz_no_heap.dmp diff --git a/gnu/llvm/lldb/unittests/Process/minidump/Inputs/fizzbuzz_wow64.dmp b/gnu/llvm/lldb/unittests/Process/minidump/Inputs/fizzbuzz_wow64.dmp Binary files differnew file mode 100644 index 00000000000..3d97186f2cd --- /dev/null +++ b/gnu/llvm/lldb/unittests/Process/minidump/Inputs/fizzbuzz_wow64.dmp diff --git a/gnu/llvm/lldb/unittests/Process/minidump/Inputs/linux-x86_64.cpp b/gnu/llvm/lldb/unittests/Process/minidump/Inputs/linux-x86_64.cpp new file mode 100644 index 00000000000..827fe67b503 --- /dev/null +++ b/gnu/llvm/lldb/unittests/Process/minidump/Inputs/linux-x86_64.cpp @@ -0,0 +1,28 @@ +// Example source from breakpad's linux tutorial +// https://chromium.googlesource.com/breakpad/breakpad/+/master/docs/linux_starter_guide.md + +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> + +#include "client/linux/handler/exception_handler.h" + +static bool dumpCallback(const google_breakpad::MinidumpDescriptor &descriptor, + void *context, bool succeeded) { + printf("Dump path: %s\n", descriptor.path()); + return succeeded; +} + +void crash() { + volatile int *a = (int *)(NULL); + *a = 1; +} + +int main(int argc, char *argv[]) { + google_breakpad::MinidumpDescriptor descriptor("/tmp"); + google_breakpad::ExceptionHandler eh(descriptor, NULL, dumpCallback, NULL, + true, -1); + printf("pid: %d\n", getpid()); + crash(); + return 0; +} diff --git a/gnu/llvm/lldb/unittests/Process/minidump/Inputs/linux-x86_64.dmp b/gnu/llvm/lldb/unittests/Process/minidump/Inputs/linux-x86_64.dmp Binary files differnew file mode 100644 index 00000000000..29a12d6a2eb --- /dev/null +++ b/gnu/llvm/lldb/unittests/Process/minidump/Inputs/linux-x86_64.dmp diff --git a/gnu/llvm/lldb/unittests/Process/minidump/Inputs/regions-memlist64.dmp b/gnu/llvm/lldb/unittests/Process/minidump/Inputs/regions-memlist64.dmp Binary files differnew file mode 100644 index 00000000000..1bb8db8464d --- /dev/null +++ b/gnu/llvm/lldb/unittests/Process/minidump/Inputs/regions-memlist64.dmp diff --git a/gnu/llvm/lldb/unittests/Process/minidump/MinidumpParserTest.cpp b/gnu/llvm/lldb/unittests/Process/minidump/MinidumpParserTest.cpp new file mode 100644 index 00000000000..94bb1b395f0 --- /dev/null +++ b/gnu/llvm/lldb/unittests/Process/minidump/MinidumpParserTest.cpp @@ -0,0 +1,724 @@ +//===-- MinidumpTypesTest.cpp -----------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "Plugins/Process/minidump/MinidumpParser.h" +#include "Plugins/Process/minidump/MinidumpTypes.h" +#include "Plugins/Process/minidump/RegisterContextMinidump_x86_32.h" +#include "Plugins/Process/minidump/RegisterContextMinidump_x86_64.h" +#include "TestingSupport/SubsystemRAII.h" +#include "TestingSupport/TestUtilities.h" +#include "lldb/Host/FileSystem.h" +#include "lldb/Target/MemoryRegionInfo.h" +#include "lldb/Utility/ArchSpec.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/DataExtractor.h" +#include "lldb/Utility/FileSpec.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/Optional.h" +#include "llvm/ObjectYAML/yaml2obj.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/Path.h" +#include "llvm/Support/YAMLTraits.h" +#include "llvm/Testing/Support/Error.h" +#include "gtest/gtest.h" + +// C includes + +// C++ includes +#include <memory> + +using namespace lldb_private; +using namespace minidump; + +class MinidumpParserTest : public testing::Test { +public: + SubsystemRAII<FileSystem> subsystems; + + void SetUpData(const char *minidump_filename) { + std::string filename = GetInputFilePath(minidump_filename); + auto BufferPtr = FileSystem::Instance().CreateDataBuffer(filename, -1, 0); + ASSERT_NE(BufferPtr, nullptr); + llvm::Expected<MinidumpParser> expected_parser = + MinidumpParser::Create(BufferPtr); + ASSERT_THAT_EXPECTED(expected_parser, llvm::Succeeded()); + parser = std::move(*expected_parser); + ASSERT_GT(parser->GetData().size(), 0UL); + } + + llvm::Error SetUpFromYaml(llvm::StringRef yaml) { + std::string data; + llvm::raw_string_ostream os(data); + llvm::yaml::Input YIn(yaml); + if (!llvm::yaml::convertYAML(YIn, os, [](const llvm::Twine &Msg) {})) + return llvm::createStringError(llvm::inconvertibleErrorCode(), + "convertYAML() failed"); + + os.flush(); + auto data_buffer_sp = + std::make_shared<DataBufferHeap>(data.data(), data.size()); + auto expected_parser = MinidumpParser::Create(std::move(data_buffer_sp)); + if (!expected_parser) + return expected_parser.takeError(); + parser = std::move(*expected_parser); + return llvm::Error::success(); + } + + llvm::Optional<MinidumpParser> parser; +}; + +TEST_F(MinidumpParserTest, InvalidMinidump) { + std::string duplicate_streams; + llvm::raw_string_ostream os(duplicate_streams); + llvm::yaml::Input YIn(R"( +--- !minidump +Streams: + - Type: LinuxAuxv + Content: DEADBEEFBAADF00D + - Type: LinuxAuxv + Content: DEADBEEFBAADF00D + )"); + + ASSERT_TRUE(llvm::yaml::convertYAML(YIn, os, [](const llvm::Twine &Msg){})); + os.flush(); + auto data_buffer_sp = std::make_shared<DataBufferHeap>( + duplicate_streams.data(), duplicate_streams.size()); + ASSERT_THAT_EXPECTED(MinidumpParser::Create(data_buffer_sp), llvm::Failed()); +} + +TEST_F(MinidumpParserTest, GetThreadsAndGetThreadContext) { + ASSERT_THAT_ERROR(SetUpFromYaml(R"( +--- !minidump +Streams: + - Type: ThreadList + Threads: + - Thread Id: 0x00003E81 + Stack: + Start of Memory Range: 0x00007FFCEB34A000 + Content: C84D04BCE97F00 + Context: 00000000000000 +... +)"), + llvm::Succeeded()); + llvm::ArrayRef<minidump::Thread> thread_list; + + thread_list = parser->GetThreads(); + ASSERT_EQ(1UL, thread_list.size()); + + const minidump::Thread &thread = thread_list[0]; + + EXPECT_EQ(0x3e81u, thread.ThreadId); + + llvm::ArrayRef<uint8_t> context = parser->GetThreadContext(thread); + EXPECT_EQ(7u, context.size()); +} + +TEST_F(MinidumpParserTest, GetArchitecture) { + ASSERT_THAT_ERROR(SetUpFromYaml(R"( +--- !minidump +Streams: + - Type: SystemInfo + Processor Arch: AMD64 + Processor Level: 6 + Processor Revision: 16130 + Number of Processors: 1 + Platform ID: Linux + CPU: + Vendor ID: GenuineIntel + Version Info: 0x00000000 + Feature Info: 0x00000000 +... +)"), + llvm::Succeeded()); + ASSERT_EQ(llvm::Triple::ArchType::x86_64, + parser->GetArchitecture().GetMachine()); + ASSERT_EQ(llvm::Triple::OSType::Linux, + parser->GetArchitecture().GetTriple().getOS()); +} + +TEST_F(MinidumpParserTest, GetMiscInfo_no_stream) { + // Test that GetMiscInfo returns nullptr when the minidump does not contain + // this stream. + ASSERT_THAT_ERROR(SetUpFromYaml(R"( +--- !minidump +Streams: +... +)"), + llvm::Succeeded()); + EXPECT_EQ(nullptr, parser->GetMiscInfo()); +} + +TEST_F(MinidumpParserTest, GetLinuxProcStatus) { + ASSERT_THAT_ERROR(SetUpFromYaml(R"( +--- !minidump +Streams: + - Type: SystemInfo + Processor Arch: AMD64 + Processor Level: 6 + Processor Revision: 16130 + Number of Processors: 1 + Platform ID: Linux + CSD Version: 'Linux 3.13.0-91-generic' + CPU: + Vendor ID: GenuineIntel + Version Info: 0x00000000 + Feature Info: 0x00000000 + - Type: LinuxProcStatus + Text: | + Name: a.out + State: t (tracing stop) + Tgid: 16001 + Ngid: 0 + Pid: 16001 + PPid: 13243 + TracerPid: 16002 + Uid: 404696 404696 404696 404696 + Gid: 5762 5762 5762 5762 +... +)"), + llvm::Succeeded()); + llvm::Optional<LinuxProcStatus> proc_status = parser->GetLinuxProcStatus(); + ASSERT_TRUE(proc_status.hasValue()); + lldb::pid_t pid = proc_status->GetPid(); + ASSERT_EQ(16001UL, pid); +} + +TEST_F(MinidumpParserTest, GetPid) { + ASSERT_THAT_ERROR(SetUpFromYaml(R"( +--- !minidump +Streams: + - Type: SystemInfo + Processor Arch: AMD64 + Processor Level: 6 + Processor Revision: 16130 + Number of Processors: 1 + Platform ID: Linux + CSD Version: 'Linux 3.13.0-91-generic' + CPU: + Vendor ID: GenuineIntel + Version Info: 0x00000000 + Feature Info: 0x00000000 + - Type: LinuxProcStatus + Text: | + Name: a.out + State: t (tracing stop) + Tgid: 16001 + Ngid: 0 + Pid: 16001 + PPid: 13243 + TracerPid: 16002 + Uid: 404696 404696 404696 404696 + Gid: 5762 5762 5762 5762 +... +)"), + llvm::Succeeded()); + llvm::Optional<lldb::pid_t> pid = parser->GetPid(); + ASSERT_TRUE(pid.hasValue()); + ASSERT_EQ(16001UL, pid.getValue()); +} + +TEST_F(MinidumpParserTest, GetFilteredModuleList) { + ASSERT_THAT_ERROR(SetUpFromYaml(R"( +--- !minidump +Streams: + - Type: ModuleList + Modules: + - Base of Image: 0x0000000000400000 + Size of Image: 0x00001000 + Module Name: '/tmp/test/linux-x86_64_not_crashed' + CodeView Record: 4C4570426CCF3F60FFA7CC4B86AE8FF44DB2576A68983611 + - Base of Image: 0x0000000000600000 + Size of Image: 0x00002000 + Module Name: '/tmp/test/linux-x86_64_not_crashed' + CodeView Record: 4C4570426CCF3F60FFA7CC4B86AE8FF44DB2576A68983611 +... +)"), + llvm::Succeeded()); + llvm::ArrayRef<minidump::Module> modules = parser->GetModuleList(); + std::vector<const minidump::Module *> filtered_modules = + parser->GetFilteredModuleList(); + EXPECT_EQ(2u, modules.size()); + ASSERT_EQ(1u, filtered_modules.size()); + const minidump::Module &M = *filtered_modules[0]; + EXPECT_THAT_EXPECTED(parser->GetMinidumpFile().getString(M.ModuleNameRVA), + llvm::HasValue("/tmp/test/linux-x86_64_not_crashed")); +} + +TEST_F(MinidumpParserTest, GetExceptionStream) { + SetUpData("linux-x86_64.dmp"); + const llvm::minidump::ExceptionStream *exception_stream = + parser->GetExceptionStream(); + ASSERT_NE(nullptr, exception_stream); + ASSERT_EQ(11UL, exception_stream->ExceptionRecord.ExceptionCode); +} + +void check_mem_range_exists(MinidumpParser &parser, const uint64_t range_start, + const uint64_t range_size) { + llvm::Optional<minidump::Range> range = parser.FindMemoryRange(range_start); + ASSERT_TRUE(range.hasValue()) << "There is no range containing this address"; + EXPECT_EQ(range_start, range->start); + EXPECT_EQ(range_start + range_size, range->start + range->range_ref.size()); +} + +TEST_F(MinidumpParserTest, FindMemoryRange) { + ASSERT_THAT_ERROR(SetUpFromYaml(R"( +--- !minidump +Streams: + - Type: MemoryList + Memory Ranges: + - Start of Memory Range: 0x00007FFCEB34A000 + Content: C84D04BCE9 + - Start of Memory Range: 0x0000000000401D46 + Content: 5421 +... +)"), + llvm::Succeeded()); + EXPECT_EQ(llvm::None, parser->FindMemoryRange(0x00)); + EXPECT_EQ(llvm::None, parser->FindMemoryRange(0x2a)); + EXPECT_EQ((minidump::Range{0x401d46, llvm::ArrayRef<uint8_t>{0x54, 0x21}}), + parser->FindMemoryRange(0x401d46)); + EXPECT_EQ(llvm::None, parser->FindMemoryRange(0x401d46 + 2)); + + EXPECT_EQ( + (minidump::Range{0x7ffceb34a000, + llvm::ArrayRef<uint8_t>{0xc8, 0x4d, 0x04, 0xbc, 0xe9}}), + parser->FindMemoryRange(0x7ffceb34a000 + 2)); + EXPECT_EQ(llvm::None, parser->FindMemoryRange(0x7ffceb34a000 + 5)); +} + +TEST_F(MinidumpParserTest, GetMemory) { + ASSERT_THAT_ERROR(SetUpFromYaml(R"( +--- !minidump +Streams: + - Type: MemoryList + Memory Ranges: + - Start of Memory Range: 0x00007FFCEB34A000 + Content: C84D04BCE9 + - Start of Memory Range: 0x0000000000401D46 + Content: 5421 +... +)"), + llvm::Succeeded()); + + EXPECT_EQ((llvm::ArrayRef<uint8_t>{0x54}), parser->GetMemory(0x401d46, 1)); + EXPECT_EQ((llvm::ArrayRef<uint8_t>{0x54, 0x21}), + parser->GetMemory(0x401d46, 4)); + + EXPECT_EQ((llvm::ArrayRef<uint8_t>{0xc8, 0x4d, 0x04, 0xbc, 0xe9}), + parser->GetMemory(0x7ffceb34a000, 5)); + EXPECT_EQ((llvm::ArrayRef<uint8_t>{0xc8, 0x4d, 0x04}), + parser->GetMemory(0x7ffceb34a000, 3)); + + EXPECT_EQ(llvm::ArrayRef<uint8_t>(), parser->GetMemory(0x500000, 512)); +} + +TEST_F(MinidumpParserTest, FindMemoryRangeWithFullMemoryMinidump) { + SetUpData("fizzbuzz_wow64.dmp"); + + // There are a lot of ranges in the file, just testing with some of them + EXPECT_FALSE(parser->FindMemoryRange(0x00).hasValue()); + EXPECT_FALSE(parser->FindMemoryRange(0x2a).hasValue()); + check_mem_range_exists(*parser, 0x10000, 65536); // first range + check_mem_range_exists(*parser, 0x40000, 4096); + EXPECT_FALSE(parser->FindMemoryRange(0x40000 + 4096).hasValue()); + check_mem_range_exists(*parser, 0x77c12000, 8192); + check_mem_range_exists(*parser, 0x7ffe0000, 4096); // last range + EXPECT_FALSE(parser->FindMemoryRange(0x7ffe0000 + 4096).hasValue()); +} + +constexpr auto yes = MemoryRegionInfo::eYes; +constexpr auto no = MemoryRegionInfo::eNo; +constexpr auto unknown = MemoryRegionInfo::eDontKnow; + +TEST_F(MinidumpParserTest, GetMemoryRegionInfo) { + ASSERT_THAT_ERROR(SetUpFromYaml(R"( +--- !minidump +Streams: + - Type: MemoryInfoList + Memory Ranges: + - Base Address: 0x0000000000000000 + Allocation Protect: [ ] + Region Size: 0x0000000000010000 + State: [ MEM_FREE ] + Protect: [ PAGE_NO_ACCESS ] + Type: [ ] + - Base Address: 0x0000000000010000 + Allocation Protect: [ PAGE_READ_WRITE ] + Region Size: 0x0000000000021000 + State: [ MEM_COMMIT ] + Type: [ MEM_MAPPED ] + - Base Address: 0x0000000000040000 + Allocation Protect: [ PAGE_EXECUTE_WRITE_COPY ] + Region Size: 0x0000000000001000 + State: [ MEM_COMMIT ] + Protect: [ PAGE_READ_ONLY ] + Type: [ MEM_IMAGE ] + - Base Address: 0x000000007FFE0000 + Allocation Protect: [ PAGE_READ_ONLY ] + Region Size: 0x0000000000001000 + State: [ MEM_COMMIT ] + Type: [ MEM_PRIVATE ] + - Base Address: 0x000000007FFE1000 + Allocation Base: 0x000000007FFE0000 + Allocation Protect: [ PAGE_READ_ONLY ] + Region Size: 0x000000000000F000 + State: [ MEM_RESERVE ] + Protect: [ PAGE_NO_ACCESS ] + Type: [ MEM_PRIVATE ] +... +)"), + llvm::Succeeded()); + + EXPECT_THAT( + parser->BuildMemoryRegions(), + testing::Pair(testing::ElementsAre( + MemoryRegionInfo({0x0, 0x10000}, no, no, no, no, + ConstString(), unknown, 0), + MemoryRegionInfo({0x10000, 0x21000}, yes, yes, no, yes, + ConstString(), unknown, 0), + MemoryRegionInfo({0x40000, 0x1000}, yes, no, no, yes, + ConstString(), unknown, 0), + MemoryRegionInfo({0x7ffe0000, 0x1000}, yes, no, no, yes, + ConstString(), unknown, 0), + MemoryRegionInfo({0x7ffe1000, 0xf000}, no, no, no, yes, + ConstString(), unknown, 0)), + true)); +} + +TEST_F(MinidumpParserTest, GetMemoryRegionInfoFromMemoryList) { + ASSERT_THAT_ERROR(SetUpFromYaml(R"( +--- !minidump +Streams: + - Type: MemoryList + Memory Ranges: + - Start of Memory Range: 0x0000000000001000 + Content: '31313131313131313131313131313131' + - Start of Memory Range: 0x0000000000002000 + Content: '3333333333333333333333333333333333333333333333333333333333333333' +... +)"), + llvm::Succeeded()); + + // Test we can get memory regions from the MINIDUMP_MEMORY_LIST stream when + // we don't have a MemoryInfoListStream. + + EXPECT_THAT( + parser->BuildMemoryRegions(), + testing::Pair(testing::ElementsAre( + MemoryRegionInfo({0x1000, 0x10}, yes, unknown, unknown, + yes, ConstString(), unknown, 0), + MemoryRegionInfo({0x2000, 0x20}, yes, unknown, unknown, + yes, ConstString(), unknown, 0)), + false)); +} + +TEST_F(MinidumpParserTest, GetMemoryRegionInfoFromMemory64List) { + SetUpData("regions-memlist64.dmp"); + + // Test we can get memory regions from the MINIDUMP_MEMORY64_LIST stream when + // we don't have a MemoryInfoListStream. + EXPECT_THAT( + parser->BuildMemoryRegions(), + testing::Pair(testing::ElementsAre( + MemoryRegionInfo({0x1000, 0x10}, yes, unknown, unknown, + yes, ConstString(), unknown, 0), + MemoryRegionInfo({0x2000, 0x20}, yes, unknown, unknown, + yes, ConstString(), unknown, 0)), + false)); +} + +TEST_F(MinidumpParserTest, GetMemoryRegionInfoLinuxMaps) { + ASSERT_THAT_ERROR(SetUpFromYaml(R"( +--- !minidump +Streams: + - Type: LinuxMaps + Text: | + 400d9000-400db000 r-xp 00000000 b3:04 227 /system/bin/app_process + 400db000-400dc000 r--p 00001000 b3:04 227 /system/bin/app_process + 400dc000-400dd000 rw-p 00000000 00:00 0 + 400ec000-400ed000 r--p 00000000 00:00 0 + 400ee000-400ef000 rw-p 00010000 b3:04 300 /system/bin/linker + 400fc000-400fd000 rwxp 00001000 b3:04 1096 /system/lib/liblog.so + +... +)"), + llvm::Succeeded()); + // Test we can get memory regions from the linux /proc/<pid>/maps stream when + // we don't have a MemoryInfoListStream. + ConstString app_process("/system/bin/app_process"); + ConstString linker("/system/bin/linker"); + ConstString liblog("/system/lib/liblog.so"); + EXPECT_THAT( + parser->BuildMemoryRegions(), + testing::Pair(testing::ElementsAre( + MemoryRegionInfo({0x400d9000, 0x2000}, yes, no, yes, + yes, app_process, unknown, 0), + MemoryRegionInfo({0x400db000, 0x1000}, yes, no, no, yes, + app_process, unknown, 0), + MemoryRegionInfo({0x400dc000, 0x1000}, yes, yes, no, + yes, ConstString(), unknown, 0), + MemoryRegionInfo({0x400ec000, 0x1000}, yes, no, no, yes, + ConstString(), unknown, 0), + MemoryRegionInfo({0x400ee000, 0x1000}, yes, yes, no, + yes, linker, unknown, 0), + MemoryRegionInfo({0x400fc000, 0x1000}, yes, yes, yes, + yes, liblog, unknown, 0)), + true)); +} + +// Windows Minidump tests +TEST_F(MinidumpParserTest, GetArchitectureWindows) { + ASSERT_THAT_ERROR(SetUpFromYaml(R"( +--- !minidump +Streams: + - Type: SystemInfo + Processor Arch: X86 + Processor Level: 6 + Processor Revision: 15876 + Number of Processors: 32 + Product type: 1 + Major Version: 6 + Minor Version: 1 + Build Number: 7601 + Platform ID: Win32NT + CSD Version: Service Pack 1 + Suite Mask: 0x0100 + CPU: + Vendor ID: GenuineIntel + Version Info: 0x000306E4 + Feature Info: 0xBFEBFBFF + AMD Extended Features: 0x771EEC80 +... +)"), + llvm::Succeeded()); + ASSERT_EQ(llvm::Triple::ArchType::x86, + parser->GetArchitecture().GetMachine()); + ASSERT_EQ(llvm::Triple::OSType::Win32, + parser->GetArchitecture().GetTriple().getOS()); +} + +TEST_F(MinidumpParserTest, GetLinuxProcStatus_no_stream) { + // Test that GetLinuxProcStatus returns nullptr when the minidump does not + // contain this stream. + ASSERT_THAT_ERROR(SetUpFromYaml(R"( +--- !minidump +Streams: +... +)"), + llvm::Succeeded()); + EXPECT_EQ(llvm::None, parser->GetLinuxProcStatus()); +} + +TEST_F(MinidumpParserTest, GetMiscInfoWindows) { + SetUpData("fizzbuzz_no_heap.dmp"); + const MinidumpMiscInfo *misc_info = parser->GetMiscInfo(); + ASSERT_NE(nullptr, misc_info); + llvm::Optional<lldb::pid_t> pid = misc_info->GetPid(); + ASSERT_TRUE(pid.hasValue()); + ASSERT_EQ(4440UL, pid.getValue()); +} + +TEST_F(MinidumpParserTest, GetPidWindows) { + SetUpData("fizzbuzz_no_heap.dmp"); + llvm::Optional<lldb::pid_t> pid = parser->GetPid(); + ASSERT_TRUE(pid.hasValue()); + ASSERT_EQ(4440UL, pid.getValue()); +} + +// wow64 +TEST_F(MinidumpParserTest, GetPidWow64) { + SetUpData("fizzbuzz_wow64.dmp"); + llvm::Optional<lldb::pid_t> pid = parser->GetPid(); + ASSERT_TRUE(pid.hasValue()); + ASSERT_EQ(7836UL, pid.getValue()); +} + +// Register tests +#define REG_VAL32(x) *(reinterpret_cast<uint32_t *>(x)) +#define REG_VAL64(x) *(reinterpret_cast<uint64_t *>(x)) + +TEST_F(MinidumpParserTest, GetThreadContext_x86_32) { + ASSERT_THAT_ERROR(SetUpFromYaml(R"( +--- !minidump +Streams: + - Type: ThreadList + Threads: + - Thread Id: 0x00026804 + Stack: + Start of Memory Range: 0x00000000FF9DD000 + Content: 68D39DFF + Context: 0F0001000000000000000000000000000000000000000000000000007F03FFFF0000FFFFFFFFFFFF09DC62F72300000088E36CF72B00FFFF00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000063000000000000002B0000002B000000A88204085CD59DFF008077F7A3D49DFF01000000000000003CD59DFFA082040823000000820201002CD59DFF2B0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +)"), + llvm::Succeeded()); + + llvm::ArrayRef<minidump::Thread> thread_list = parser->GetThreads(); + const minidump::Thread &thread = thread_list[0]; + llvm::ArrayRef<uint8_t> registers(parser->GetThreadContext(thread)); + const MinidumpContext_x86_32 *context; + EXPECT_TRUE(consumeObject(registers, context).Success()); + + EXPECT_EQ(MinidumpContext_x86_32_Flags(uint32_t(context->context_flags)), + MinidumpContext_x86_32_Flags::x86_32_Flag | + MinidumpContext_x86_32_Flags::Full | + MinidumpContext_x86_32_Flags::FloatingPoint); + + EXPECT_EQ(0x00000000u, context->eax); + EXPECT_EQ(0xf7778000u, context->ebx); + EXPECT_EQ(0x00000001u, context->ecx); + EXPECT_EQ(0xff9dd4a3u, context->edx); + EXPECT_EQ(0x080482a8u, context->edi); + EXPECT_EQ(0xff9dd55cu, context->esi); + EXPECT_EQ(0xff9dd53cu, context->ebp); + EXPECT_EQ(0xff9dd52cu, context->esp); + EXPECT_EQ(0x080482a0u, context->eip); + EXPECT_EQ(0x00010282u, context->eflags); + EXPECT_EQ(0x0023u, context->cs); + EXPECT_EQ(0x0000u, context->fs); + EXPECT_EQ(0x0063u, context->gs); + EXPECT_EQ(0x002bu, context->ss); + EXPECT_EQ(0x002bu, context->ds); + EXPECT_EQ(0x002bu, context->es); +} + +TEST_F(MinidumpParserTest, GetThreadContext_x86_64) { + ASSERT_THAT_ERROR(SetUpFromYaml(R"( +--- !minidump +Streams: + - Type: ThreadList + Threads: + - Thread Id: 0x00003E81 + Stack: + Start of Memory Range: 0x00007FFCEB34A000 + Content: C84D04BCE97F00 + Context: 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000B0010000000000033000000000000000000000006020100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000010A234EBFC7F000010A234EBFC7F00000000000000000000F09C34EBFC7F0000C0A91ABCE97F00000000000000000000A0163FBCE97F00004602000000000000921C40000000000030A434EBFC7F000000000000000000000000000000000000C61D4000000000007F0300000000000000000000000000000000000000000000801F0000FFFF0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000FFFF00FFFFFFFFFFFFFF00FFFFFFFF25252525252525252525252525252525000000000000000000000000000000000000000000000000000000000000000000FFFF00FFFFFFFFFFFFFF00FFFFFFFF0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000FF00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +... +)"), + llvm::Succeeded()); + llvm::ArrayRef<minidump::Thread> thread_list = parser->GetThreads(); + const minidump::Thread &thread = thread_list[0]; + llvm::ArrayRef<uint8_t> registers(parser->GetThreadContext(thread)); + const MinidumpContext_x86_64 *context; + EXPECT_TRUE(consumeObject(registers, context).Success()); + + EXPECT_EQ(MinidumpContext_x86_64_Flags(uint32_t(context->context_flags)), + MinidumpContext_x86_64_Flags::x86_64_Flag | + MinidumpContext_x86_64_Flags::Control | + MinidumpContext_x86_64_Flags::FloatingPoint | + MinidumpContext_x86_64_Flags::Integer); + EXPECT_EQ(0x0000000000000000u, context->rax); + EXPECT_EQ(0x0000000000000000u, context->rbx); + EXPECT_EQ(0x0000000000000010u, context->rcx); + EXPECT_EQ(0x0000000000000000u, context->rdx); + EXPECT_EQ(0x00007ffceb349cf0u, context->rdi); + EXPECT_EQ(0x0000000000000000u, context->rsi); + EXPECT_EQ(0x00007ffceb34a210u, context->rbp); + EXPECT_EQ(0x00007ffceb34a210u, context->rsp); + EXPECT_EQ(0x00007fe9bc1aa9c0u, context->r8); + EXPECT_EQ(0x0000000000000000u, context->r9); + EXPECT_EQ(0x00007fe9bc3f16a0u, context->r10); + EXPECT_EQ(0x0000000000000246u, context->r11); + EXPECT_EQ(0x0000000000401c92u, context->r12); + EXPECT_EQ(0x00007ffceb34a430u, context->r13); + EXPECT_EQ(0x0000000000000000u, context->r14); + EXPECT_EQ(0x0000000000000000u, context->r15); + EXPECT_EQ(0x0000000000401dc6u, context->rip); + EXPECT_EQ(0x00010206u, context->eflags); + EXPECT_EQ(0x0033u, context->cs); + EXPECT_EQ(0x0000u, context->ss); +} + +TEST_F(MinidumpParserTest, GetThreadContext_x86_32_wow64) { + SetUpData("fizzbuzz_wow64.dmp"); + llvm::ArrayRef<minidump::Thread> thread_list = parser->GetThreads(); + const minidump::Thread &thread = thread_list[0]; + llvm::ArrayRef<uint8_t> registers(parser->GetThreadContextWow64(thread)); + const MinidumpContext_x86_32 *context; + EXPECT_TRUE(consumeObject(registers, context).Success()); + + EXPECT_EQ(MinidumpContext_x86_32_Flags(uint32_t(context->context_flags)), + MinidumpContext_x86_32_Flags::x86_32_Flag | + MinidumpContext_x86_32_Flags::Full | + MinidumpContext_x86_32_Flags::FloatingPoint | + MinidumpContext_x86_32_Flags::ExtendedRegisters); + + EXPECT_EQ(0x00000000u, context->eax); + EXPECT_EQ(0x0037f608u, context->ebx); + EXPECT_EQ(0x00e61578u, context->ecx); + EXPECT_EQ(0x00000008u, context->edx); + EXPECT_EQ(0x00000000u, context->edi); + EXPECT_EQ(0x00000002u, context->esi); + EXPECT_EQ(0x0037f654u, context->ebp); + EXPECT_EQ(0x0037f5b8u, context->esp); + EXPECT_EQ(0x77ce01fdu, context->eip); + EXPECT_EQ(0x00000246u, context->eflags); + EXPECT_EQ(0x0023u, context->cs); + EXPECT_EQ(0x0053u, context->fs); + EXPECT_EQ(0x002bu, context->gs); + EXPECT_EQ(0x002bu, context->ss); + EXPECT_EQ(0x002bu, context->ds); + EXPECT_EQ(0x002bu, context->es); +} + +TEST_F(MinidumpParserTest, MinidumpDuplicateModuleMinAddress) { + ASSERT_THAT_ERROR(SetUpFromYaml(R"( +--- !minidump +Streams: + - Type: ModuleList + Modules: + - Base of Image: 0x0000000000002000 + Size of Image: 0x00001000 + Module Name: '/tmp/a' + CodeView Record: '' + - Base of Image: 0x0000000000001000 + Size of Image: 0x00001000 + Module Name: '/tmp/a' + CodeView Record: '' +... +)"), + llvm::Succeeded()); + // If we have a module mentioned twice in the module list, the filtered + // module list should contain the instance with the lowest BaseOfImage. + std::vector<const minidump::Module *> filtered_modules = + parser->GetFilteredModuleList(); + ASSERT_EQ(1u, filtered_modules.size()); + EXPECT_EQ(0x0000000000001000u, filtered_modules[0]->BaseOfImage); +} + +TEST_F(MinidumpParserTest, MinidumpModuleOrder) { + ASSERT_THAT_ERROR(SetUpFromYaml(R"( +--- !minidump +Streams: + - Type: ModuleList + Modules: + - Base of Image: 0x0000000000002000 + Size of Image: 0x00001000 + Module Name: '/tmp/a' + CodeView Record: '' + - Base of Image: 0x0000000000001000 + Size of Image: 0x00001000 + Module Name: '/tmp/b' + CodeView Record: '' +... +)"), + llvm::Succeeded()); + // Test module filtering does not affect the overall module order. Previous + // versions of the MinidumpParser::GetFilteredModuleList() function would sort + // all images by address and modify the order of the modules. + std::vector<const minidump::Module *> filtered_modules = + parser->GetFilteredModuleList(); + ASSERT_EQ(2u, filtered_modules.size()); + EXPECT_EQ(0x0000000000002000u, filtered_modules[0]->BaseOfImage); + EXPECT_THAT_EXPECTED( + parser->GetMinidumpFile().getString(filtered_modules[0]->ModuleNameRVA), + llvm::HasValue("/tmp/a")); + EXPECT_EQ(0x0000000000001000u, filtered_modules[1]->BaseOfImage); + EXPECT_THAT_EXPECTED( + parser->GetMinidumpFile().getString(filtered_modules[1]->ModuleNameRVA), + llvm::HasValue("/tmp/b")); +} + diff --git a/gnu/llvm/lldb/unittests/Process/minidump/RegisterContextMinidumpTest.cpp b/gnu/llvm/lldb/unittests/Process/minidump/RegisterContextMinidumpTest.cpp new file mode 100644 index 00000000000..265da63d33a --- /dev/null +++ b/gnu/llvm/lldb/unittests/Process/minidump/RegisterContextMinidumpTest.cpp @@ -0,0 +1,201 @@ +//===-- RegisterContextMinidumpTest.cpp -------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "Plugins/Process/Utility/RegisterContextLinux_i386.h" +#include "Plugins/Process/Utility/RegisterContextLinux_x86_64.h" +#include "Plugins/Process/minidump/RegisterContextMinidump_x86_32.h" +#include "Plugins/Process/minidump/RegisterContextMinidump_x86_64.h" +#include "Plugins/Process/minidump/RegisterContextMinidump_ARM.h" +#include "lldb/Utility/DataBuffer.h" +#include "llvm/ADT/StringRef.h" +#include "gtest/gtest.h" + +using namespace lldb_private; +using namespace lldb_private::minidump; + +static uint32_t reg32(const DataBuffer &Buf, const RegisterInfo &Info) { + return *reinterpret_cast<const uint32_t *>(Buf.GetBytes() + Info.byte_offset); +} + +static uint64_t reg64(const DataBuffer &Buf, const RegisterInfo &Info) { + return *reinterpret_cast<const uint64_t *>(Buf.GetBytes() + Info.byte_offset); +} + +TEST(RegisterContextMinidump, ConvertMinidumpContext_x86_32) { + MinidumpContext_x86_32 Context; + Context.context_flags = + static_cast<uint32_t>(MinidumpContext_x86_32_Flags::x86_32_Flag | + MinidumpContext_x86_32_Flags::Control | + MinidumpContext_x86_32_Flags::Segments | + MinidumpContext_x86_32_Flags::Integer); + Context.eax = 0x00010203; + Context.ebx = 0x04050607; + Context.ecx = 0x08090a0b; + Context.edx = 0x0c0d0e0f; + Context.edi = 0x10111213; + Context.esi = 0x14151617; + Context.ebp = 0x18191a1b; + Context.esp = 0x1c1d1e1f; + Context.eip = 0x20212223; + Context.eflags = 0x24252627; + Context.cs = 0x2829; + Context.fs = 0x2a2b; + Context.gs = 0x2c2d; + Context.ss = 0x2e2f; + Context.ds = 0x3031; + Context.es = 0x3233; + llvm::ArrayRef<uint8_t> ContextRef(reinterpret_cast<uint8_t *>(&Context), + sizeof(Context)); + + ArchSpec arch("i386-pc-linux"); + auto RegInterface = std::make_unique<RegisterContextLinux_i386>(arch); + lldb::DataBufferSP Buf = + ConvertMinidumpContext_x86_32(ContextRef, RegInterface.get()); + ASSERT_EQ(RegInterface->GetGPRSize(), Buf->GetByteSize()); + + const RegisterInfo *Info = RegInterface->GetRegisterInfo(); + ASSERT_NE(nullptr, Info); + + EXPECT_EQ(Context.eax, reg32(*Buf, Info[lldb_eax_i386])); + EXPECT_EQ(Context.ebx, reg32(*Buf, Info[lldb_ebx_i386])); + EXPECT_EQ(Context.ecx, reg32(*Buf, Info[lldb_ecx_i386])); + EXPECT_EQ(Context.edx, reg32(*Buf, Info[lldb_edx_i386])); + EXPECT_EQ(Context.edi, reg32(*Buf, Info[lldb_edi_i386])); + EXPECT_EQ(Context.esi, reg32(*Buf, Info[lldb_esi_i386])); + EXPECT_EQ(Context.ebp, reg32(*Buf, Info[lldb_ebp_i386])); + EXPECT_EQ(Context.esp, reg32(*Buf, Info[lldb_esp_i386])); + EXPECT_EQ(Context.eip, reg32(*Buf, Info[lldb_eip_i386])); + EXPECT_EQ(Context.eflags, reg32(*Buf, Info[lldb_eflags_i386])); + EXPECT_EQ(Context.cs, reg32(*Buf, Info[lldb_cs_i386])); + EXPECT_EQ(Context.fs, reg32(*Buf, Info[lldb_fs_i386])); + EXPECT_EQ(Context.gs, reg32(*Buf, Info[lldb_gs_i386])); + EXPECT_EQ(Context.ss, reg32(*Buf, Info[lldb_ss_i386])); + EXPECT_EQ(Context.ds, reg32(*Buf, Info[lldb_ds_i386])); + EXPECT_EQ(Context.es, reg32(*Buf, Info[lldb_es_i386])); +} + +TEST(RegisterContextMinidump, ConvertMinidumpContext_x86_64) { + MinidumpContext_x86_64 Context; + Context.context_flags = + static_cast<uint32_t>(MinidumpContext_x86_64_Flags::x86_64_Flag | + MinidumpContext_x86_64_Flags::Control | + MinidumpContext_x86_64_Flags::Segments | + MinidumpContext_x86_64_Flags::Integer); + Context.rax = 0x0001020304050607; + Context.rbx = 0x08090a0b0c0d0e0f; + Context.rcx = 0x1011121314151617; + Context.rdx = 0x18191a1b1c1d1e1f; + Context.rdi = 0x2021222324252627; + Context.rsi = 0x28292a2b2c2d2e2f; + Context.rbp = 0x3031323334353637; + Context.rsp = 0x38393a3b3c3d3e3f; + Context.r8 = 0x4041424344454647; + Context.r9 = 0x48494a4b4c4d4e4f; + Context.r10 = 0x5051525354555657; + Context.r11 = 0x58595a5b5c5d5e5f; + Context.r12 = 0x6061626364656667; + Context.r13 = 0x68696a6b6c6d6e6f; + Context.r14 = 0x7071727374757677; + Context.r15 = 0x78797a7b7c7d7e7f; + Context.rip = 0x8081828384858687; + Context.eflags = 0x88898a8b; + Context.cs = 0x8c8d; + Context.fs = 0x8e8f; + Context.gs = 0x9091; + Context.ss = 0x9293; + Context.ds = 0x9495; + Context.ss = 0x9697; + llvm::ArrayRef<uint8_t> ContextRef(reinterpret_cast<uint8_t *>(&Context), + sizeof(Context)); + + ArchSpec arch("x86_64-pc-linux"); + auto RegInterface = std::make_unique<RegisterContextLinux_x86_64>(arch); + lldb::DataBufferSP Buf = + ConvertMinidumpContext_x86_64(ContextRef, RegInterface.get()); + ASSERT_EQ(RegInterface->GetGPRSize(), Buf->GetByteSize()); + + const RegisterInfo *Info = RegInterface->GetRegisterInfo(); + EXPECT_EQ(Context.rax, reg64(*Buf, Info[lldb_rax_x86_64])); + EXPECT_EQ(Context.rbx, reg64(*Buf, Info[lldb_rbx_x86_64])); + EXPECT_EQ(Context.rcx, reg64(*Buf, Info[lldb_rcx_x86_64])); + EXPECT_EQ(Context.rdx, reg64(*Buf, Info[lldb_rdx_x86_64])); + EXPECT_EQ(Context.rdi, reg64(*Buf, Info[lldb_rdi_x86_64])); + EXPECT_EQ(Context.rsi, reg64(*Buf, Info[lldb_rsi_x86_64])); + EXPECT_EQ(Context.rbp, reg64(*Buf, Info[lldb_rbp_x86_64])); + EXPECT_EQ(Context.rsp, reg64(*Buf, Info[lldb_rsp_x86_64])); + EXPECT_EQ(Context.r8, reg64(*Buf, Info[lldb_r8_x86_64])); + EXPECT_EQ(Context.r9, reg64(*Buf, Info[lldb_r9_x86_64])); + EXPECT_EQ(Context.r10, reg64(*Buf, Info[lldb_r10_x86_64])); + EXPECT_EQ(Context.r11, reg64(*Buf, Info[lldb_r11_x86_64])); + EXPECT_EQ(Context.r12, reg64(*Buf, Info[lldb_r12_x86_64])); + EXPECT_EQ(Context.r13, reg64(*Buf, Info[lldb_r13_x86_64])); + EXPECT_EQ(Context.r14, reg64(*Buf, Info[lldb_r14_x86_64])); + EXPECT_EQ(Context.r15, reg64(*Buf, Info[lldb_r15_x86_64])); + EXPECT_EQ(Context.rip, reg64(*Buf, Info[lldb_rip_x86_64])); + EXPECT_EQ(Context.eflags, reg64(*Buf, Info[lldb_rflags_x86_64])); + EXPECT_EQ(Context.cs, reg64(*Buf, Info[lldb_cs_x86_64])); + EXPECT_EQ(Context.fs, reg64(*Buf, Info[lldb_fs_x86_64])); + EXPECT_EQ(Context.gs, reg64(*Buf, Info[lldb_gs_x86_64])); + EXPECT_EQ(Context.ss, reg64(*Buf, Info[lldb_ss_x86_64])); + EXPECT_EQ(Context.ds, reg64(*Buf, Info[lldb_ds_x86_64])); + EXPECT_EQ(Context.es, reg64(*Buf, Info[lldb_es_x86_64])); +} + +static void TestARMRegInfo(const lldb_private::RegisterInfo *info) { + // Make sure we have valid register numbers for eRegisterKindEHFrame and + // eRegisterKindDWARF for GPR registers r0-r15 so that we can unwind + // correctly when using this information. + llvm::StringRef name(info->name); + llvm::StringRef alt_name(info->alt_name); + if (name.startswith("r") || alt_name.startswith("r")) { + EXPECT_NE(info->kinds[lldb::eRegisterKindEHFrame], LLDB_INVALID_REGNUM); + EXPECT_NE(info->kinds[lldb::eRegisterKindDWARF], LLDB_INVALID_REGNUM); + } + // Verify generic register are set correctly + if (name == "r0") { + EXPECT_EQ(info->kinds[lldb::eRegisterKindGeneric], + (uint32_t)LLDB_REGNUM_GENERIC_ARG1); + } else if (name == "r1") { + EXPECT_EQ(info->kinds[lldb::eRegisterKindGeneric], + (uint32_t)LLDB_REGNUM_GENERIC_ARG2); + } else if (name == "r2") { + EXPECT_EQ(info->kinds[lldb::eRegisterKindGeneric], + (uint32_t)LLDB_REGNUM_GENERIC_ARG3); + } else if (name == "r3") { + EXPECT_EQ(info->kinds[lldb::eRegisterKindGeneric], + (uint32_t)LLDB_REGNUM_GENERIC_ARG4); + } else if (name == "sp") { + EXPECT_EQ(info->kinds[lldb::eRegisterKindGeneric], + (uint32_t)LLDB_REGNUM_GENERIC_SP); + } else if (name == "fp") { + EXPECT_EQ(info->kinds[lldb::eRegisterKindGeneric], + (uint32_t)LLDB_REGNUM_GENERIC_FP); + } else if (name == "lr") { + EXPECT_EQ(info->kinds[lldb::eRegisterKindGeneric], + (uint32_t)LLDB_REGNUM_GENERIC_RA); + } else if (name == "pc") { + EXPECT_EQ(info->kinds[lldb::eRegisterKindGeneric], + (uint32_t)LLDB_REGNUM_GENERIC_PC); + } else if (name == "cpsr") { + EXPECT_EQ(info->kinds[lldb::eRegisterKindGeneric], + (uint32_t)LLDB_REGNUM_GENERIC_FLAGS); + } +} + +TEST(RegisterContextMinidump, CheckRegisterContextMinidump_ARM) { + size_t num_regs = RegisterContextMinidump_ARM::GetRegisterCountStatic(); + const lldb_private::RegisterInfo *reg_info; + for (size_t reg=0; reg<num_regs; ++reg) { + reg_info = RegisterContextMinidump_ARM::GetRegisterInfoAtIndexStatic(reg, + true); + TestARMRegInfo(reg_info); + reg_info = RegisterContextMinidump_ARM::GetRegisterInfoAtIndexStatic(reg, + false); + TestARMRegInfo(reg_info); + } +} |