CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
82 lines
3.1 KiB
C++
82 lines
3.1 KiB
C++
//===-llvm/unittest/DebugInfo/DWARFDieManualExtractTest.cpp---------------===//
|
|
//
|
|
// 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 "DwarfGenerator.h"
|
|
#include "DwarfUtils.h"
|
|
#include "llvm/BinaryFormat/Dwarf.h"
|
|
#include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h"
|
|
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
|
|
#include "llvm/ObjectYAML/DWARFEmitter.h"
|
|
#include "llvm/Testing/Support/Error.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
using namespace llvm;
|
|
using namespace llvm::dwarf;
|
|
using namespace utils;
|
|
|
|
namespace {
|
|
|
|
TEST(DWARFDie, manualExtractDump) {
|
|
typedef uint32_t AddrType;
|
|
uint16_t Version = 4;
|
|
Triple Triple = getDefaultTargetTripleForAddrSize(sizeof(AddrType));
|
|
if (!isConfigurationSupported(Triple))
|
|
GTEST_SKIP();
|
|
|
|
auto ExpectedDG = dwarfgen::Generator::create(Triple, Version);
|
|
ASSERT_THAT_EXPECTED(ExpectedDG, Succeeded());
|
|
dwarfgen::Generator *DG = ExpectedDG.get().get();
|
|
dwarfgen::CompileUnit &DGCU = DG->addCompileUnit();
|
|
dwarfgen::DIE CUDie = DGCU.getUnitDIE();
|
|
|
|
CUDie.addAttribute(DW_AT_name, DW_FORM_strp, "/tmp/main.c");
|
|
CUDie.addAttribute(DW_AT_language, DW_FORM_data2, DW_LANG_C);
|
|
|
|
dwarfgen::DIE SubprogramDie = CUDie.addChild(DW_TAG_subprogram);
|
|
SubprogramDie.addAttribute(DW_AT_name, DW_FORM_strp, "main");
|
|
SubprogramDie.addAttribute(DW_AT_low_pc, DW_FORM_addr, 0x1000U);
|
|
SubprogramDie.addAttribute(DW_AT_high_pc, DW_FORM_addr, 0x2000U);
|
|
|
|
StringRef FileBytes = DG->generate();
|
|
MemoryBufferRef FileBuffer(FileBytes, "dwarf");
|
|
auto Obj = object::ObjectFile::createObjectFile(FileBuffer);
|
|
EXPECT_TRUE((bool)Obj);
|
|
std::unique_ptr<DWARFContext> Ctx = DWARFContext::create(**Obj);
|
|
|
|
DWARFCompileUnit *CU = Ctx->getCompileUnitForOffset(0);
|
|
ASSERT_NE(nullptr, CU);
|
|
// Manually extracting DWARF DIE.
|
|
uint64_t DIEOffset = CU->getOffset() + CU->getHeaderSize();
|
|
uint64_t NextCUOffset = CU->getNextUnitOffset();
|
|
DWARFDebugInfoEntry DieInfo;
|
|
DWARFDataExtractor DebugInfoData = CU->getDebugInfoExtractor();
|
|
ASSERT_TRUE(DieInfo.extractFast(*CU, &DIEOffset, DebugInfoData, NextCUOffset,
|
|
UINT32_MAX));
|
|
DWARFDie Die(CU, &DieInfo);
|
|
ASSERT_TRUE(Die.isValid());
|
|
ASSERT_TRUE(Die.hasChildren());
|
|
// Since we have extracted manually DieArray is empty.
|
|
// Dump function should respect the default flags and print just current DIE,
|
|
// and not explore children.
|
|
SmallString<512> Output;
|
|
raw_svector_ostream OS(Output);
|
|
Die.dump(OS);
|
|
constexpr size_t NumOfLines = 3;
|
|
SmallVector<StringRef, NumOfLines> Strings;
|
|
SmallVector<StringRef, NumOfLines> ValidStrings = {
|
|
"0x0000000b: DW_TAG_compile_unit",
|
|
" DW_AT_name (\"/tmp/main.c\")",
|
|
" DW_AT_language (DW_LANG_C)"};
|
|
Output.str().split(Strings, '\n', -1, false);
|
|
ASSERT_EQ(Strings.size(), NumOfLines);
|
|
for (size_t I = 0; I < NumOfLines; ++I)
|
|
EXPECT_EQ(ValidStrings[I], Strings[I]);
|
|
}
|
|
|
|
} // end anonymous namespace
|