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