2016-02-10 21:55:49 +01:00
|
|
|
//===-- llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.h --------*- C++ -*--===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Common functionality for different debug information format backends.
|
2018-11-30 17:54:43 +01:00
|
|
|
// LLVM currently supports DWARF and CodeView.
|
2016-02-10 21:55:49 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DEBUGHANDLERBASE_H
|
|
|
|
#define LLVM_LIB_CODEGEN_ASMPRINTER_DEBUGHANDLERBASE_H
|
|
|
|
|
|
|
|
#include "AsmPrinterHandler.h"
|
2018-08-17 17:22:04 +02:00
|
|
|
#include "DbgEntityHistoryCalculator.h"
|
2017-08-29 22:59:25 +02:00
|
|
|
#include "llvm/ADT/Optional.h"
|
2016-02-10 21:55:49 +01:00
|
|
|
#include "llvm/CodeGen/LexicalScopes.h"
|
2016-02-18 19:02:48 +01:00
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
2017-08-29 22:59:25 +02:00
|
|
|
#include "llvm/IR/DebugInfoMetadata.h"
|
2016-02-10 21:55:49 +01:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class AsmPrinter;
|
2017-08-29 22:59:25 +02:00
|
|
|
class MachineInstr;
|
2016-02-10 21:55:49 +01:00
|
|
|
class MachineModuleInfo;
|
|
|
|
|
2017-08-29 22:59:25 +02:00
|
|
|
/// Represents the location at which a variable is stored.
|
|
|
|
struct DbgVariableLocation {
|
|
|
|
/// Base register.
|
|
|
|
unsigned Register;
|
|
|
|
|
2017-08-31 17:56:49 +02:00
|
|
|
/// Chain of offsetted loads necessary to load the value if it lives in
|
|
|
|
/// memory. Every load except for the last is pointer-sized.
|
|
|
|
SmallVector<int64_t, 1> LoadChain;
|
2017-08-29 22:59:25 +02:00
|
|
|
|
|
|
|
/// Present if the location is part of a larger variable.
|
|
|
|
llvm::Optional<llvm::DIExpression::FragmentInfo> FragmentInfo;
|
|
|
|
|
2017-08-30 19:50:21 +02:00
|
|
|
/// Extract a VariableLocation from a MachineInstr.
|
|
|
|
/// This will only work if Instruction is a debug value instruction
|
|
|
|
/// and the associated DIExpression is in one of the supported forms.
|
|
|
|
/// If these requirements are not met, the returned Optional will not
|
|
|
|
/// have a value.
|
|
|
|
static Optional<DbgVariableLocation>
|
|
|
|
extractFromMachineInstruction(const MachineInstr &Instruction);
|
2017-08-29 22:59:25 +02:00
|
|
|
};
|
|
|
|
|
2016-02-10 21:55:49 +01:00
|
|
|
/// Base class for debug information backends. Common functionality related to
|
|
|
|
/// tracking which variables and scopes are alive at a given PC live here.
|
2016-02-11 16:41:56 +01:00
|
|
|
class DebugHandlerBase : public AsmPrinterHandler {
|
2016-02-10 21:55:49 +01:00
|
|
|
protected:
|
|
|
|
DebugHandlerBase(AsmPrinter *A);
|
|
|
|
|
|
|
|
/// Target of debug info emission.
|
|
|
|
AsmPrinter *Asm;
|
|
|
|
|
|
|
|
/// Collected machine module information.
|
|
|
|
MachineModuleInfo *MMI;
|
|
|
|
|
|
|
|
/// Previous instruction's location information. This is used to
|
2016-12-12 21:49:11 +01:00
|
|
|
/// determine label location to indicate scope boundaries in debug info.
|
|
|
|
/// We track the previous instruction's source location (if not line 0),
|
|
|
|
/// whether it was a label, and its parent BB.
|
2016-02-10 21:55:49 +01:00
|
|
|
DebugLoc PrevInstLoc;
|
|
|
|
MCSymbol *PrevLabel = nullptr;
|
2016-12-12 21:49:11 +01:00
|
|
|
const MachineBasicBlock *PrevInstBB = nullptr;
|
2016-02-10 21:55:49 +01:00
|
|
|
|
|
|
|
/// This location indicates end of function prologue and beginning of
|
|
|
|
/// function body.
|
|
|
|
DebugLoc PrologEndLoc;
|
|
|
|
|
|
|
|
/// If nonnull, stores the current machine instruction we're processing.
|
|
|
|
const MachineInstr *CurMI = nullptr;
|
|
|
|
|
|
|
|
LexicalScopes LScopes;
|
|
|
|
|
|
|
|
/// History of DBG_VALUE and clobber instructions for each user
|
|
|
|
/// variable. Variables are listed in order of appearance.
|
|
|
|
DbgValueHistoryMap DbgValues;
|
|
|
|
|
2018-08-17 17:22:04 +02:00
|
|
|
/// Mapping of inlined labels and DBG_LABEL machine instruction.
|
|
|
|
DbgLabelInstrMap DbgLabels;
|
|
|
|
|
2016-02-10 21:55:49 +01:00
|
|
|
/// Maps instruction with label emitted before instruction.
|
|
|
|
/// FIXME: Make this private from DwarfDebug, we have the necessary accessors
|
|
|
|
/// for it.
|
|
|
|
DenseMap<const MachineInstr *, MCSymbol *> LabelsBeforeInsn;
|
|
|
|
|
|
|
|
/// Maps instruction with label emitted after instruction.
|
|
|
|
DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn;
|
|
|
|
|
|
|
|
/// Indentify instructions that are marking the beginning of or
|
|
|
|
/// ending of a scope.
|
|
|
|
void identifyScopeMarkers();
|
|
|
|
|
|
|
|
/// Ensure that a label will be emitted before MI.
|
|
|
|
void requestLabelBeforeInsn(const MachineInstr *MI) {
|
|
|
|
LabelsBeforeInsn.insert(std::make_pair(MI, nullptr));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Ensure that a label will be emitted after MI.
|
|
|
|
void requestLabelAfterInsn(const MachineInstr *MI) {
|
|
|
|
LabelsAfterInsn.insert(std::make_pair(MI, nullptr));
|
|
|
|
}
|
|
|
|
|
2017-02-16 19:48:33 +01:00
|
|
|
virtual void beginFunctionImpl(const MachineFunction *MF) = 0;
|
|
|
|
virtual void endFunctionImpl(const MachineFunction *MF) = 0;
|
|
|
|
virtual void skippedNonDebugFunction() {}
|
|
|
|
|
2016-02-10 21:55:49 +01:00
|
|
|
// AsmPrinterHandler overrides.
|
|
|
|
public:
|
|
|
|
void beginInstruction(const MachineInstr *MI) override;
|
|
|
|
void endInstruction() override;
|
|
|
|
|
|
|
|
void beginFunction(const MachineFunction *MF) override;
|
|
|
|
void endFunction(const MachineFunction *MF) override;
|
|
|
|
|
|
|
|
/// Return Label preceding the instruction.
|
|
|
|
MCSymbol *getLabelBeforeInsn(const MachineInstr *MI);
|
|
|
|
|
|
|
|
/// Return Label immediately following the instruction.
|
|
|
|
MCSymbol *getLabelAfterInsn(const MachineInstr *MI);
|
|
|
|
|
2018-10-22 23:44:21 +02:00
|
|
|
/// Return the function-local offset of an instruction. A label for the
|
|
|
|
/// instruction \p MI should exist (\ref getLabelAfterInsn).
|
|
|
|
const MCExpr *getFunctionLocalOffsetAfterInsn(const MachineInstr *MI);
|
|
|
|
|
2016-07-12 14:06:34 +02:00
|
|
|
/// If this type is derived from a base type then return base type size.
|
|
|
|
static uint64_t getBaseTypeSize(const DITypeRef TyRef);
|
2016-02-10 21:55:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|