LLVM 24.0.0git
DWARFFile.h
Go to the documentation of this file.
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"
16#include <functional>
17#include <memory>
18#include <string>
19
20namespace llvm {
21namespace dwarf_linker {
22
23/// This class represents DWARF information for source file
24/// and it's address map.
25///
26/// May be used asynchroniously for reading.
27class DWARFFile {
28public:
29 using UnloadCallbackTy = std::function<void(StringRef FileName)>;
30
32 std::function<void(uint64_t OriginalUnitOffset, uint64_t DebugInfoOffset,
33 uint64_t DebugAddrOffset)>;
34
35 DWARFFile(StringRef Name, std::unique_ptr<DWARFContext> Dwarf,
36 std::unique_ptr<AddressesMap> Addresses,
38 : FileName(Name), Dwarf(std::move(Dwarf)),
40
41 /// Object file name.
43
44 /// Source DWARF information.
45 std::unique_ptr<DWARFContext> Dwarf;
46
47 /// Helpful address information(list of valid address ranges, relocations).
48 std::unique_ptr<AddressesMap> Addresses;
49
50 /// Callback to the module keeping object file to unload.
52
53 /// Maps the path prefixes that the compiler remapped in this file's debug
54 /// info back to the original ones.
55 std::shared_ptr<PrefixMapper> PrefixMap;
56
57 /// \returns \p Path, a path from this file's debug info, with the prefix
58 /// mapping undone. This is used both to locate build artifacts referenced by
59 /// the debug info, such as Swift interfaces and Clang modules, and to
60 /// restore the original paths in the linked debug info.
61 std::string remapPath(StringRef Path) const {
62 return PrefixMap ? PrefixMap->mapToString(Path) : Path.str();
63 }
64
65 /// Reports where a unit landed in the output .debug_info and .debug_addr, for
66 /// the relocations saved relative to it. Unlike Addresses, it outlives
67 /// unload(), as a linker may only place the units after unloading them.
69
70 /// Unloads object file and corresponding AddressesMap and Dwarf Context.
71 void unload() {
72 Addresses.reset();
73 Dwarf.reset();
74
75 if (UnloadFunc)
77 }
78};
79
80} // namespace dwarf_linker
81} // end namespace llvm
82
83#endif // LLVM_DWARFLINKER_DWARFFILE_H
uint64_t uint64_t
Prefix mapping utility.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
std::unique_ptr< AddressesMap > Addresses
Helpful address information(list of valid address ranges, relocations).
Definition DWARFFile.h:48
UnloadCallbackTy UnloadFunc
Callback to the module keeping object file to unload.
Definition DWARFFile.h:51
std::string remapPath(StringRef Path) const
Definition DWARFFile.h:61
std::function< void(StringRef FileName)> UnloadCallbackTy
Definition DWARFFile.h:29
void unload()
Unloads object file and corresponding AddressesMap and Dwarf Context.
Definition DWARFFile.h:71
StringRef FileName
Object file name.
Definition DWARFFile.h:42
UnitOffsetsCallbackTy UnitOffsetsFunc
Reports where a unit landed in the output .debug_info and .debug_addr, for the relocations saved rela...
Definition DWARFFile.h:68
std::shared_ptr< PrefixMapper > PrefixMap
Maps the path prefixes that the compiler remapped in this file's debug info back to the original ones...
Definition DWARFFile.h:55
DWARFFile(StringRef Name, std::unique_ptr< DWARFContext > Dwarf, std::unique_ptr< AddressesMap > Addresses, UnloadCallbackTy UnloadFunc=nullptr)
Definition DWARFFile.h:35
std::function< void(uint64_t OriginalUnitOffset, uint64_t DebugInfoOffset, uint64_t DebugAddrOffset)> UnitOffsetsCallbackTy
Definition DWARFFile.h:31
std::unique_ptr< DWARFContext > Dwarf
Source DWARF information.
Definition DWARFFile.h:45
This is an optimization pass for GlobalISel generic memory operations.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1933
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:879