2016-02-11 04:55:49 +08: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.
|
|
|
|
// LLVM currently supports DWARF and CodeView.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DEBUGHANDLERBASE_H
|
|
|
|
#define LLVM_LIB_CODEGEN_ASMPRINTER_DEBUGHANDLERBASE_H
|
|
|
|
|
|
|
|
#include "AsmPrinterHandler.h"
|
2018-08-17 23:22:04 +08:00
|
|
|
#include "DbgEntityHistoryCalculator.h"
|
2017-08-30 04:59:25 +08:00
|
|
|
#include "llvm/ADT/Optional.h"
|
2016-02-11 04:55:49 +08:00
|
|
|
#include "llvm/CodeGen/LexicalScopes.h"
|
2016-02-19 02:02:48 +08:00
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
2017-08-30 04:59:25 +08:00
|
|
|
#include "llvm/IR/DebugInfoMetadata.h"
|
2016-02-11 04:55:49 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class AsmPrinter;
|
2017-08-30 04:59:25 +08:00
|
|
|
class MachineInstr;
|
2016-02-11 04:55:49 +08:00
|
|
|
class MachineModuleInfo;
|
|
|
|
|
2017-08-30 04:59:25 +08:00
|
|
|
/// Represents the location at which a variable is stored.
|
|
|
|
struct DbgVariableLocation {
|
|
|
|
/// Base register.
|
|
|
|
unsigned Register;
|
|
|
|
|
2017-08-31 23:56:49 +08: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-30 04:59:25 +08:00
|
|
|
|
|
|
|
/// Present if the location is part of a larger variable.
|
|
|
|
llvm::Optional<llvm::DIExpression::FragmentInfo> FragmentInfo;
|
|
|
|
|
2017-08-31 01:50:21 +08: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-30 04:59:25 +08:00
|
|
|
};
|
|
|
|
|
2016-02-11 04:55:49 +08: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 23:41:56 +08:00
|
|
|
class DebugHandlerBase : public AsmPrinterHandler {
|
2016-02-11 04:55:49 +08: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-13 04:49:11 +08: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-11 04:55:49 +08:00
|
|
|
DebugLoc PrevInstLoc;
|
|
|
|
MCSymbol *PrevLabel = nullptr;
|
2016-12-13 04:49:11 +08:00
|
|
|
const MachineBasicBlock *PrevInstBB = nullptr;
|
2016-02-11 04:55:49 +08: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 23:22:04 +08:00
|
|
|
/// Mapping of inlined labels and DBG_LABEL machine instruction.
|
|
|
|
DbgLabelInstrMap DbgLabels;
|
|
|
|
|
2016-02-11 04:55:49 +08: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-17 02:48:33 +08:00
|
|
|
virtual void beginFunctionImpl(const MachineFunction *MF) = 0;
|
|
|
|
virtual void endFunctionImpl(const MachineFunction *MF) = 0;
|
|
|
|
virtual void skippedNonDebugFunction() {}
|
|
|
|
|
2016-02-11 04:55:49 +08: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);
|
|
|
|
|
2016-07-12 20:06:34 +08:00
|
|
|
/// If this type is derived from a base type then return base type size.
|
|
|
|
static uint64_t getBaseTypeSize(const DITypeRef TyRef);
|
2016-02-11 04:55:49 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|