[AArch64,ELF] Restrict MOVZ/MOVK to non-PIC large code model (#70178)
[llvm-project.git] / lldb / unittests / Symbol / MangledTest.cpp
blob85df7780cff87a971f2573bfae13f4ae66fe9301
1 //===-- SymbolTest.cpp ----------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Core/Mangled.h"
10 #include "lldb/Core/DataFileCache.h"
11 #include "lldb/Utility/DataEncoder.h"
12 #include "lldb/Utility/DataExtractor.h"
14 #include "gtest/gtest.h"
16 using namespace lldb;
17 using namespace lldb_private;
19 static void EncodeDecode(const Mangled &object, ByteOrder byte_order) {
20 const uint8_t addr_size = 8;
21 DataEncoder file(byte_order, addr_size);
22 DataEncoder strtab_encoder(byte_order, addr_size);
23 ConstStringTable const_strtab;
25 object.Encode(file, const_strtab);
27 llvm::ArrayRef<uint8_t> bytes = file.GetData();
28 DataExtractor data(bytes.data(), bytes.size(), byte_order, addr_size);
30 const_strtab.Encode(strtab_encoder);
31 llvm::ArrayRef<uint8_t> strtab_bytes = strtab_encoder.GetData();
32 DataExtractor strtab_data(strtab_bytes.data(), strtab_bytes.size(),
33 byte_order, addr_size);
34 StringTableReader strtab_reader;
35 offset_t strtab_data_offset = 0;
36 ASSERT_EQ(strtab_reader.Decode(strtab_data, &strtab_data_offset), true);
38 Mangled decoded_object;
39 offset_t data_offset = 0;
40 decoded_object.Decode(data, &data_offset, strtab_reader);
41 EXPECT_EQ(object, decoded_object);
44 static void EncodeDecode(const Mangled &object) {
45 EncodeDecode(object, eByteOrderLittle);
46 EncodeDecode(object, eByteOrderBig);
49 TEST(MangledTest, EncodeDecodeMangled) {
50 Mangled mangled;
51 // Test encoding and decoding an empty mangled object.
52 EncodeDecode(mangled);
54 // Test encoding a mangled object that hasn't demangled its name yet.
55 mangled.SetMangledName(ConstString("_Z3fooi"));
56 EncodeDecode(mangled);
58 // Test encoding a mangled object that has demangled its name by computing it.
59 mangled.GetDemangledName();
60 // EncodeDecode(mangled);
62 // Test encoding a mangled object that has just a demangled name
63 mangled.SetMangledName(ConstString());
64 mangled.SetDemangledName(ConstString("hello"));
65 EncodeDecode(mangled);
67 // Test encoding a mangled name that has both a mangled and demangled name
68 // that are not mangled/demangled counterparts of each other.
69 mangled.SetMangledName(ConstString("world"));
70 EncodeDecode(mangled);