1 | //===- DWARFFile.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 LLVM_DWARFLINKER_DWARFFILE_H |
10 | #define LLVM_DWARFLINKER_DWARFFILE_H |
11 | |
12 | #include "AddressesMap.h" |
13 | #include "llvm/ADT/StringRef.h" |
14 | #include "llvm/DebugInfo/DWARF/DWARFContext.h" |
15 | #include <functional> |
16 | #include <memory> |
17 | |
18 | namespace llvm { |
19 | namespace dwarf_linker { |
20 | |
21 | /// This class represents DWARF information for source file |
22 | /// and it's address map. |
23 | /// |
24 | /// May be used asynchroniously for reading. |
25 | class DWARFFile { |
26 | public: |
27 | using UnloadCallbackTy = std::function<void(StringRef FileName)>; |
28 | |
29 | DWARFFile(StringRef Name, std::unique_ptr<DWARFContext> Dwarf, |
30 | std::unique_ptr<AddressesMap> Addresses, |
31 | UnloadCallbackTy UnloadFunc = nullptr) |
32 | : FileName(Name), Dwarf(std::move(Dwarf)), |
33 | Addresses(std::move(Addresses)), UnloadFunc(UnloadFunc) {} |
34 | |
35 | /// Object file name. |
36 | StringRef FileName; |
37 | |
38 | /// Source DWARF information. |
39 | std::unique_ptr<DWARFContext> Dwarf; |
40 | |
41 | /// Helpful address information(list of valid address ranges, relocations). |
42 | std::unique_ptr<AddressesMap> Addresses; |
43 | |
44 | /// Callback to the module keeping object file to unload. |
45 | UnloadCallbackTy UnloadFunc; |
46 | |
47 | /// Unloads object file and corresponding AddressesMap and Dwarf Context. |
48 | void unload() { |
49 | Addresses.reset(); |
50 | Dwarf.reset(); |
51 | |
52 | if (UnloadFunc) |
53 | UnloadFunc(FileName); |
54 | } |
55 | }; |
56 | |
57 | } // namespace dwarf_linker |
58 | } // end namespace llvm |
59 | |
60 | #endif // LLVM_DWARFLINKER_DWARFFILE_H |
61 |