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