xref: /llvm-project/llvm/include/llvm/DebugInfo/GSYM/DwarfTransformer.h (revision 558de0e1f993f413a9c8b93d969b28b651c6e437)
119602b71SGreg Clayton //===- DwarfTransformer.h ---------------------------------------*- C++ -*-===//
219602b71SGreg Clayton //
319602b71SGreg Clayton // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
419602b71SGreg Clayton // See https://llvm.org/LICENSE.txt for license information.
519602b71SGreg Clayton // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
619602b71SGreg Clayton //
719602b71SGreg Clayton //===----------------------------------------------------------------------===//
819602b71SGreg Clayton 
919602b71SGreg Clayton #ifndef LLVM_DEBUGINFO_GSYM_DWARFTRANSFORMER_H
1019602b71SGreg Clayton #define LLVM_DEBUGINFO_GSYM_DWARFTRANSFORMER_H
1119602b71SGreg Clayton 
1219602b71SGreg Clayton #include "llvm/ADT/StringRef.h"
135ee9c2c0SThomas Fransham #include "llvm/DebugInfo/DWARF/DWARFContext.h"
14854c3394SAlexey Lapshin #include "llvm/DebugInfo/GSYM/ExtractRanges.h"
1519602b71SGreg Clayton #include "llvm/Support/Error.h"
1619602b71SGreg Clayton 
1719602b71SGreg Clayton namespace llvm {
1819602b71SGreg Clayton 
1919602b71SGreg Clayton class raw_ostream;
2019602b71SGreg Clayton 
2119602b71SGreg Clayton namespace gsym {
2219602b71SGreg Clayton 
2319602b71SGreg Clayton struct CUInfo;
2419602b71SGreg Clayton struct FunctionInfo;
2519602b71SGreg Clayton class GsymCreator;
263bdc4c70SKevin Frei class OutputAggregator;
2719602b71SGreg Clayton 
2819602b71SGreg Clayton /// A class that transforms the DWARF in a DWARFContext into GSYM information
2919602b71SGreg Clayton /// by populating the GsymCreator object that it is constructed with. This
3019602b71SGreg Clayton /// class supports converting all DW_TAG_subprogram DIEs into
3119602b71SGreg Clayton /// gsym::FunctionInfo objects that includes line table information and inline
3219602b71SGreg Clayton /// function information. Creating a separate class to transform this data
3319602b71SGreg Clayton /// allows this class to be unit tested.
3419602b71SGreg Clayton class DwarfTransformer {
3519602b71SGreg Clayton public:
3619602b71SGreg Clayton   /// Create a DWARF transformer.
3719602b71SGreg Clayton   ///
3819602b71SGreg Clayton   /// \param D The DWARF to use when converting to GSYM.
3919602b71SGreg Clayton   ///
4019602b71SGreg Clayton   /// \param G The GSYM creator to populate with the function information
4119602b71SGreg Clayton   /// from the debug info.
42*558de0e1Salx32   ///
43*558de0e1Salx32   /// \param LDCS Flag to indicate whether we should load the call site
44*558de0e1Salx32   /// information from DWARF `DW_TAG_call_site` entries
45*558de0e1Salx32   DwarfTransformer(DWARFContext &D, GsymCreator &G, bool LDCS = false)
46*558de0e1Salx32       : DICtx(D), Gsym(G), LoadDwarfCallSites(LDCS) {}
4719602b71SGreg Clayton 
4819602b71SGreg Clayton   /// Extract the DWARF from the supplied object file and convert it into the
4919602b71SGreg Clayton   /// Gsym format in the GsymCreator object that is passed in. Returns an
5019602b71SGreg Clayton   /// error if something fatal is encountered.
5119602b71SGreg Clayton   ///
5227d6161bSGreg Clayton   /// \param NumThreads The number of threads that the conversion process can
5327d6161bSGreg Clayton   ///                   use.
5427d6161bSGreg Clayton   ///
5527d6161bSGreg Clayton   /// \param OS The stream to log warnings and non fatal issues to. If NULL
5627d6161bSGreg Clayton   ///           then don't log.
5727d6161bSGreg Clayton   ///
5819602b71SGreg Clayton   /// \returns An error indicating any fatal issues that happen when parsing
5919602b71SGreg Clayton   /// the DWARF, or Error::success() if all goes well.
603bdc4c70SKevin Frei   llvm::Error convert(uint32_t NumThreads, OutputAggregator &OS);
6119602b71SGreg Clayton 
623bdc4c70SKevin Frei   llvm::Error verify(StringRef GsymPath, OutputAggregator &OS);
6319602b71SGreg Clayton 
6419602b71SGreg Clayton private:
6519602b71SGreg Clayton 
6619602b71SGreg Clayton   /// Parse the DWARF in the object file and convert it into the GsymCreator.
6719602b71SGreg Clayton   Error parse();
6819602b71SGreg Clayton 
6919602b71SGreg Clayton   /// Handle any DIE (debug info entry) from the DWARF.
7019602b71SGreg Clayton   ///
7119602b71SGreg Clayton   /// This function will find all DW_TAG_subprogram DIEs that convert them into
7219602b71SGreg Clayton   /// GSYM FuntionInfo objects and add them to the GsymCreator supplied during
7319602b71SGreg Clayton   /// construction. The DIE and all its children will be recursively parsed
7419602b71SGreg Clayton   /// with calls to this function.
7519602b71SGreg Clayton   ///
7619602b71SGreg Clayton   /// \param Strm The thread specific log stream for any non fatal errors and
7719602b71SGreg Clayton   /// warnings. Once a thread has finished parsing an entire compile unit, all
7819602b71SGreg Clayton   /// information in this temporary stream will be forwarded to the member
7927d6161bSGreg Clayton   /// variable log. This keeps logging thread safe. If the value is NULL, then
8027d6161bSGreg Clayton   /// don't log.
8119602b71SGreg Clayton   ///
8219602b71SGreg Clayton   /// \param CUI The compile unit specific information that contains the DWARF
8319602b71SGreg Clayton   /// line table, cached file list, and other compile unit specific
8419602b71SGreg Clayton   /// information.
8519602b71SGreg Clayton   ///
8619602b71SGreg Clayton   /// \param Die The DWARF debug info entry to parse.
873bdc4c70SKevin Frei   void handleDie(OutputAggregator &Strm, CUInfo &CUI, DWARFDie Die);
8819602b71SGreg Clayton 
89*558de0e1Salx32   /// Parse call site information from DWARF
90*558de0e1Salx32   ///
91*558de0e1Salx32   /// \param CUI   The compile unit info for the current CU.
92*558de0e1Salx32   /// \param Die   The DWARFDie for the function.
93*558de0e1Salx32   /// \param FI    The FunctionInfo for the function being populated.
94*558de0e1Salx32   void parseCallSiteInfoFromDwarf(CUInfo &CUI, DWARFDie Die, FunctionInfo &FI);
95*558de0e1Salx32 
9619602b71SGreg Clayton   DWARFContext &DICtx;
9719602b71SGreg Clayton   GsymCreator &Gsym;
98*558de0e1Salx32   bool LoadDwarfCallSites;
9919602b71SGreg Clayton 
10019602b71SGreg Clayton   friend class DwarfTransformerTest;
10119602b71SGreg Clayton };
10219602b71SGreg Clayton 
10319602b71SGreg Clayton } // namespace gsym
10419602b71SGreg Clayton } // namespace llvm
10519602b71SGreg Clayton 
106aa5c09beSKazu Hirata #endif // LLVM_DEBUGINFO_GSYM_DWARFTRANSFORMER_H
107