summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/PECOFF/PDBPass.h
blob: 0efa054db8231cf833a5670d07e5b2d0ae40b6e5 (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
//===- lib/ReaderWriter/PECOFF/PDBPass.h ----------------------------------===//
//
//                             The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef LLD_READER_WRITER_PE_COFF_PDB_PASS_H
#define LLD_READER_WRITER_PE_COFF_PDB_PASS_H

#include "lld/Core/Pass.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Process.h"

namespace lld {
namespace pecoff {

class PDBPass : public lld::Pass {
public:
  PDBPass(PECOFFLinkingContext &ctx) : _ctx(ctx) {}

  void perform(std::unique_ptr<MutableFile> &file) override {
    if (_ctx.getDebug())
      touch(_ctx.getPDBFilePath());
  }

private:
  void touch(StringRef path) {
    int fd;
    if (llvm::sys::fs::openFileForWrite(path, fd, llvm::sys::fs::F_Append))
      llvm::report_fatal_error("failed to create a PDB file");
    llvm::sys::Process::SafelyCloseFileDescriptor(fd);
  }

  PECOFFLinkingContext &_ctx;
};

} // namespace pecoff
} // namespace lld

#endif
OpenPOWER on IntegriCloud