#include "llvm/Support/Path.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/raw_ostream.h"
-using namespace llvm;
-
-// Given a special op, return the address skip amount (in units of
-// DWARF2_LINE_MIN_INSN_LENGTH.
-#define SPECIAL_ADDR(op) (((op) - DWARF2_LINE_OPCODE_BASE)/DWARF2_LINE_RANGE)
-
-// The maximum address skip amount that can be encoded with a special op.
-#define MAX_SPECIAL_ADDR_DELTA SPECIAL_ADDR(255)
-
-// First special line opcode - leave room for the standard opcodes.
-// Note: If you want to change this, you'll have to update the
-// "standard_opcode_lengths" table that is emitted in DwarfFileTable::Emit().
-#define DWARF2_LINE_OPCODE_BASE 13
-
-// Minimum line offset in a special line info. opcode. This value
-// was chosen to give a reasonable range of values.
-#define DWARF2_LINE_BASE -5
-// Range of line offsets in a special line info. opcode.
-#define DWARF2_LINE_RANGE 14
+using namespace llvm;
static inline uint64_t ScaleAddrDelta(MCContext &Context, uint64_t AddrDelta) {
unsigned MinInsnLength = Context.getAsmInfo()->getMinInstAlignment();
//
// This emits the Dwarf file and the line tables.
//
-void MCDwarfLineTable::Emit(MCObjectStreamer *MCOS) {
+void MCDwarfLineTable::Emit(MCObjectStreamer *MCOS,
+ MCDwarfLineTableParams Params) {
MCContext &context = MCOS->getContext();
auto &LineTables = context.getMCDwarfLineTables();
// Handle the rest of the Compile Units.
for (const auto &CUIDTablePair : LineTables)
- CUIDTablePair.second.EmitCU(MCOS);
+ CUIDTablePair.second.EmitCU(MCOS, Params);
}
-void MCDwarfDwoLineTable::Emit(MCStreamer &MCOS) const {
- MCOS.EmitLabel(Header.Emit(&MCOS, None).second);
+void MCDwarfDwoLineTable::Emit(MCStreamer &MCOS,
+ MCDwarfLineTableParams Params) const {
+ MCOS.EmitLabel(Header.Emit(&MCOS, Params, None).second);
}
-std::pair<MCSymbol *, MCSymbol *> MCDwarfLineTableHeader::Emit(MCStreamer *MCOS) const {
+std::pair<MCSymbol *, MCSymbol *>
+MCDwarfLineTableHeader::Emit(MCStreamer *MCOS,
+ MCDwarfLineTableParams Params) const {
static const char StandardOpcodeLengths[] = {
0, // length of DW_LNS_copy
1, // length of DW_LNS_advance_pc
0, // length of DW_LNS_set_epilogue_begin
1 // DW_LNS_set_isa
};
- assert(array_lengthof(StandardOpcodeLengths) ==
- (DWARF2_LINE_OPCODE_BASE - 1));
- return Emit(MCOS, StandardOpcodeLengths);
+ assert(array_lengthof(StandardOpcodeLengths) >=
+ (Params.DWARF2LineOpcodeBase - 1U));
+ return Emit(MCOS, Params, makeArrayRef(StandardOpcodeLengths,
+ Params.DWARF2LineOpcodeBase - 1));
}
static const MCExpr *forceExpAbs(MCStreamer &OS, const MCExpr* Expr) {
}
std::pair<MCSymbol *, MCSymbol *>
-MCDwarfLineTableHeader::Emit(MCStreamer *MCOS,
+MCDwarfLineTableHeader::Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params,
ArrayRef<char> StandardOpcodeLengths) const {
-
MCContext &context = MCOS->getContext();
// Create a symbol at the beginning of the line table.
// Parameters of the state machine, are next.
MCOS->EmitIntValue(context.getAsmInfo()->getMinInstAlignment(), 1);
MCOS->EmitIntValue(DWARF2_LINE_DEFAULT_IS_STMT, 1);
- MCOS->EmitIntValue(DWARF2_LINE_BASE, 1);
- MCOS->EmitIntValue(DWARF2_LINE_RANGE, 1);
+ MCOS->EmitIntValue(Params.DWARF2LineBase, 1);
+ MCOS->EmitIntValue(Params.DWARF2LineRange, 1);
MCOS->EmitIntValue(StandardOpcodeLengths.size() + 1, 1);
// Standard opcode lengths
return std::make_pair(LineStartSym, LineEndSym);
}
-void MCDwarfLineTable::EmitCU(MCObjectStreamer *MCOS) const {
- MCSymbol *LineEndSym = Header.Emit(MCOS).second;
+void MCDwarfLineTable::EmitCU(MCObjectStreamer *MCOS,
+ MCDwarfLineTableParams Params) const {
+ MCSymbol *LineEndSym = Header.Emit(MCOS, Params).second;
// Put out the line tables.
for (const auto &LineSec : MCLineSections.getMCLineEntries())
}
/// Utility function to emit the encoding to a streamer.
-void MCDwarfLineAddr::Emit(MCStreamer *MCOS, int64_t LineDelta,
- uint64_t AddrDelta) {
+void MCDwarfLineAddr::Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params,
+ int64_t LineDelta, uint64_t AddrDelta) {
MCContext &Context = MCOS->getContext();
SmallString<256> Tmp;
raw_svector_ostream OS(Tmp);
- MCDwarfLineAddr::Encode(Context, LineDelta, AddrDelta, OS);
+ MCDwarfLineAddr::Encode(Context, Params, LineDelta, AddrDelta, OS);
MCOS->EmitBytes(OS.str());
}
+/// Given a special op, return the address skip amount (in units of
+/// DWARF2_LINE_MIN_INSN_LENGTH).
+static uint64_t SpecialAddr(MCDwarfLineTableParams Params, uint64_t op) {
+ return (op - Params.DWARF2LineOpcodeBase) / Params.DWARF2LineRange;
+}
+
/// Utility function to encode a Dwarf pair of LineDelta and AddrDeltas.
-void MCDwarfLineAddr::Encode(MCContext &Context, int64_t LineDelta,
- uint64_t AddrDelta, raw_ostream &OS) {
+void MCDwarfLineAddr::Encode(MCContext &Context, MCDwarfLineTableParams Params,
+ int64_t LineDelta, uint64_t AddrDelta,
+ raw_ostream &OS) {
uint64_t Temp, Opcode;
bool NeedCopy = false;
+ // The maximum address skip amount that can be encoded with a special op.
+ uint64_t MaxSpecialAddrDelta = SpecialAddr(Params, 255);
+
// Scale the address delta by the minimum instruction length.
AddrDelta = ScaleAddrDelta(Context, AddrDelta);
// DW_LNE_end_sequence. We cannot use special opcodes here, since we want the
// end_sequence to emit the matrix entry.
if (LineDelta == INT64_MAX) {
- if (AddrDelta == MAX_SPECIAL_ADDR_DELTA)
+ if (AddrDelta == MaxSpecialAddrDelta)
OS << char(dwarf::DW_LNS_const_add_pc);
else if (AddrDelta) {
OS << char(dwarf::DW_LNS_advance_pc);
}
// Bias the line delta by the base.
- Temp = LineDelta - DWARF2_LINE_BASE;
+ Temp = LineDelta - Params.DWARF2LineBase;
// If the line increment is out of range of a special opcode, we must encode
// it with DW_LNS_advance_line.
- if (Temp >= DWARF2_LINE_RANGE) {
+ if (Temp >= Params.DWARF2LineRange) {
OS << char(dwarf::DW_LNS_advance_line);
encodeSLEB128(LineDelta, OS);
LineDelta = 0;
- Temp = 0 - DWARF2_LINE_BASE;
+ Temp = 0 - Params.DWARF2LineBase;
NeedCopy = true;
}
}
// Bias the opcode by the special opcode base.
- Temp += DWARF2_LINE_OPCODE_BASE;
+ Temp += Params.DWARF2LineOpcodeBase;
// Avoid overflow when addr_delta is large.
- if (AddrDelta < 256 + MAX_SPECIAL_ADDR_DELTA) {
+ if (AddrDelta < 256 + MaxSpecialAddrDelta) {
// Try using a special opcode.
- Opcode = Temp + AddrDelta * DWARF2_LINE_RANGE;
+ Opcode = Temp + AddrDelta * Params.DWARF2LineRange;
if (Opcode <= 255) {
OS << char(Opcode);
return;
}
// Try using DW_LNS_const_add_pc followed by special op.
- Opcode = Temp + (AddrDelta - MAX_SPECIAL_ADDR_DELTA) * DWARF2_LINE_RANGE;
+ Opcode = Temp + (AddrDelta - MaxSpecialAddrDelta) * Params.DWARF2LineRange;
if (Opcode <= 255) {
OS << char(dwarf::DW_LNS_const_add_pc);
OS << char(Opcode);
LineSectionSymbol = MCOS->getDwarfLineTableSymbol(0);
MCSymbol *AbbrevSectionSymbol = nullptr;
MCSymbol *InfoSectionSymbol = nullptr;
- MCSymbol *RangesSectionSymbol = NULL;
+ MCSymbol *RangesSectionSymbol = nullptr;
// Create end symbols for each section, and remove empty sections
MCOS->getContext().finalizeDwarfSections(*MCOS);
Streamer.EmitIntValue(dwarf::DW_CFA_restore | Reg, 1);
return;
}
+ case MCCFIInstruction::OpGnuArgsSize: {
+ Streamer.EmitIntValue(dwarf::DW_CFA_GNU_args_size, 1);
+ Streamer.EmitULEB128IntValue(Instr.getOffset());
+ return;
+ }
case MCCFIInstruction::OpEscape:
Streamer.EmitBytes(Instr.getValues());
return;
bool IsSignalFrame;
bool IsSimple;
};
-}
+} // anonymous namespace
namespace llvm {
template <>
LHS.IsSimple == RHS.IsSimple;
}
};
-}
+} // namespace llvm
void MCDwarfFrameEmitter::Emit(MCObjectStreamer &Streamer, MCAsmBackend *MAB,
bool IsEH) {