1 //===-- TestSectionFileSize.cpp -------------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #include "gtest/gtest.h"
12 #include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
13 #include "Plugins/Process/Utility/lldb-x86-register-enums.h"
14 #include "TestingSupport/SubsystemRAII.h"
15 #include "TestingSupport/TestUtilities.h"
17 #include "lldb/Core/Module.h"
18 #include "lldb/Symbol/CallFrameInfo.h"
19 #include "lldb/Symbol/UnwindPlan.h"
20 #include "llvm/Testing/Support/Error.h"
22 using namespace lldb_private
;
25 class SectionSizeTest
: public testing::Test
{
26 SubsystemRAII
<FileSystem
, ObjectFilePECOFF
> subsystems
;
29 TEST_F(SectionSizeTest
, NoAlignmentPadding
) {
30 llvm::Expected
<TestFile
> ExpectedFile
= TestFile::fromYaml(
34 SectionAlignment: 4096
37 Machine: IMAGE_FILE_MACHINE_AMD64
38 Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_LARGE_ADDRESS_AWARE ]
43 Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]
44 SectionData: 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110000
49 ASSERT_THAT_EXPECTED(ExpectedFile
, llvm::Succeeded());
51 ModuleSP module_sp
= std::make_shared
<Module
>(ExpectedFile
->moduleSpec());
52 ObjectFile
*object_file
= module_sp
->GetObjectFile();
53 ASSERT_NE(object_file
, nullptr);
55 SectionList
*section_list
= object_file
->GetSectionList();
56 ASSERT_NE(section_list
, nullptr);
58 SectionSP swiftast_section
;
59 size_t section_count
= section_list
->GetNumSections(0);
60 for (size_t i
= 0; i
< section_count
; ++i
) {
61 SectionSP section_sp
= section_list
->GetSectionAtIndex(i
);
62 if (section_sp
->GetName() == "swiftast") {
63 swiftast_section
= section_sp
;
67 ASSERT_NE(swiftast_section
.get(), nullptr);
69 DataExtractor section_data
;
70 ASSERT_NE(object_file
->ReadSectionData(swiftast_section
.get(),
74 // Check that the section data size is equal to VirtualSize (496)
75 // without the zero padding, instead of SizeOfRawData (512).
76 EXPECT_EQ(section_data
.GetByteSize(), (uint64_t)496);