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 //===----------------------------------------------------------------------===//
8 
9 #include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h"
10 #include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
11 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
12 #include "TestingSupport/SubsystemRAII.h"
13 #include "TestingSupport/TestUtilities.h"
14 
15 #include "lldb/Core/DataFileCache.h"
16 #include "lldb/Core/Module.h"
17 #include "lldb/Host/FileSystem.h"
18 #include "lldb/Host/HostInfo.h"
19 #include "lldb/Symbol/Symbol.h"
20 #include "lldb/Symbol/Symtab.h"
21 #include "lldb/Utility/DataEncoder.h"
22 #include "lldb/Utility/DataExtractor.h"
23 
24 #include <memory>
25 
26 #include "gtest/gtest.h"
27 
28 using namespace lldb;
29 using namespace lldb_private;
30 
31 class SymtabTest : public testing::Test {
32   SubsystemRAII<FileSystem, HostInfo, ObjectFileMachO, SymbolFileDWARF,
33                 TypeSystemClang>
34       subsystem;
35 };
36 
EncodeDecode(const Symtab & object,ByteOrder byte_order)37 static void EncodeDecode(const Symtab &object, ByteOrder byte_order) {
38   const uint8_t addr_size = 8;
39   DataEncoder file(byte_order, addr_size);
40 
41   object.Encode(file);
42   llvm::ArrayRef<uint8_t> bytes = file.GetData();
43   DataExtractor data(bytes.data(), bytes.size(), byte_order, addr_size);
44   Symtab decoded_object(object.GetObjectFile());
45   offset_t data_offset = 0;
46   bool uuid_mismatch = false;
47   decoded_object.Decode(data, &data_offset, uuid_mismatch);
48   ASSERT_EQ(object.GetNumSymbols(), decoded_object.GetNumSymbols());
49   for (size_t i = 0; i < object.GetNumSymbols(); ++i)
50     EXPECT_EQ(*object.SymbolAtIndex(i), *decoded_object.SymbolAtIndex(i));
51 }
52 
EncodeDecode(const Symtab & object)53 static void EncodeDecode(const Symtab &object) {
54   EncodeDecode(object, eByteOrderLittle);
55   EncodeDecode(object, eByteOrderBig);
56 }
57 
TEST_F(SymtabTest,EncodeDecodeSymtab)58 TEST_F(SymtabTest, EncodeDecodeSymtab) {
59 
60   auto ExpectedFile = TestFile::fromYaml(R"(
61 --- !mach-o
62 FileHeader:
63   magic:           0xFEEDFACF
64   cputype:         0x100000C
65   cpusubtype:      0x0
66   filetype:        0x2
67   ncmds:           17
68   sizeofcmds:      792
69   flags:           0x200085
70   reserved:        0x0
71 LoadCommands:
72   - cmd:             LC_SEGMENT_64
73     cmdsize:         72
74     segname:         __PAGEZERO
75     vmaddr:          0
76     vmsize:          4294967296
77     fileoff:         0
78     filesize:        0
79     maxprot:         0
80     initprot:        0
81     nsects:          0
82     flags:           0
83   - cmd:             LC_SEGMENT_64
84     cmdsize:         232
85     segname:         __TEXT
86     vmaddr:          4294967296
87     vmsize:          16384
88     fileoff:         0
89     filesize:        16384
90     maxprot:         5
91     initprot:        5
92     nsects:          2
93     flags:           0
94     Sections:
95       - sectname:        __text
96         segname:         __TEXT
97         addr:            0x100003F94
98         size:            36
99         offset:          0x3F94
100         align:           2
101         reloff:          0x0
102         nreloc:          0
103         flags:           0x80000400
104         reserved1:       0x0
105         reserved2:       0x0
106         reserved3:       0x0
107         content:         FF8300D1E80300AA00008052FF1F00B9E81B00B9E10B00F9E20700F9FF830091C0035FD6
108       - sectname:        __unwind_info
109         segname:         __TEXT
110         addr:            0x100003FB8
111         size:            72
112         offset:          0x3FB8
113         align:           2
114         reloff:          0x0
115         nreloc:          0
116         flags:           0x0
117         reserved1:       0x0
118         reserved2:       0x0
119         reserved3:       0x0
120         content:         010000001C000000000000001C000000000000001C00000002000000943F00003400000034000000B93F00000000000034000000030000000C000100100001000000000000200002
121   - cmd:             LC_SEGMENT_64
122     cmdsize:         72
123     segname:         __LINKEDIT
124     vmaddr:          4294983680
125     vmsize:          16384
126     fileoff:         16384
127     filesize:        674
128     maxprot:         1
129     initprot:        1
130     nsects:          0
131     flags:           0
132   - cmd:             LC_DYLD_CHAINED_FIXUPS
133     cmdsize:         16
134     dataoff:         16384
135     datasize:        56
136   - cmd:             LC_DYLD_EXPORTS_TRIE
137     cmdsize:         16
138     dataoff:         16440
139     datasize:        48
140   - cmd:             LC_SYMTAB
141     cmdsize:         24
142     symoff:          16496
143     nsyms:           10
144     stroff:          16656
145     strsize:         128
146   - cmd:             LC_DYSYMTAB
147     cmdsize:         80
148     ilocalsym:       0
149     nlocalsym:       8
150     iextdefsym:      8
151     nextdefsym:      2
152     iundefsym:       10
153     nundefsym:       0
154     tocoff:          0
155     ntoc:            0
156     modtaboff:       0
157     nmodtab:         0
158     extrefsymoff:    0
159     nextrefsyms:     0
160     indirectsymoff:  0
161     nindirectsyms:   0
162     extreloff:       0
163     nextrel:         0
164     locreloff:       0
165     nlocrel:         0
166   - cmd:             LC_LOAD_DYLINKER
167     cmdsize:         32
168     name:            12
169     Content:         '/usr/lib/dyld'
170     ZeroPadBytes:    7
171   - cmd:             LC_UUID
172     cmdsize:         24
173     uuid:            1EECD2B8-16EA-3FEC-AB3C-F46139DBD0E2
174   - cmd:             LC_BUILD_VERSION
175     cmdsize:         32
176     platform:        1
177     minos:           786432
178     sdk:             786432
179     ntools:          1
180     Tools:
181       - tool:            3
182         version:         46596096
183   - cmd:             LC_SOURCE_VERSION
184     cmdsize:         16
185     version:         0
186   - cmd:             LC_MAIN
187     cmdsize:         24
188     entryoff:        16276
189     stacksize:       0
190   - cmd:             LC_LOAD_DYLIB
191     cmdsize:         48
192     dylib:
193       name:            24
194       timestamp:       2
195       current_version: 78643968
196       compatibility_version: 65536
197     Content:         '/usr/lib/libc++.1.dylib'
198     ZeroPadBytes:    1
199   - cmd:             LC_LOAD_DYLIB
200     cmdsize:         56
201     dylib:
202       name:            24
203       timestamp:       2
204       current_version: 85917696
205       compatibility_version: 65536
206     Content:         '/usr/lib/libSystem.B.dylib'
207     ZeroPadBytes:    6
208   - cmd:             LC_FUNCTION_STARTS
209     cmdsize:         16
210     dataoff:         16488
211     datasize:        8
212   - cmd:             LC_DATA_IN_CODE
213     cmdsize:         16
214     dataoff:         16496
215     datasize:        0
216   - cmd:             LC_CODE_SIGNATURE
217     cmdsize:         16
218     dataoff:         16784
219     datasize:        274
220 LinkEditData:
221   NameList:
222     - n_strx:          28
223       n_type:          0x64
224       n_sect:          0
225       n_desc:          0
226       n_value:         0
227     - n_strx:          64
228       n_type:          0x64
229       n_sect:          0
230       n_desc:          0
231       n_value:         0
232     - n_strx:          73
233       n_type:          0x66
234       n_sect:          0
235       n_desc:          1
236       n_value:         1639532873
237     - n_strx:          1
238       n_type:          0x2E
239       n_sect:          1
240       n_desc:          0
241       n_value:         4294983572
242     - n_strx:          115
243       n_type:          0x24
244       n_sect:          1
245       n_desc:          0
246       n_value:         4294983572
247     - n_strx:          1
248       n_type:          0x24
249       n_sect:          0
250       n_desc:          0
251       n_value:         36
252     - n_strx:          1
253       n_type:          0x4E
254       n_sect:          1
255       n_desc:          0
256       n_value:         36
257     - n_strx:          1
258       n_type:          0x64
259       n_sect:          1
260       n_desc:          0
261       n_value:         0
262     - n_strx:          2
263       n_type:          0xF
264       n_sect:          1
265       n_desc:          16
266       n_value:         4294967296
267     - n_strx:          22
268       n_type:          0xF
269       n_sect:          1
270       n_desc:          0
271       n_value:         4294983572
272   StringTable:
273     - ' '
274     - __mh_execute_header
275     - _main
276     - '/Users/gclayton/Documents/src/args/'
277     - main.cpp
278     - '/Users/gclayton/Documents/src/args/main.o'
279     - _main
280     - ''
281     - ''
282     - ''
283     - ''
284     - ''
285     - ''
286     - ''
287 ...
288 )");
289 
290   ASSERT_THAT_EXPECTED(ExpectedFile, llvm::Succeeded());
291   auto module_sp = std::make_shared<Module>(ExpectedFile->moduleSpec());
292   ObjectFile *objfile = module_sp->GetObjectFile();
293   ASSERT_NE(objfile, nullptr);
294 
295   // Test encoding and decoding an empty symbol table.
296   Symtab symtab(objfile);
297   symtab.PreloadSymbols();
298   EncodeDecode(symtab);
299 
300   // Now encode and decode an actual symbol table from our yaml.
301   Symtab *module_symtab = module_sp->GetSymtab();
302   ASSERT_NE(module_symtab, nullptr);
303   module_symtab->PreloadSymbols();
304   EncodeDecode(*module_symtab);
305 }
306 
TEST_F(SymtabTest,TestDecodeCStringMaps)307 TEST_F(SymtabTest, TestDecodeCStringMaps) {
308   // Symbol tables save out the symbols, but they also save out the symbol table
309   // name indexes. These name indexes are a map of sorted ConstString + T pairs
310   // and when they are decoded from a file, they are no longer sorted since
311   // ConstString objects can be sorted by "const char *" and the order in which
312   // these strings are created won't be the same in a new process. We need to
313   // ensure these name lookups happen correctly when we load the name indexes,
314   // so this test loads a symbol table from a cache file from
315   // "lldb/unittests/Symbol/Inputs/indexnames-symtab-cache" and make sure we
316   // can correctly lookup each of the names in the symbol table.
317   auto ExpectedFile = TestFile::fromYaml(R"(
318 --- !mach-o
319 FileHeader:
320   magic:           0xFEEDFACF
321   cputype:         0x100000C
322   cpusubtype:      0x0
323   filetype:        0x2
324   ncmds:           16
325   sizeofcmds:      744
326   flags:           0x200085
327   reserved:        0x0
328 LoadCommands:
329   - cmd:             LC_SEGMENT_64
330     cmdsize:         72
331     segname:         __PAGEZERO
332     vmaddr:          0
333     vmsize:          4294967296
334     fileoff:         0
335     filesize:        0
336     maxprot:         0
337     initprot:        0
338     nsects:          0
339     flags:           0
340   - cmd:             LC_SEGMENT_64
341     cmdsize:         232
342     segname:         __TEXT
343     vmaddr:          4294967296
344     vmsize:          16384
345     fileoff:         0
346     filesize:        16384
347     maxprot:         5
348     initprot:        5
349     nsects:          2
350     flags:           0
351     Sections:
352       - sectname:        __text
353         segname:         __TEXT
354         addr:            0x100003F64
355         size:            76
356         offset:          0x3F64
357         align:           2
358         reloff:          0x0
359         nreloc:          0
360         flags:           0x80000400
361         reserved1:       0x0
362         reserved2:       0x0
363         reserved3:       0x0
364         content:         80018052C0035FD6E0028052C0035FD640048052C0035FD6FF8300D1FD7B01A9FD43009108008052E80B00B9BFC31FB8F4FFFF97F5FFFF97F6FFFF97E00B40B9FD7B41A9FF830091C0035FD6
365       - sectname:        __unwind_info
366         segname:         __TEXT
367         addr:            0x100003FB0
368         size:            80
369         offset:          0x3FB0
370         align:           2
371         reloff:          0x0
372         nreloc:          0
373         flags:           0x0
374         reserved1:       0x0
375         reserved2:       0x0
376         reserved3:       0x0
377         content:         010000001C000000000000001C000000000000001C00000002000000643F00003400000034000000B13F00000000000034000000030000000C0002001400020000000001180000000000000400000002
378   - cmd:             LC_SEGMENT_64
379     cmdsize:         72
380     segname:         __LINKEDIT
381     vmaddr:          4294983680
382     vmsize:          16384
383     fileoff:         16384
384     filesize:        994
385     maxprot:         1
386     initprot:        1
387     nsects:          0
388     flags:           0
389   - cmd:             LC_DYLD_CHAINED_FIXUPS
390     cmdsize:         16
391     dataoff:         16384
392     datasize:        56
393   - cmd:             LC_DYLD_EXPORTS_TRIE
394     cmdsize:         16
395     dataoff:         16440
396     datasize:        80
397   - cmd:             LC_SYMTAB
398     cmdsize:         24
399     symoff:          16528
400     nsyms:           25
401     stroff:          16928
402     strsize:         176
403   - cmd:             LC_DYSYMTAB
404     cmdsize:         80
405     ilocalsym:       0
406     nlocalsym:       20
407     iextdefsym:      20
408     nextdefsym:      5
409     iundefsym:       25
410     nundefsym:       0
411     tocoff:          0
412     ntoc:            0
413     modtaboff:       0
414     nmodtab:         0
415     extrefsymoff:    0
416     nextrefsyms:     0
417     indirectsymoff:  0
418     nindirectsyms:   0
419     extreloff:       0
420     nextrel:         0
421     locreloff:       0
422     nlocrel:         0
423   - cmd:             LC_LOAD_DYLINKER
424     cmdsize:         32
425     name:            12
426     Content:         '/usr/lib/dyld'
427     ZeroPadBytes:    7
428   - cmd:             LC_UUID
429     cmdsize:         24
430     uuid:            3E94866E-0D1A-39BD-975B-64E8F1FDBAAE
431   - cmd:             LC_BUILD_VERSION
432     cmdsize:         32
433     platform:        1
434     minos:           786432
435     sdk:             787200
436     ntools:          1
437     Tools:
438       - tool:            3
439         version:         49938432
440   - cmd:             LC_SOURCE_VERSION
441     cmdsize:         16
442     version:         0
443   - cmd:             LC_MAIN
444     cmdsize:         24
445     entryoff:        16252
446     stacksize:       0
447   - cmd:             LC_LOAD_DYLIB
448     cmdsize:         56
449     dylib:
450       name:            24
451       timestamp:       2
452       current_version: 85943299
453       compatibility_version: 65536
454     Content:         '/usr/lib/libSystem.B.dylib'
455     ZeroPadBytes:    6
456   - cmd:             LC_FUNCTION_STARTS
457     cmdsize:         16
458     dataoff:         16520
459     datasize:        8
460   - cmd:             LC_DATA_IN_CODE
461     cmdsize:         16
462     dataoff:         16528
463     datasize:        0
464   - cmd:             LC_CODE_SIGNATURE
465     cmdsize:         16
466     dataoff:         17104
467     datasize:        274
468 LinkEditData:
469   NameList:
470     - n_strx:          43
471       n_type:          0x64
472       n_sect:          0
473       n_desc:          0
474       n_value:         0
475     - n_strx:          91
476       n_type:          0x64
477       n_sect:          0
478       n_desc:          0
479       n_value:         0
480     - n_strx:          98
481       n_type:          0x66
482       n_sect:          0
483       n_desc:          1
484       n_value:         1651098491
485     - n_strx:          1
486       n_type:          0x2E
487       n_sect:          1
488       n_desc:          0
489       n_value:         4294983524
490     - n_strx:          152
491       n_type:          0x24
492       n_sect:          1
493       n_desc:          0
494       n_value:         4294983524
495     - n_strx:          1
496       n_type:          0x24
497       n_sect:          0
498       n_desc:          0
499       n_value:         8
500     - n_strx:          1
501       n_type:          0x4E
502       n_sect:          1
503       n_desc:          0
504       n_value:         8
505     - n_strx:          1
506       n_type:          0x2E
507       n_sect:          1
508       n_desc:          0
509       n_value:         4294983532
510     - n_strx:          157
511       n_type:          0x24
512       n_sect:          1
513       n_desc:          0
514       n_value:         4294983532
515     - n_strx:          1
516       n_type:          0x24
517       n_sect:          0
518       n_desc:          0
519       n_value:         8
520     - n_strx:          1
521       n_type:          0x4E
522       n_sect:          1
523       n_desc:          0
524       n_value:         8
525     - n_strx:          1
526       n_type:          0x2E
527       n_sect:          1
528       n_desc:          0
529       n_value:         4294983540
530     - n_strx:          162
531       n_type:          0x24
532       n_sect:          1
533       n_desc:          0
534       n_value:         4294983540
535     - n_strx:          1
536       n_type:          0x24
537       n_sect:          0
538       n_desc:          0
539       n_value:         8
540     - n_strx:          1
541       n_type:          0x4E
542       n_sect:          1
543       n_desc:          0
544       n_value:         8
545     - n_strx:          1
546       n_type:          0x2E
547       n_sect:          1
548       n_desc:          0
549       n_value:         4294983548
550     - n_strx:          167
551       n_type:          0x24
552       n_sect:          1
553       n_desc:          0
554       n_value:         4294983548
555     - n_strx:          1
556       n_type:          0x24
557       n_sect:          0
558       n_desc:          0
559       n_value:         52
560     - n_strx:          1
561       n_type:          0x4E
562       n_sect:          1
563       n_desc:          0
564       n_value:         52
565     - n_strx:          1
566       n_type:          0x64
567       n_sect:          1
568       n_desc:          0
569       n_value:         0
570     - n_strx:          2
571       n_type:          0xF
572       n_sect:          1
573       n_desc:          16
574       n_value:         4294967296
575     - n_strx:          22
576       n_type:          0xF
577       n_sect:          1
578       n_desc:          0
579       n_value:         4294983532
580     - n_strx:          27
581       n_type:          0xF
582       n_sect:          1
583       n_desc:          0
584       n_value:         4294983540
585     - n_strx:          32
586       n_type:          0xF
587       n_sect:          1
588       n_desc:          0
589       n_value:         4294983524
590     - n_strx:          37
591       n_type:          0xF
592       n_sect:          1
593       n_desc:          0
594       n_value:         4294983548
595   StringTable:
596     - ' '
597     - __mh_execute_header
598     - _bar
599     - _baz
600     - _foo
601     - _main
602     - '/Users/gclayton/Documents/objfiles/index-names/'
603     - main.c
604     - '/Users/gclayton/Documents/objfiles/index-names/main.o'
605     - _foo
606     - _bar
607     - _baz
608     - _main
609     - ''
610     - ''
611     - ''
612   FunctionStarts:  [ 0x3F64, 0x3F6C, 0x3F74, 0x3F7C ]
613 ...
614 )");
615   // This data was taken from a hex dump of the object file from the above yaml
616   // and hexdumped so we can load the cache data in this test.
617   const uint8_t symtab_cache_bytes[] = {
618     0x01, 0x10, 0x3e, 0x94, 0x86, 0x6e, 0x0d, 0x1a,
619     0x39, 0xbd, 0x97, 0x5b, 0x64, 0xe8, 0xf1, 0xfd,
620     0xba, 0xae, 0xff, 0x53, 0x54, 0x41, 0x42, 0x91,
621     0x00, 0x00, 0x00, 0x00, 0x2f, 0x55, 0x73, 0x65,
622     0x72, 0x73, 0x2f, 0x67, 0x63, 0x6c, 0x61, 0x79,
623     0x74, 0x6f, 0x6e, 0x2f, 0x44, 0x6f, 0x63, 0x75,
624     0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x6f, 0x62,
625     0x6a, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2f, 0x69,
626     0x6e, 0x64, 0x65, 0x78, 0x2d, 0x6e, 0x61, 0x6d,
627     0x65, 0x73, 0x2f, 0x6d, 0x61, 0x69, 0x6e, 0x2e,
628     0x63, 0x00, 0x2f, 0x55, 0x73, 0x65, 0x72, 0x73,
629     0x2f, 0x67, 0x63, 0x6c, 0x61, 0x79, 0x74, 0x6f,
630     0x6e, 0x2f, 0x44, 0x6f, 0x63, 0x75, 0x6d, 0x65,
631     0x6e, 0x74, 0x73, 0x2f, 0x6f, 0x62, 0x6a, 0x66,
632     0x69, 0x6c, 0x65, 0x73, 0x2f, 0x69, 0x6e, 0x64,
633     0x65, 0x78, 0x2d, 0x6e, 0x61, 0x6d, 0x65, 0x73,
634     0x2f, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x6f, 0x00,
635     0x66, 0x6f, 0x6f, 0x00, 0x62, 0x61, 0x72, 0x00,
636     0x62, 0x61, 0x7a, 0x00, 0x6d, 0x61, 0x69, 0x6e,
637     0x00, 0x5f, 0x6d, 0x68, 0x5f, 0x65, 0x78, 0x65,
638     0x63, 0x75, 0x74, 0x65, 0x5f, 0x68, 0x65, 0x61,
639     0x64, 0x65, 0x72, 0x00, 0x53, 0x59, 0x4d, 0x42,
640     0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
641     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x2a,
642     0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
643     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00,
644     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
645     0x64, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
646     0x0a, 0x20, 0x01, 0x37, 0x00, 0x00, 0x00, 0x00,
647     0x7b, 0xc3, 0x69, 0x62, 0x00, 0x00, 0x00, 0x00,
648     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
649     0x01, 0x00, 0x66, 0x00, 0x04, 0x00, 0x00, 0x00,
650     0x00, 0x00, 0x02, 0x32, 0x01, 0x6d, 0x00, 0x00,
651     0x00, 0x01, 0x64, 0x3f, 0x00, 0x00, 0x01, 0x00,
652     0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
653     0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x08, 0x00,
654     0x00, 0x00, 0x00, 0x00, 0x02, 0x32, 0x01, 0x71,
655     0x00, 0x00, 0x00, 0x01, 0x6c, 0x3f, 0x00, 0x00,
656     0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
657     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00,
658     0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x32,
659     0x01, 0x75, 0x00, 0x00, 0x00, 0x01, 0x74, 0x3f,
660     0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00,
661     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
662     0x0f, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
663     0x02, 0x32, 0x01, 0x79, 0x00, 0x00, 0x00, 0x01,
664     0x7c, 0x3f, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
665     0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
666     0x00, 0x00, 0x0f, 0x00, 0x14, 0x00, 0x00, 0x00,
667     0x00, 0x00, 0x04, 0x12, 0x02, 0x7e, 0x00, 0x00,
668     0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
669     0x00, 0x00, 0x64, 0x3f, 0x00, 0x00, 0x00, 0x00,
670     0x00, 0x00, 0x10, 0x00, 0x0f, 0x00, 0x01, 0x00,
671     0x43, 0x4d, 0x41, 0x50, 0x07, 0x00, 0x00, 0x00,
672     0x6d, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
673     0x75, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
674     0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
675     0x79, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
676     0x37, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
677     0x71, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
678     0x7e, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00
679   };
680 
681   ASSERT_THAT_EXPECTED(ExpectedFile, llvm::Succeeded());
682   auto module_sp = std::make_shared<Module>(ExpectedFile->moduleSpec());
683   ObjectFile *objfile = module_sp->GetObjectFile();
684   ASSERT_NE(objfile, nullptr);
685 
686   // Test encoding and decoding an empty symbol table.
687   DataExtractor data(symtab_cache_bytes, sizeof(symtab_cache_bytes),
688                      eByteOrderLittle, 8);
689   Symtab symtab(objfile);
690   offset_t data_offset = 0;
691   bool uuid_mismatch = false; // Gets set to true if signature doesn't match.
692   const bool success = symtab.Decode(data, &data_offset, uuid_mismatch);
693   ASSERT_EQ(success, true);
694   ASSERT_EQ(uuid_mismatch, false);
695 
696   // Now make sure that name lookup works for all symbols. This indicates that
697   // the Symtab::NameToIndexMap was decoded correctly and works as expected.
698   Symbol *symbol = nullptr;
699   symbol = symtab.FindFirstSymbolWithNameAndType(ConstString("main"),
700                                                  eSymbolTypeCode,
701                                                  Symtab::eDebugAny,
702                                                  Symtab::eVisibilityAny);
703   ASSERT_NE(symbol, nullptr);
704   symbol = symtab.FindFirstSymbolWithNameAndType(ConstString("foo"),
705                                                  eSymbolTypeCode,
706                                                  Symtab::eDebugAny,
707                                                  Symtab::eVisibilityAny);
708   ASSERT_NE(symbol, nullptr);
709   symbol = symtab.FindFirstSymbolWithNameAndType(ConstString("bar"),
710                                                  eSymbolTypeCode,
711                                                  Symtab::eDebugAny,
712                                                  Symtab::eVisibilityAny);
713   ASSERT_NE(symbol, nullptr);
714   symbol = symtab.FindFirstSymbolWithNameAndType(ConstString("baz"),
715                                                  eSymbolTypeCode,
716                                                  Symtab::eDebugAny,
717                                                  Symtab::eVisibilityAny);
718   ASSERT_NE(symbol, nullptr);
719 }
720