2017-08-18 05:26:39 +08:00
|
|
|
//===- llvm/CodeGen/DwarfExpression.cpp - Dwarf Debug Framework -----------===//
|
2015-01-13 06:19:22 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains support for writing dwarf debug info into asm files.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "DwarfExpression.h"
|
2017-08-18 05:26:39 +08:00
|
|
|
#include "llvm/ADT/APInt.h"
|
2015-01-13 06:19:22 +08:00
|
|
|
#include "llvm/ADT/SmallBitVector.h"
|
2017-06-07 11:48:56 +08:00
|
|
|
#include "llvm/BinaryFormat/Dwarf.h"
|
2017-08-18 05:26:39 +08:00
|
|
|
#include "llvm/IR/DebugInfoMetadata.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2015-01-13 06:19:22 +08:00
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
2017-08-18 05:26:39 +08:00
|
|
|
#include <algorithm>
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstdint>
|
2015-01-13 06:19:22 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2017-03-17 01:42:45 +08:00
|
|
|
void DwarfExpression::addReg(int DwarfReg, const char *Comment) {
|
2017-04-18 09:21:53 +08:00
|
|
|
assert(DwarfReg >= 0 && "invalid negative dwarf register number");
|
|
|
|
assert((LocationKind == Unknown || LocationKind == Register) &&
|
|
|
|
"location description already locked down");
|
|
|
|
LocationKind = Register;
|
|
|
|
if (DwarfReg < 32) {
|
|
|
|
emitOp(dwarf::DW_OP_reg0 + DwarfReg, Comment);
|
2015-01-13 06:19:22 +08:00
|
|
|
} else {
|
2017-03-17 01:42:45 +08:00
|
|
|
emitOp(dwarf::DW_OP_regx, Comment);
|
|
|
|
emitUnsigned(DwarfReg);
|
2015-01-13 06:19:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-23 01:19:55 +08:00
|
|
|
void DwarfExpression::addBReg(int DwarfReg, int Offset) {
|
2015-01-13 06:19:22 +08:00
|
|
|
assert(DwarfReg >= 0 && "invalid negative dwarf register number");
|
2017-04-18 09:21:53 +08:00
|
|
|
assert(LocationKind != Register && "location description already locked down");
|
2015-01-13 06:19:22 +08:00
|
|
|
if (DwarfReg < 32) {
|
2017-03-17 01:42:45 +08:00
|
|
|
emitOp(dwarf::DW_OP_breg0 + DwarfReg);
|
2015-01-13 06:19:22 +08:00
|
|
|
} else {
|
2017-03-17 01:42:45 +08:00
|
|
|
emitOp(dwarf::DW_OP_bregx);
|
|
|
|
emitUnsigned(DwarfReg);
|
2015-01-13 06:19:22 +08:00
|
|
|
}
|
2017-03-17 01:42:45 +08:00
|
|
|
emitSigned(Offset);
|
2015-01-13 06:19:22 +08:00
|
|
|
}
|
|
|
|
|
2017-03-22 09:15:57 +08:00
|
|
|
void DwarfExpression::addFBReg(int Offset) {
|
|
|
|
emitOp(dwarf::DW_OP_fbreg);
|
|
|
|
emitSigned(Offset);
|
|
|
|
}
|
|
|
|
|
2017-03-17 01:42:45 +08:00
|
|
|
void DwarfExpression::addOpPiece(unsigned SizeInBits, unsigned OffsetInBits) {
|
2016-12-10 04:43:40 +08:00
|
|
|
if (!SizeInBits)
|
|
|
|
return;
|
|
|
|
|
2015-01-13 06:19:22 +08:00
|
|
|
const unsigned SizeOfByte = 8;
|
|
|
|
if (OffsetInBits > 0 || SizeInBits % SizeOfByte) {
|
2017-03-17 01:42:45 +08:00
|
|
|
emitOp(dwarf::DW_OP_bit_piece);
|
|
|
|
emitUnsigned(SizeInBits);
|
|
|
|
emitUnsigned(OffsetInBits);
|
2015-01-13 06:19:22 +08:00
|
|
|
} else {
|
2017-03-17 01:42:45 +08:00
|
|
|
emitOp(dwarf::DW_OP_piece);
|
2015-01-13 06:19:22 +08:00
|
|
|
unsigned ByteSize = SizeInBits / SizeOfByte;
|
2017-03-17 01:42:45 +08:00
|
|
|
emitUnsigned(ByteSize);
|
2015-01-13 06:19:22 +08:00
|
|
|
}
|
2016-12-10 04:43:40 +08:00
|
|
|
this->OffsetInBits += SizeInBits;
|
2015-01-13 06:19:22 +08:00
|
|
|
}
|
|
|
|
|
2017-03-17 01:42:45 +08:00
|
|
|
void DwarfExpression::addShr(unsigned ShiftBy) {
|
|
|
|
emitOp(dwarf::DW_OP_constu);
|
|
|
|
emitUnsigned(ShiftBy);
|
|
|
|
emitOp(dwarf::DW_OP_shr);
|
2015-01-13 06:19:22 +08:00
|
|
|
}
|
|
|
|
|
2017-03-17 01:42:45 +08:00
|
|
|
void DwarfExpression::addAnd(unsigned Mask) {
|
|
|
|
emitOp(dwarf::DW_OP_constu);
|
|
|
|
emitUnsigned(Mask);
|
|
|
|
emitOp(dwarf::DW_OP_and);
|
2017-03-17 01:14:56 +08:00
|
|
|
}
|
|
|
|
|
2017-03-17 01:42:45 +08:00
|
|
|
bool DwarfExpression::addMachineReg(const TargetRegisterInfo &TRI,
|
2016-12-22 14:10:41 +08:00
|
|
|
unsigned MachineReg, unsigned MaxSize) {
|
2017-03-22 09:15:57 +08:00
|
|
|
if (!TRI.isPhysicalRegister(MachineReg)) {
|
|
|
|
if (isFrameRegister(TRI, MachineReg)) {
|
|
|
|
DwarfRegs.push_back({-1, 0, nullptr});
|
|
|
|
return true;
|
|
|
|
}
|
2015-01-26 03:04:08 +08:00
|
|
|
return false;
|
2017-03-22 09:15:57 +08:00
|
|
|
}
|
2015-01-26 03:04:08 +08:00
|
|
|
|
2015-03-03 06:02:33 +08:00
|
|
|
int Reg = TRI.getDwarfRegNum(MachineReg, false);
|
2015-01-13 06:19:22 +08:00
|
|
|
|
|
|
|
// If this is a valid register number, emit it.
|
|
|
|
if (Reg >= 0) {
|
2017-03-22 09:15:57 +08:00
|
|
|
DwarfRegs.push_back({Reg, 0, nullptr});
|
2015-01-14 09:01:28 +08:00
|
|
|
return true;
|
2015-01-13 06:19:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Walk up the super-register chain until we find a valid number.
|
2016-12-06 02:04:47 +08:00
|
|
|
// For example, EAX on x86_64 is a 32-bit fragment of RAX with offset 0.
|
2015-03-03 06:02:33 +08:00
|
|
|
for (MCSuperRegIterator SR(MachineReg, &TRI); SR.isValid(); ++SR) {
|
|
|
|
Reg = TRI.getDwarfRegNum(*SR, false);
|
2015-01-13 06:19:22 +08:00
|
|
|
if (Reg >= 0) {
|
2015-03-03 06:02:33 +08:00
|
|
|
unsigned Idx = TRI.getSubRegIndex(*SR, MachineReg);
|
|
|
|
unsigned Size = TRI.getSubRegIdxSize(Idx);
|
|
|
|
unsigned RegOffset = TRI.getSubRegIdxOffset(Idx);
|
2017-03-22 09:15:57 +08:00
|
|
|
DwarfRegs.push_back({Reg, 0, "super-register"});
|
2016-12-10 04:43:40 +08:00
|
|
|
// Use a DW_OP_bit_piece to describe the sub-register.
|
|
|
|
setSubRegisterPiece(Size, RegOffset);
|
2015-01-14 09:01:28 +08:00
|
|
|
return true;
|
2015-01-13 06:19:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, attempt to find a covering set of sub-register numbers.
|
|
|
|
// For example, Q0 on ARM is a composition of D0+D1.
|
2016-12-10 04:43:40 +08:00
|
|
|
unsigned CurPos = 0;
|
2017-04-25 02:55:33 +08:00
|
|
|
// The size of the register in bits.
|
|
|
|
const TargetRegisterClass *RC = TRI.getMinimalPhysRegClass(MachineReg);
|
|
|
|
unsigned RegSize = TRI.getRegSizeInBits(*RC);
|
2015-01-13 06:19:22 +08:00
|
|
|
// Keep track of the bits in the register we already emitted, so we
|
|
|
|
// can avoid emitting redundant aliasing subregs.
|
|
|
|
SmallBitVector Coverage(RegSize, false);
|
2015-03-03 06:02:33 +08:00
|
|
|
for (MCSubRegIterator SR(MachineReg, &TRI); SR.isValid(); ++SR) {
|
|
|
|
unsigned Idx = TRI.getSubRegIndex(MachineReg, *SR);
|
|
|
|
unsigned Size = TRI.getSubRegIdxSize(Idx);
|
|
|
|
unsigned Offset = TRI.getSubRegIdxOffset(Idx);
|
|
|
|
Reg = TRI.getDwarfRegNum(*SR, false);
|
2015-01-13 06:19:22 +08:00
|
|
|
|
|
|
|
// Intersection between the bits we already emitted and the bits
|
|
|
|
// covered by this subregister.
|
2017-08-29 07:07:43 +08:00
|
|
|
SmallBitVector CurSubReg(RegSize, false);
|
|
|
|
CurSubReg.set(Offset, Offset + Size);
|
2015-01-13 06:19:22 +08:00
|
|
|
|
|
|
|
// If this sub-register has a DWARF number and we haven't covered
|
|
|
|
// its range, emit a DWARF piece for it.
|
2017-08-29 07:07:43 +08:00
|
|
|
if (Reg >= 0 && CurSubReg.test(Coverage)) {
|
2017-03-22 09:15:57 +08:00
|
|
|
// Emit a piece for any gap in the coverage.
|
|
|
|
if (Offset > CurPos)
|
|
|
|
DwarfRegs.push_back({-1, Offset - CurPos, nullptr});
|
|
|
|
DwarfRegs.push_back(
|
|
|
|
{Reg, std::min<unsigned>(Size, MaxSize - Offset), "sub-register"});
|
2016-12-22 14:10:41 +08:00
|
|
|
if (Offset >= MaxSize)
|
2017-08-28 14:47:47 +08:00
|
|
|
break;
|
2015-01-13 06:19:22 +08:00
|
|
|
|
|
|
|
// Mark it as emitted.
|
|
|
|
Coverage.set(Offset, Offset + Size);
|
2017-03-22 09:15:57 +08:00
|
|
|
CurPos = Offset + Size;
|
2015-01-13 06:19:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-10 04:43:40 +08:00
|
|
|
return CurPos;
|
2015-01-13 06:19:22 +08:00
|
|
|
}
|
2015-01-13 08:04:06 +08:00
|
|
|
|
2017-03-17 01:42:45 +08:00
|
|
|
void DwarfExpression::addStackValue() {
|
2016-04-08 08:38:37 +08:00
|
|
|
if (DwarfVersion >= 4)
|
2017-03-17 01:42:45 +08:00
|
|
|
emitOp(dwarf::DW_OP_stack_value);
|
2016-04-08 08:38:37 +08:00
|
|
|
}
|
|
|
|
|
2017-03-17 01:42:45 +08:00
|
|
|
void DwarfExpression::addSignedConstant(int64_t Value) {
|
2017-04-18 09:21:53 +08:00
|
|
|
assert(LocationKind == Implicit || LocationKind == Unknown);
|
|
|
|
LocationKind = Implicit;
|
2017-03-17 01:42:45 +08:00
|
|
|
emitOp(dwarf::DW_OP_consts);
|
|
|
|
emitSigned(Value);
|
2015-01-13 08:04:06 +08:00
|
|
|
}
|
|
|
|
|
2017-03-17 01:42:45 +08:00
|
|
|
void DwarfExpression::addUnsignedConstant(uint64_t Value) {
|
2017-04-18 09:21:53 +08:00
|
|
|
assert(LocationKind == Implicit || LocationKind == Unknown);
|
|
|
|
LocationKind = Implicit;
|
2017-03-17 01:42:45 +08:00
|
|
|
emitOp(dwarf::DW_OP_constu);
|
|
|
|
emitUnsigned(Value);
|
2016-04-08 08:38:37 +08:00
|
|
|
}
|
|
|
|
|
2017-03-17 01:42:45 +08:00
|
|
|
void DwarfExpression::addUnsignedConstant(const APInt &Value) {
|
2017-04-18 09:21:53 +08:00
|
|
|
assert(LocationKind == Implicit || LocationKind == Unknown);
|
|
|
|
LocationKind = Implicit;
|
|
|
|
|
2016-04-08 08:38:37 +08:00
|
|
|
unsigned Size = Value.getBitWidth();
|
|
|
|
const uint64_t *Data = Value.getRawData();
|
|
|
|
|
|
|
|
// Chop it up into 64-bit pieces, because that's the maximum that
|
2017-03-17 01:42:45 +08:00
|
|
|
// addUnsignedConstant takes.
|
2016-04-08 08:38:37 +08:00
|
|
|
unsigned Offset = 0;
|
|
|
|
while (Offset < Size) {
|
2017-03-17 01:42:45 +08:00
|
|
|
addUnsignedConstant(*Data++);
|
2016-04-08 08:38:37 +08:00
|
|
|
if (Offset == 0 && Size <= 64)
|
|
|
|
break;
|
2017-04-18 09:21:53 +08:00
|
|
|
addStackValue();
|
|
|
|
addOpPiece(std::min(Size - Offset, 64u), Offset);
|
2016-04-08 08:38:37 +08:00
|
|
|
Offset += 64;
|
|
|
|
}
|
2015-01-13 08:04:06 +08:00
|
|
|
}
|
Debug Info: Move the complex expression handling (=the remainder) of
emitDebugLocValue() into DwarfExpression.
Ought to be NFC, but it actually uncovered a bug in the debug-loc-asan.ll
testcase. The testcase checks that the address of variable "y" is stored
at [RSP+16], which also lines up with the comment.
It also check(ed) that the *value* of "y" is stored in RDI before that,
but that is actually incorrect, since RDI is the very value that is
stored in [RSP+16]. Here's the assembler output:
movb 2147450880(%rcx), %r8b
#DEBUG_VALUE: bar:y <- RDI
cmpb $0, %r8b
movq %rax, 32(%rsp) # 8-byte Spill
movq %rsi, 24(%rsp) # 8-byte Spill
movq %rdi, 16(%rsp) # 8-byte Spill
.Ltmp3:
#DEBUG_VALUE: bar:y <- [RSP+16]
Fixed the comment to spell out the correct register and the check to
expect an address rather than a value.
Note that the range that is emitted for the RDI location was and is still
wrong, it claims to begin at the function prologue, but really it should
start where RDI is first assigned.
llvm-svn: 225851
2015-01-14 07:39:11 +08:00
|
|
|
|
2017-04-20 07:42:25 +08:00
|
|
|
bool DwarfExpression::addMachineRegExpression(const TargetRegisterInfo &TRI,
|
2016-11-03 00:12:20 +08:00
|
|
|
DIExpressionCursor &ExprCursor,
|
2017-04-20 07:42:25 +08:00
|
|
|
unsigned MachineReg,
|
2016-12-06 02:04:47 +08:00
|
|
|
unsigned FragmentOffsetInBits) {
|
2017-03-22 09:15:57 +08:00
|
|
|
auto Fragment = ExprCursor.getFragmentInfo();
|
2017-04-26 03:40:53 +08:00
|
|
|
if (!addMachineReg(TRI, MachineReg, Fragment ? Fragment->SizeInBits : ~1U)) {
|
|
|
|
LocationKind = Unknown;
|
2017-03-22 09:15:57 +08:00
|
|
|
return false;
|
2017-04-26 03:40:53 +08:00
|
|
|
}
|
2015-01-22 08:00:59 +08:00
|
|
|
|
2017-03-22 09:15:57 +08:00
|
|
|
bool HasComplexExpression = false;
|
2017-03-22 01:14:30 +08:00
|
|
|
auto Op = ExprCursor.peek();
|
2017-03-22 09:15:57 +08:00
|
|
|
if (Op && Op->getOp() != dwarf::DW_OP_LLVM_fragment)
|
|
|
|
HasComplexExpression = true;
|
|
|
|
|
2017-03-22 09:16:01 +08:00
|
|
|
// If the register can only be described by a complex expression (i.e.,
|
|
|
|
// multiple subregisters) it doesn't safely compose with another complex
|
|
|
|
// expression. For example, it is not possible to apply a DW_OP_deref
|
|
|
|
// operation to multiple DW_OP_pieces.
|
|
|
|
if (HasComplexExpression && DwarfRegs.size() > 1) {
|
|
|
|
DwarfRegs.clear();
|
2017-04-26 03:40:53 +08:00
|
|
|
LocationKind = Unknown;
|
2017-03-22 09:16:01 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-22 09:15:57 +08:00
|
|
|
// Handle simple register locations.
|
2017-04-18 09:21:53 +08:00
|
|
|
if (LocationKind != Memory && !HasComplexExpression) {
|
2017-03-22 09:15:57 +08:00
|
|
|
for (auto &Reg : DwarfRegs) {
|
|
|
|
if (Reg.DwarfRegNo >= 0)
|
|
|
|
addReg(Reg.DwarfRegNo, Reg.Comment);
|
|
|
|
addOpPiece(Reg.Size);
|
|
|
|
}
|
|
|
|
DwarfRegs.clear();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-04-18 09:21:53 +08:00
|
|
|
// Don't emit locations that cannot be expressed without DW_OP_stack_value.
|
2017-04-21 04:42:33 +08:00
|
|
|
if (DwarfVersion < 4)
|
|
|
|
if (std::any_of(ExprCursor.begin(), ExprCursor.end(),
|
|
|
|
[](DIExpression::ExprOperand Op) -> bool {
|
|
|
|
return Op.getOp() == dwarf::DW_OP_stack_value;
|
|
|
|
})) {
|
|
|
|
DwarfRegs.clear();
|
2017-04-26 03:40:53 +08:00
|
|
|
LocationKind = Unknown;
|
2017-04-21 04:42:33 +08:00
|
|
|
return false;
|
|
|
|
}
|
2017-04-18 09:21:53 +08:00
|
|
|
|
2017-03-22 09:15:57 +08:00
|
|
|
assert(DwarfRegs.size() == 1);
|
|
|
|
auto Reg = DwarfRegs[0];
|
2017-04-18 09:21:53 +08:00
|
|
|
bool FBReg = isFrameRegister(TRI, MachineReg);
|
|
|
|
int SignedOffset = 0;
|
2017-03-22 09:15:57 +08:00
|
|
|
assert(Reg.Size == 0 && "subregister has same size as superregister");
|
|
|
|
|
|
|
|
// Pattern-match combinations for which more efficient representations exist.
|
2017-06-14 00:54:44 +08:00
|
|
|
// [Reg, DW_OP_plus_uconst, Offset] --> [DW_OP_breg, Offset].
|
|
|
|
if (Op && (Op->getOp() == dwarf::DW_OP_plus_uconst)) {
|
|
|
|
SignedOffset = Op->getArg(0);
|
|
|
|
ExprCursor.take();
|
|
|
|
}
|
|
|
|
|
2017-06-14 21:14:38 +08:00
|
|
|
// [Reg, DW_OP_constu, Offset, DW_OP_plus] --> [DW_OP_breg, Offset]
|
|
|
|
// [Reg, DW_OP_constu, Offset, DW_OP_minus] --> [DW_OP_breg,-Offset]
|
2017-04-18 09:21:53 +08:00
|
|
|
// If Reg is a subregister we need to mask it out before subtracting.
|
2017-06-14 21:14:38 +08:00
|
|
|
if (Op && Op->getOp() == dwarf::DW_OP_constu) {
|
|
|
|
auto N = ExprCursor.peekNext();
|
|
|
|
if (N && (N->getOp() == dwarf::DW_OP_plus ||
|
|
|
|
(N->getOp() == dwarf::DW_OP_minus && !SubRegisterSizeInBits))) {
|
|
|
|
int Offset = Op->getArg(0);
|
|
|
|
SignedOffset = (N->getOp() == dwarf::DW_OP_minus) ? -Offset : Offset;
|
|
|
|
ExprCursor.consume(2);
|
|
|
|
}
|
2016-12-22 14:10:41 +08:00
|
|
|
}
|
2017-06-14 21:14:38 +08:00
|
|
|
|
2017-04-18 09:21:53 +08:00
|
|
|
if (FBReg)
|
|
|
|
addFBReg(SignedOffset);
|
|
|
|
else
|
|
|
|
addBReg(Reg.DwarfRegNo, SignedOffset);
|
|
|
|
DwarfRegs.clear();
|
|
|
|
return true;
|
|
|
|
}
|
2017-03-22 09:15:57 +08:00
|
|
|
|
2017-04-18 09:21:53 +08:00
|
|
|
/// Assuming a well-formed expression, match "DW_OP_deref* DW_OP_LLVM_fragment?".
|
|
|
|
static bool isMemoryLocation(DIExpressionCursor ExprCursor) {
|
|
|
|
while (ExprCursor) {
|
|
|
|
auto Op = ExprCursor.take();
|
|
|
|
switch (Op->getOp()) {
|
|
|
|
case dwarf::DW_OP_deref:
|
|
|
|
case dwarf::DW_OP_LLVM_fragment:
|
2017-03-22 09:15:57 +08:00
|
|
|
break;
|
2017-04-18 09:21:53 +08:00
|
|
|
default:
|
|
|
|
return false;
|
2017-03-22 09:15:57 +08:00
|
|
|
}
|
2015-01-22 08:00:59 +08:00
|
|
|
}
|
2017-03-22 09:15:57 +08:00
|
|
|
return true;
|
Debug Info: Move the complex expression handling (=the remainder) of
emitDebugLocValue() into DwarfExpression.
Ought to be NFC, but it actually uncovered a bug in the debug-loc-asan.ll
testcase. The testcase checks that the address of variable "y" is stored
at [RSP+16], which also lines up with the comment.
It also check(ed) that the *value* of "y" is stored in RDI before that,
but that is actually incorrect, since RDI is the very value that is
stored in [RSP+16]. Here's the assembler output:
movb 2147450880(%rcx), %r8b
#DEBUG_VALUE: bar:y <- RDI
cmpb $0, %r8b
movq %rax, 32(%rsp) # 8-byte Spill
movq %rsi, 24(%rsp) # 8-byte Spill
movq %rdi, 16(%rsp) # 8-byte Spill
.Ltmp3:
#DEBUG_VALUE: bar:y <- [RSP+16]
Fixed the comment to spell out the correct register and the check to
expect an address rather than a value.
Note that the range that is emitted for the RDI location was and is still
wrong, it claims to begin at the function prologue, but really it should
start where RDI is first assigned.
llvm-svn: 225851
2015-01-14 07:39:11 +08:00
|
|
|
}
|
|
|
|
|
2017-03-17 01:42:45 +08:00
|
|
|
void DwarfExpression::addExpression(DIExpressionCursor &&ExprCursor,
|
2016-12-06 02:04:47 +08:00
|
|
|
unsigned FragmentOffsetInBits) {
|
2017-04-18 09:21:53 +08:00
|
|
|
// If we need to mask out a subregister, do it now, unless the next
|
|
|
|
// operation would emit an OpPiece anyway.
|
|
|
|
auto N = ExprCursor.peek();
|
|
|
|
if (SubRegisterSizeInBits && N && (N->getOp() != dwarf::DW_OP_LLVM_fragment))
|
|
|
|
maskSubRegister();
|
|
|
|
|
2016-11-03 00:12:20 +08:00
|
|
|
while (ExprCursor) {
|
|
|
|
auto Op = ExprCursor.take();
|
|
|
|
switch (Op->getOp()) {
|
2016-12-06 02:04:47 +08:00
|
|
|
case dwarf::DW_OP_LLVM_fragment: {
|
2016-12-10 04:43:40 +08:00
|
|
|
unsigned SizeInBits = Op->getArg(1);
|
|
|
|
unsigned FragmentOffset = Op->getArg(0);
|
|
|
|
// The fragment offset must have already been adjusted by emitting an
|
|
|
|
// empty DW_OP_piece / DW_OP_bit_piece before we emitted the base
|
|
|
|
// location.
|
|
|
|
assert(OffsetInBits >= FragmentOffset && "fragment offset not added?");
|
|
|
|
|
2017-04-18 09:21:53 +08:00
|
|
|
// If addMachineReg already emitted DW_OP_piece operations to represent
|
2016-12-10 04:43:40 +08:00
|
|
|
// a super-register by splicing together sub-registers, subtract the size
|
|
|
|
// of the pieces that was already emitted.
|
|
|
|
SizeInBits -= OffsetInBits - FragmentOffset;
|
|
|
|
|
2017-04-18 09:21:53 +08:00
|
|
|
// If addMachineReg requested a DW_OP_bit_piece to stencil out a
|
2016-12-10 04:43:40 +08:00
|
|
|
// sub-register that is smaller than the current fragment's size, use it.
|
|
|
|
if (SubRegisterSizeInBits)
|
|
|
|
SizeInBits = std::min<unsigned>(SizeInBits, SubRegisterSizeInBits);
|
2017-04-18 09:21:53 +08:00
|
|
|
|
|
|
|
// Emit a DW_OP_stack_value for implicit location descriptions.
|
|
|
|
if (LocationKind == Implicit)
|
|
|
|
addStackValue();
|
|
|
|
|
|
|
|
// Emit the DW_OP_piece.
|
2017-03-17 01:42:45 +08:00
|
|
|
addOpPiece(SizeInBits, SubRegisterOffsetInBits);
|
2016-12-10 04:43:40 +08:00
|
|
|
setSubRegisterPiece(0, 0);
|
2017-04-18 09:21:53 +08:00
|
|
|
// Reset the location description kind.
|
|
|
|
LocationKind = Unknown;
|
|
|
|
return;
|
Debug Info: Move the complex expression handling (=the remainder) of
emitDebugLocValue() into DwarfExpression.
Ought to be NFC, but it actually uncovered a bug in the debug-loc-asan.ll
testcase. The testcase checks that the address of variable "y" is stored
at [RSP+16], which also lines up with the comment.
It also check(ed) that the *value* of "y" is stored in RDI before that,
but that is actually incorrect, since RDI is the very value that is
stored in [RSP+16]. Here's the assembler output:
movb 2147450880(%rcx), %r8b
#DEBUG_VALUE: bar:y <- RDI
cmpb $0, %r8b
movq %rax, 32(%rsp) # 8-byte Spill
movq %rsi, 24(%rsp) # 8-byte Spill
movq %rdi, 16(%rsp) # 8-byte Spill
.Ltmp3:
#DEBUG_VALUE: bar:y <- [RSP+16]
Fixed the comment to spell out the correct register and the check to
expect an address rather than a value.
Note that the range that is emitted for the RDI location was and is still
wrong, it claims to begin at the function prologue, but really it should
start where RDI is first assigned.
llvm-svn: 225851
2015-01-14 07:39:11 +08:00
|
|
|
}
|
2017-06-14 00:54:44 +08:00
|
|
|
case dwarf::DW_OP_plus_uconst:
|
2017-04-18 09:21:53 +08:00
|
|
|
assert(LocationKind != Register);
|
2017-03-17 01:42:45 +08:00
|
|
|
emitOp(dwarf::DW_OP_plus_uconst);
|
|
|
|
emitUnsigned(Op->getArg(0));
|
Debug Info: Move the complex expression handling (=the remainder) of
emitDebugLocValue() into DwarfExpression.
Ought to be NFC, but it actually uncovered a bug in the debug-loc-asan.ll
testcase. The testcase checks that the address of variable "y" is stored
at [RSP+16], which also lines up with the comment.
It also check(ed) that the *value* of "y" is stored in RDI before that,
but that is actually incorrect, since RDI is the very value that is
stored in [RSP+16]. Here's the assembler output:
movb 2147450880(%rcx), %r8b
#DEBUG_VALUE: bar:y <- RDI
cmpb $0, %r8b
movq %rax, 32(%rsp) # 8-byte Spill
movq %rsi, 24(%rsp) # 8-byte Spill
movq %rdi, 16(%rsp) # 8-byte Spill
.Ltmp3:
#DEBUG_VALUE: bar:y <- [RSP+16]
Fixed the comment to spell out the correct register and the check to
expect an address rather than a value.
Note that the range that is emitted for the RDI location was and is still
wrong, it claims to begin at the function prologue, but really it should
start where RDI is first assigned.
llvm-svn: 225851
2015-01-14 07:39:11 +08:00
|
|
|
break;
|
2017-06-14 21:14:38 +08:00
|
|
|
case dwarf::DW_OP_plus:
|
2015-10-01 03:55:43 +08:00
|
|
|
case dwarf::DW_OP_minus:
|
2017-06-14 21:14:38 +08:00
|
|
|
emitOp(Op->getOp());
|
2015-10-01 03:55:43 +08:00
|
|
|
break;
|
2017-08-18 05:26:39 +08:00
|
|
|
case dwarf::DW_OP_deref:
|
2017-04-18 09:21:53 +08:00
|
|
|
assert(LocationKind != Register);
|
|
|
|
if (LocationKind != Memory && isMemoryLocation(ExprCursor))
|
|
|
|
// Turning this into a memory location description makes the deref
|
|
|
|
// implicit.
|
|
|
|
LocationKind = Memory;
|
|
|
|
else
|
|
|
|
emitOp(dwarf::DW_OP_deref);
|
Debug Info: Move the complex expression handling (=the remainder) of
emitDebugLocValue() into DwarfExpression.
Ought to be NFC, but it actually uncovered a bug in the debug-loc-asan.ll
testcase. The testcase checks that the address of variable "y" is stored
at [RSP+16], which also lines up with the comment.
It also check(ed) that the *value* of "y" is stored in RDI before that,
but that is actually incorrect, since RDI is the very value that is
stored in [RSP+16]. Here's the assembler output:
movb 2147450880(%rcx), %r8b
#DEBUG_VALUE: bar:y <- RDI
cmpb $0, %r8b
movq %rax, 32(%rsp) # 8-byte Spill
movq %rsi, 24(%rsp) # 8-byte Spill
movq %rdi, 16(%rsp) # 8-byte Spill
.Ltmp3:
#DEBUG_VALUE: bar:y <- [RSP+16]
Fixed the comment to spell out the correct register and the check to
expect an address rather than a value.
Note that the range that is emitted for the RDI location was and is still
wrong, it claims to begin at the function prologue, but really it should
start where RDI is first assigned.
llvm-svn: 225851
2015-01-14 07:39:11 +08:00
|
|
|
break;
|
2016-09-13 09:12:59 +08:00
|
|
|
case dwarf::DW_OP_constu:
|
2017-04-18 09:21:53 +08:00
|
|
|
assert(LocationKind != Register);
|
2017-03-17 01:42:45 +08:00
|
|
|
emitOp(dwarf::DW_OP_constu);
|
|
|
|
emitUnsigned(Op->getArg(0));
|
2016-09-13 09:12:59 +08:00
|
|
|
break;
|
|
|
|
case dwarf::DW_OP_stack_value:
|
2017-04-18 09:21:53 +08:00
|
|
|
LocationKind = Implicit;
|
2016-09-13 09:12:59 +08:00
|
|
|
break;
|
2017-03-08 08:28:57 +08:00
|
|
|
case dwarf::DW_OP_swap:
|
2017-04-18 09:21:53 +08:00
|
|
|
assert(LocationKind != Register);
|
2017-03-17 01:42:45 +08:00
|
|
|
emitOp(dwarf::DW_OP_swap);
|
2017-03-08 08:28:57 +08:00
|
|
|
break;
|
|
|
|
case dwarf::DW_OP_xderef:
|
2017-04-18 09:21:53 +08:00
|
|
|
assert(LocationKind != Register);
|
2017-03-17 01:42:45 +08:00
|
|
|
emitOp(dwarf::DW_OP_xderef);
|
2017-03-08 08:28:57 +08:00
|
|
|
break;
|
Debug Info: Move the complex expression handling (=the remainder) of
emitDebugLocValue() into DwarfExpression.
Ought to be NFC, but it actually uncovered a bug in the debug-loc-asan.ll
testcase. The testcase checks that the address of variable "y" is stored
at [RSP+16], which also lines up with the comment.
It also check(ed) that the *value* of "y" is stored in RDI before that,
but that is actually incorrect, since RDI is the very value that is
stored in [RSP+16]. Here's the assembler output:
movb 2147450880(%rcx), %r8b
#DEBUG_VALUE: bar:y <- RDI
cmpb $0, %r8b
movq %rax, 32(%rsp) # 8-byte Spill
movq %rsi, 24(%rsp) # 8-byte Spill
movq %rdi, 16(%rsp) # 8-byte Spill
.Ltmp3:
#DEBUG_VALUE: bar:y <- [RSP+16]
Fixed the comment to spell out the correct register and the check to
expect an address rather than a value.
Note that the range that is emitted for the RDI location was and is still
wrong, it claims to begin at the function prologue, but really it should
start where RDI is first assigned.
llvm-svn: 225851
2015-01-14 07:39:11 +08:00
|
|
|
default:
|
2015-04-22 02:44:06 +08:00
|
|
|
llvm_unreachable("unhandled opcode found in expression");
|
Debug Info: Move the complex expression handling (=the remainder) of
emitDebugLocValue() into DwarfExpression.
Ought to be NFC, but it actually uncovered a bug in the debug-loc-asan.ll
testcase. The testcase checks that the address of variable "y" is stored
at [RSP+16], which also lines up with the comment.
It also check(ed) that the *value* of "y" is stored in RDI before that,
but that is actually incorrect, since RDI is the very value that is
stored in [RSP+16]. Here's the assembler output:
movb 2147450880(%rcx), %r8b
#DEBUG_VALUE: bar:y <- RDI
cmpb $0, %r8b
movq %rax, 32(%rsp) # 8-byte Spill
movq %rsi, 24(%rsp) # 8-byte Spill
movq %rdi, 16(%rsp) # 8-byte Spill
.Ltmp3:
#DEBUG_VALUE: bar:y <- [RSP+16]
Fixed the comment to spell out the correct register and the check to
expect an address rather than a value.
Note that the range that is emitted for the RDI location was and is still
wrong, it claims to begin at the function prologue, but really it should
start where RDI is first assigned.
llvm-svn: 225851
2015-01-14 07:39:11 +08:00
|
|
|
}
|
|
|
|
}
|
2017-04-18 09:21:53 +08:00
|
|
|
|
|
|
|
if (LocationKind == Implicit)
|
|
|
|
// Turn this into an implicit location description.
|
|
|
|
addStackValue();
|
Debug Info: Move the complex expression handling (=the remainder) of
emitDebugLocValue() into DwarfExpression.
Ought to be NFC, but it actually uncovered a bug in the debug-loc-asan.ll
testcase. The testcase checks that the address of variable "y" is stored
at [RSP+16], which also lines up with the comment.
It also check(ed) that the *value* of "y" is stored in RDI before that,
but that is actually incorrect, since RDI is the very value that is
stored in [RSP+16]. Here's the assembler output:
movb 2147450880(%rcx), %r8b
#DEBUG_VALUE: bar:y <- RDI
cmpb $0, %r8b
movq %rax, 32(%rsp) # 8-byte Spill
movq %rsi, 24(%rsp) # 8-byte Spill
movq %rdi, 16(%rsp) # 8-byte Spill
.Ltmp3:
#DEBUG_VALUE: bar:y <- [RSP+16]
Fixed the comment to spell out the correct register and the check to
expect an address rather than a value.
Note that the range that is emitted for the RDI location was and is still
wrong, it claims to begin at the function prologue, but really it should
start where RDI is first assigned.
llvm-svn: 225851
2015-01-14 07:39:11 +08:00
|
|
|
}
|
2016-12-10 04:43:40 +08:00
|
|
|
|
2017-03-17 01:42:45 +08:00
|
|
|
/// add masking operations to stencil out a subregister.
|
2017-03-17 01:14:56 +08:00
|
|
|
void DwarfExpression::maskSubRegister() {
|
|
|
|
assert(SubRegisterSizeInBits && "no subregister was registered");
|
|
|
|
if (SubRegisterOffsetInBits > 0)
|
2017-03-17 01:42:45 +08:00
|
|
|
addShr(SubRegisterOffsetInBits);
|
2017-03-17 02:06:04 +08:00
|
|
|
uint64_t Mask = (1ULL << (uint64_t)SubRegisterSizeInBits) - 1ULL;
|
2017-03-17 01:42:45 +08:00
|
|
|
addAnd(Mask);
|
2017-03-17 01:14:56 +08:00
|
|
|
}
|
|
|
|
|
2016-12-10 04:43:40 +08:00
|
|
|
void DwarfExpression::finalize() {
|
2017-03-22 09:15:57 +08:00
|
|
|
assert(DwarfRegs.size() == 0 && "dwarf registers not emitted");
|
2017-03-17 01:14:56 +08:00
|
|
|
// Emit any outstanding DW_OP_piece operations to mask out subregisters.
|
|
|
|
if (SubRegisterSizeInBits == 0)
|
|
|
|
return;
|
|
|
|
// Don't emit a DW_OP_piece for a subregister at offset 0.
|
|
|
|
if (SubRegisterOffsetInBits == 0)
|
|
|
|
return;
|
2017-03-17 01:42:45 +08:00
|
|
|
addOpPiece(SubRegisterSizeInBits, SubRegisterOffsetInBits);
|
2016-12-10 04:43:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void DwarfExpression::addFragmentOffset(const DIExpression *Expr) {
|
|
|
|
if (!Expr || !Expr->isFragment())
|
|
|
|
return;
|
|
|
|
|
2016-12-22 13:27:12 +08:00
|
|
|
uint64_t FragmentOffset = Expr->getFragmentInfo()->OffsetInBits;
|
2016-12-10 04:43:40 +08:00
|
|
|
assert(FragmentOffset >= OffsetInBits &&
|
|
|
|
"overlapping or duplicate fragments");
|
|
|
|
if (FragmentOffset > OffsetInBits)
|
2017-03-17 01:42:45 +08:00
|
|
|
addOpPiece(FragmentOffset - OffsetInBits);
|
2016-12-10 04:43:40 +08:00
|
|
|
OffsetInBits = FragmentOffset;
|
|
|
|
}
|