summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp
blob: 8073b705dc29956061fcd3f1e068745433aba351 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//===- DWARFDebugLineTest.cpp ---------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "DwarfGenerator.h"
#include "DwarfUtils.h"
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugLine.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Testing/Support/Error.h"
#include "gtest/gtest.h"

using namespace llvm;
using namespace dwarf;
using namespace object;
using namespace utils;

namespace {

struct DebugLineGenerator {
  bool init() {
    Triple T = getHostTripleForAddrSize(8);
    if (!isConfigurationSupported(T))
      return false;
    auto ExpectedGenerator = dwarfgen::Generator::create(T, 4);
    if (ExpectedGenerator)
      Generator.reset(ExpectedGenerator->release());
    return true;
  }

  std::unique_ptr<DWARFContext> createContext() {
    if (!Generator)
      return nullptr;
    StringRef FileBytes = Generator->generate();
    MemoryBufferRef FileBuffer(FileBytes, "dwarf");
    auto Obj = object::ObjectFile::createObjectFile(FileBuffer);
    if (Obj)
      return DWARFContext::create(**Obj);
    return nullptr;
  }

  std::unique_ptr<dwarfgen::Generator> Generator;
};

TEST(DWARFDebugLine, GetLineTableAtInvalidOffset) {
  DebugLineGenerator LineGen;
  if (!LineGen.init())
    return;

  DWARFDebugLine Line;
  std::unique_ptr<DWARFContext> Context = LineGen.createContext();
  ASSERT_TRUE(Context != nullptr);
  const DWARFObject &Obj = Context->getDWARFObj();
  DWARFDataExtractor LineData(Obj, Obj.getLineSection(), true, 8);

  EXPECT_EQ(Line.getOrParseLineTable(LineData, 0, *Context, nullptr), nullptr);
}

} // end anonymous namespace
OpenPOWER on IntegriCloud