• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- DwarfTransformer.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_DEBUGINFO_GSYM_DWARFTRANSFORMER_H
10 #define LLVM_DEBUGINFO_GSYM_DWARFTRANSFORMER_H
11 
12 #include "llvm/ADT/StringRef.h"
13 #include "llvm/DebugInfo/GSYM/Range.h"
14 #include "llvm/Support/Error.h"
15 
16 namespace llvm {
17 
18 class raw_ostream;
19 
20 namespace gsym {
21 
22 struct CUInfo;
23 struct FunctionInfo;
24 class GsymCreator;
25 
26 /// A class that transforms the DWARF in a DWARFContext into GSYM information
27 /// by populating the GsymCreator object that it is constructed with. This
28 /// class supports converting all DW_TAG_subprogram DIEs into
29 /// gsym::FunctionInfo objects that includes line table information and inline
30 /// function information. Creating a separate class to transform this data
31 /// allows this class to be unit tested.
32 class DwarfTransformer {
33 public:
34 
35   /// Create a DWARF transformer.
36   ///
37   /// \param D The DWARF to use when converting to GSYM.
38   ///
39   /// \param OS The stream to log warnings and non fatal issues to.
40   ///
41   /// \param G The GSYM creator to populate with the function information
42   /// from the debug info.
DwarfTransformer(DWARFContext & D,raw_ostream & OS,GsymCreator & G)43   DwarfTransformer(DWARFContext &D, raw_ostream &OS, GsymCreator &G) :
44       DICtx(D), Log(OS), Gsym(G) {}
45 
46   /// Extract the DWARF from the supplied object file and convert it into the
47   /// Gsym format in the GsymCreator object that is passed in. Returns an
48   /// error if something fatal is encountered.
49   ///
50   /// \returns An error indicating any fatal issues that happen when parsing
51   /// the DWARF, or Error::success() if all goes well.
52   llvm::Error convert(uint32_t NumThreads);
53 
54   llvm::Error verify(StringRef GsymPath);
55 
56 
57 private:
58 
59   /// Parse the DWARF in the object file and convert it into the GsymCreator.
60   Error parse();
61 
62   /// Handle any DIE (debug info entry) from the DWARF.
63   ///
64   /// This function will find all DW_TAG_subprogram DIEs that convert them into
65   /// GSYM FuntionInfo objects and add them to the GsymCreator supplied during
66   /// construction. The DIE and all its children will be recursively parsed
67   /// with calls to this function.
68   ///
69   /// \param Strm The thread specific log stream for any non fatal errors and
70   /// warnings. Once a thread has finished parsing an entire compile unit, all
71   /// information in this temporary stream will be forwarded to the member
72   /// variable log. This keeps logging thread safe.
73   ///
74   /// \param CUI The compile unit specific information that contains the DWARF
75   /// line table, cached file list, and other compile unit specific
76   /// information.
77   ///
78   /// \param Die The DWARF debug info entry to parse.
79   void handleDie(raw_ostream &Strm, CUInfo &CUI, DWARFDie Die);
80 
81   DWARFContext &DICtx;
82   raw_ostream &Log;
83   GsymCreator &Gsym;
84 
85   friend class DwarfTransformerTest;
86 };
87 
88 } // namespace gsym
89 } // namespace llvm
90 
91 #endif // #ifndef LLVM_DEBUGINFO_GSYM_DWARFTRANSFORMER_H
92