LLVM  13.0.0git
DebugHandlerBase.h
Go to the documentation of this file.
1 //===-- llvm/CodeGen/DebugHandlerBase.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 // Common functionality for different debug information format backends.
10 // LLVM currently supports DWARF and CodeView.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CODEGEN_DEBUGHANDLERBASE_H
15 #define LLVM_CODEGEN_DEBUGHANDLERBASE_H
16 
17 #include "llvm/ADT/Optional.h"
22 #include "llvm/IR/DebugLoc.h"
23 
24 namespace llvm {
25 
26 class AsmPrinter;
27 class MachineInstr;
28 class MachineModuleInfo;
29 
30 /// Represents the location at which a variable is stored.
32  /// Base register.
33  unsigned Register;
34 
35  /// Chain of offsetted loads necessary to load the value if it lives in
36  /// memory. Every load except for the last is pointer-sized.
38 
39  /// Present if the location is part of a larger variable.
41 
42  /// Extract a VariableLocation from a MachineInstr.
43  /// This will only work if Instruction is a debug value instruction
44  /// and the associated DIExpression is in one of the supported forms.
45  /// If these requirements are not met, the returned Optional will not
46  /// have a value.
49 };
50 
51 /// Base class for debug information backends. Common functionality related to
52 /// tracking which variables and scopes are alive at a given PC live here.
54 protected:
56 
57  /// Target of debug info emission.
59 
60  /// Collected machine module information.
62 
63  /// Previous instruction's location information. This is used to
64  /// determine label location to indicate scope boundaries in debug info.
65  /// We track the previous instruction's source location (if not line 0),
66  /// whether it was a label, and its parent BB.
68  MCSymbol *PrevLabel = nullptr;
69  const MachineBasicBlock *PrevInstBB = nullptr;
70 
71  /// This location indicates end of function prologue and beginning of
72  /// function body.
74 
75  /// If nonnull, stores the current machine instruction we're processing.
76  const MachineInstr *CurMI = nullptr;
77 
79 
80  /// History of DBG_VALUE and clobber instructions for each user
81  /// variable. Variables are listed in order of appearance.
83 
84  /// Mapping of inlined labels and DBG_LABEL machine instruction.
86 
87  /// Maps instruction with label emitted before instruction.
88  /// FIXME: Make this private from DwarfDebug, we have the necessary accessors
89  /// for it.
91 
92  /// Maps instruction with label emitted after instruction.
94 
95  /// Indentify instructions that are marking the beginning of or
96  /// ending of a scope.
97  void identifyScopeMarkers();
98 
99  /// Ensure that a label will be emitted before MI.
101  LabelsBeforeInsn.insert(std::make_pair(MI, nullptr));
102  }
103 
104  /// Ensure that a label will be emitted after MI.
106  LabelsAfterInsn.insert(std::make_pair(MI, nullptr));
107  }
108 
109  virtual void beginFunctionImpl(const MachineFunction *MF) = 0;
110  virtual void endFunctionImpl(const MachineFunction *MF) = 0;
111  virtual void skippedNonDebugFunction() {}
112 
113 private:
114  InstructionOrdering InstOrdering;
115 
116  // AsmPrinterHandler overrides.
117 public:
118  void beginModule(Module *M) override;
119 
120  void beginInstruction(const MachineInstr *MI) override;
121  void endInstruction() override;
122 
123  void beginFunction(const MachineFunction *MF) override;
124  void endFunction(const MachineFunction *MF) override;
125 
126  void beginBasicBlock(const MachineBasicBlock &MBB) override;
127  void endBasicBlock(const MachineBasicBlock &MBB) override;
128 
129  /// Return Label preceding the instruction.
131 
132  /// Return Label immediately following the instruction.
134 
135  /// If this type is derived from a base type then return base type size.
136  static uint64_t getBaseTypeSize(const DIType *Ty);
137 
138  /// Return true if type encoding is unsigned.
139  static bool isUnsignedDIType(const DIType *Ty);
140 
141  const InstructionOrdering &getInstOrdering() const { return InstOrdering; }
142 };
143 
144 } // namespace llvm
145 
146 #endif
llvm::DebugHandlerBase::beginFunction
void beginFunction(const MachineFunction *MF) override
Gather pre-function debug information.
Definition: DebugHandlerBase.cpp:244
llvm::DebugHandlerBase::endInstruction
void endInstruction() override
Process end of an instruction.
Definition: DebugHandlerBase.cpp:368
llvm::DebugHandlerBase::LScopes
LexicalScopes LScopes
Definition: DebugHandlerBase.h:78
llvm::DebugHandlerBase::beginInstruction
void beginInstruction(const MachineInstr *MI) override
Process beginning of an instruction.
Definition: DebugHandlerBase.cpp:342
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:102
llvm
Definition: AllocatorList.h:23
llvm::DIType
Base class for types.
Definition: DebugInfoMetadata.h:662
llvm::DbgVariableLocation::FragmentInfo
llvm::Optional< llvm::DIExpression::FragmentInfo > FragmentInfo
Present if the location is part of a larger variable.
Definition: DebugHandlerBase.h:40
llvm::DebugHandlerBase::getLabelAfterInsn
MCSymbol * getLabelAfterInsn(const MachineInstr *MI)
Return Label immediately following the instruction.
Definition: DebugHandlerBase.cpp:143
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
Optional.h
llvm::DbgLabelInstrMap
For each inlined instance of a source-level label, keep the corresponding DBG_LABEL instruction.
Definition: DbgEntityHistoryCalculator.h:133
DebugInfoMetadata.h
llvm::SmallVector< int64_t, 1 >
llvm::DebugHandlerBase::PrevInstLoc
DebugLoc PrevInstLoc
Previous instruction's location information.
Definition: DebugHandlerBase.h:67
llvm::DebugHandlerBase::beginModule
void beginModule(Module *M) override
Definition: DebugHandlerBase.cpp:104
llvm::DbgVariableLocation::extractFromMachineInstruction
static Optional< DbgVariableLocation > extractFromMachineInstruction(const MachineInstr &Instruction)
Extract a VariableLocation from a MachineInstr.
Definition: DebugHandlerBase.cpp:35
AsmPrinterHandler.h
llvm::DebugHandlerBase::requestLabelAfterInsn
void requestLabelAfterInsn(const MachineInstr *MI)
Ensure that a label will be emitted after MI.
Definition: DebugHandlerBase.h:105
llvm::Optional< llvm::DIExpression::FragmentInfo >
llvm::DebugHandlerBase::PrologEndLoc
DebugLoc PrologEndLoc
This location indicates end of function prologue and beginning of function body.
Definition: DebugHandlerBase.h:73
llvm::DebugHandlerBase::Asm
AsmPrinter * Asm
Target of debug info emission.
Definition: DebugHandlerBase.h:58
DbgEntityHistoryCalculator.h
llvm::DebugHandlerBase::requestLabelBeforeInsn
void requestLabelBeforeInsn(const MachineInstr *MI)
Ensure that a label will be emitted before MI.
Definition: DebugHandlerBase.h:100
llvm::Instruction
Definition: Instruction.h:45
llvm::MachineModuleInfo
This class contains meta information specific to a module.
Definition: MachineModuleInfo.h:78
LexicalScopes.h
llvm::DbgVariableLocation::Register
unsigned Register
Base register.
Definition: DebugHandlerBase.h:33
DebugLoc.h
llvm::DbgVariableLocation::LoadChain
SmallVector< int64_t, 1 > LoadChain
Chain of offsetted loads necessary to load the value if it lives in memory.
Definition: DebugHandlerBase.h:37
llvm::DebugHandlerBase::getLabelBeforeInsn
MCSymbol * getLabelBeforeInsn(const MachineInstr *MI)
Return Label preceding the instruction.
Definition: DebugHandlerBase.cpp:136
llvm::InstructionOrdering
Record instruction ordering so we can query their relative positions within a function.
Definition: DbgEntityHistoryCalculator.h:31
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
llvm::DebugHandlerBase::endFunctionImpl
virtual void endFunctionImpl(const MachineFunction *MF)=0
llvm::DebugHandlerBase::getBaseTypeSize
static uint64_t getBaseTypeSize(const DIType *Ty)
If this type is derived from a base type then return base type size.
Definition: DebugHandlerBase.cpp:148
llvm::DbgVariableLocation
Represents the location at which a variable is stored.
Definition: DebugHandlerBase.h:31
llvm::DebugHandlerBase::PrevInstBB
const MachineBasicBlock * PrevInstBB
Definition: DebugHandlerBase.h:69
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
llvm::DenseMap
Definition: DenseMap.h:714
llvm::DebugHandlerBase::beginFunctionImpl
virtual void beginFunctionImpl(const MachineFunction *MF)=0
llvm::DebugHandlerBase::endBasicBlock
void endBasicBlock(const MachineBasicBlock &MBB) override
Process end of a basic block during basic block sections.
Definition: DebugHandlerBase.cpp:420
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::DebugHandlerBase::DbgLabels
DbgLabelInstrMap DbgLabels
Mapping of inlined labels and DBG_LABEL machine instruction.
Definition: DebugHandlerBase.h:85
llvm::DebugHandlerBase::CurMI
const MachineInstr * CurMI
If nonnull, stores the current machine instruction we're processing.
Definition: DebugHandlerBase.h:76
llvm::DebugHandlerBase::skippedNonDebugFunction
virtual void skippedNonDebugFunction()
Definition: DebugHandlerBase.h:111
llvm::MachineFunction
Definition: MachineFunction.h:230
llvm::DebugHandlerBase::beginBasicBlock
void beginBasicBlock(const MachineBasicBlock &MBB) override
Process beginning of a basic block during basic block sections.
Definition: DebugHandlerBase.cpp:413
llvm::DbgValueHistoryMap
For each user variable, keep a list of instruction ranges where this variable is accessible.
Definition: DbgEntityHistoryCalculator.h:47
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
llvm::DebugHandlerBase::getInstOrdering
const InstructionOrdering & getInstOrdering() const
Definition: DebugHandlerBase.h:141
llvm::AsmPrinter
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:82
llvm::AsmPrinterHandler
Collects and handles AsmPrinter objects required to build debug or EH information.
Definition: AsmPrinterHandler.h:33
llvm::DebugHandlerBase::identifyScopeMarkers
void identifyScopeMarkers()
Indentify instructions that are marking the beginning of or ending of a scope.
Definition: DebugHandlerBase.cpp:113
llvm::DebugHandlerBase::PrevLabel
MCSymbol * PrevLabel
Definition: DebugHandlerBase.h:68
llvm::DebugHandlerBase::DebugHandlerBase
DebugHandlerBase(AsmPrinter *A)
Definition: DebugHandlerBase.cpp:102
llvm::DebugHandlerBase::MMI
MachineModuleInfo * MMI
Collected machine module information.
Definition: DebugHandlerBase.h:61
llvm::DebugHandlerBase
Base class for debug information backends.
Definition: DebugHandlerBase.h:53
llvm::DebugHandlerBase::LabelsAfterInsn
DenseMap< const MachineInstr *, MCSymbol * > LabelsAfterInsn
Maps instruction with label emitted after instruction.
Definition: DebugHandlerBase.h:93
llvm::DebugHandlerBase::isUnsignedDIType
static bool isUnsignedDIType(const DIType *Ty)
Return true if type encoding is unsigned.
Definition: DebugHandlerBase.cpp:176
llvm::DebugLoc
A debug info location.
Definition: DebugLoc.h:33
llvm::DebugHandlerBase::DbgValues
DbgValueHistoryMap DbgValues
History of DBG_VALUE and clobber instructions for each user variable.
Definition: DebugHandlerBase.h:82
llvm::LexicalScopes
LexicalScopes - This class provides interface to collect and use lexical scoping information from mac...
Definition: LexicalScopes.h:141
llvm::DebugHandlerBase::LabelsBeforeInsn
DenseMap< const MachineInstr *, MCSymbol * > LabelsBeforeInsn
Maps instruction with label emitted before instruction.
Definition: DebugHandlerBase.h:90
llvm::DebugHandlerBase::endFunction
void endFunction(const MachineFunction *MF) override
Gather post-function debug information.
Definition: DebugHandlerBase.cpp:403