1 //===- DWARF.h --------------------------------------------------*- C++ -*-===//
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 #ifndef LLD_DWARF_H
10 #define LLD_DWARF_H
11 
12 #include "lld/Common/LLVM.h"
13 #include "llvm/ADT/DenseMap.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
16 #include "llvm/DebugInfo/DWARF/DWARFDebugLine.h"
17 #include <memory>
18 #include <string>
19 
20 namespace llvm {
21 struct DILineInfo;
22 } // namespace llvm
23 
24 namespace lld {
25 
26 class DWARFCache {
27 public:
28   DWARFCache(std::unique_ptr<llvm::DWARFContext> dwarf);
29   llvm::Optional<llvm::DILineInfo> getDILineInfo(uint64_t offset,
30                                                  uint64_t sectionIndex);
31   llvm::Optional<std::pair<std::string, unsigned>>
32   getVariableLoc(StringRef name);
33 
34 private:
35   std::unique_ptr<llvm::DWARFContext> dwarf;
36   std::vector<const llvm::DWARFDebugLine::LineTable *> lineTables;
37   struct VarLoc {
38     const llvm::DWARFDebugLine::LineTable *lt;
39     unsigned file;
40     unsigned line;
41   };
42   llvm::DenseMap<StringRef, VarLoc> variableLoc;
43 };
44 
45 } // namespace lld
46 
47 #endif
48