llvm.org GIT mirror llvm / 7521234
Debug Info: Move support for constants into DwarfExpression. Move the declaration of DebugLocDwarfExpression into DwarfExpression.h because it needs to be accessed from AsmPrinterDwarf.cpp and DwarfDebug.cpp NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225734 91177308-0d34-0410-b5e6-96231b3b80d8 Adrian Prantl 5 years ago
4 changed file(s) with 65 addition(s) and 37 deletion(s). Raw diff Collapse all Expand all
3131
3232 #define DEBUG_TYPE "asm-printer"
3333
34 /// DwarfExpression implementation for .debug_loc entries.
35 class DebugLocDwarfExpression : public DwarfExpression {
36 ByteStreamer &BS;
37
38 public:
39 DebugLocDwarfExpression(const AsmPrinter &AP, ByteStreamer &BS)
40 : DwarfExpression(AP), BS(BS) {}
41
42 void EmitOp(uint8_t Op, const char *Comment) override;
43 void EmitSigned(int Value) override;
44 void EmitUnsigned(unsigned Value) override;
45 unsigned getFrameRegister() override { llvm_unreachable("not available"); };
46 };
47
4834 void DebugLocDwarfExpression::EmitOp(uint8_t Op, const char *Comment) {
4935 BS.EmitInt8(
5036 Op, Comment ? Twine(Comment) + " " + dwarf::OperationEncodingString(Op)
5137 : dwarf::OperationEncodingString(Op));
5238 }
39
5340 void DebugLocDwarfExpression::EmitSigned(int Value) {
5441 BS.EmitSLEB128(Value, Twine(Value));
5542 }
43
5644 void DebugLocDwarfExpression::EmitUnsigned(unsigned Value) {
5745 BS.EmitULEB128(Value, Twine(Value));
46 }
47
48 unsigned DebugLocDwarfExpression::getFrameRegister() {
49 llvm_unreachable("not available");
5850 }
5951
6052 //===----------------------------------------------------------------------===//
1313 #include "DwarfDebug.h"
1414
1515 #include "ByteStreamer.h"
16 #include "DwarfExpression.h"
1617 #include "DwarfCompileUnit.h"
1718 #include "DIEHash.h"
1819 #include "DwarfUnit.h"
17161717 void DwarfDebug::emitDebugLocValue(ByteStreamer &Streamer,
17171718 const DebugLocEntry::Value &Value) {
17181719 DIVariable DV = Value.getVariable();
1720 DebugLocDwarfExpression Expr(*Asm, Streamer);
17191721 // Regular entry.
17201722 if (Value.isInt()) {
17211723 DIBasicType BTy(resolve(DV.getType()));
17221724 if (BTy.Verify() && (BTy.getEncoding() == dwarf::DW_ATE_signed ||
1723 BTy.getEncoding() == dwarf::DW_ATE_signed_char)) {
1724 Streamer.EmitInt8(dwarf::DW_OP_consts, "DW_OP_consts");
1725 Streamer.EmitSLEB128(Value.getInt());
1726 } else {
1727 Streamer.EmitInt8(dwarf::DW_OP_constu, "DW_OP_constu");
1728 Streamer.EmitULEB128(Value.getInt());
1729 }
1730 // The proper way to describe a constant value is
1731 // DW_OP_constu , DW_OP_stack_value.
1732 // Unfortunately, DW_OP_stack_value was not available until DWARF-4,
1733 // so we will continue to generate DW_OP_constu for DWARF-2
1734 // and DWARF-3. Technically, this is incorrect since DW_OP_const
1735 // actually describes a value at a constant addess, not a constant value.
1736 // However, in the past there was no better way to describe a constant
1737 // value, so the producers and consumers started to rely on heuristics
1738 // to disambiguate the value vs. location status of the expression.
1739 // See PR21176 for more details.
1740 if (getDwarfVersion() >= 4)
1741 Streamer.EmitInt8(dwarf::DW_OP_stack_value, "DW_OP_stack_value");
1725 BTy.getEncoding() == dwarf::DW_ATE_signed_char))
1726 Expr.AddSignedConstant(Value.getInt());
1727 else
1728 Expr.AddUnsignedConstant(Value.getInt());
17421729 } else if (Value.isLocation()) {
17431730 MachineLocation Loc = Value.getLoc();
17441731 DIExpression Expr = Value.getExpression();
2020 #include "llvm/Target/TargetRegisterInfo.h"
2121 #include "llvm/Target/TargetSubtargetInfo.h"
2222
23
2423 using namespace llvm;
2524
2625 const TargetRegisterInfo *DwarfExpression::getTRI() const {
2726 return AP.TM.getSubtargetImpl()->getRegisterInfo();
2827 }
2928
30 void DwarfExpression::AddReg(int DwarfReg, const char* Comment) {
29 unsigned DwarfExpression::getDwarfVersion() const {
30 return AP.getDwarfDebug()->getDwarfVersion();
31 }
32
33 void DwarfExpression::AddReg(int DwarfReg, const char *Comment) {
3134 assert(DwarfReg >= 0 && "invalid negative dwarf register number");
3235 if (DwarfReg < 32) {
3336 EmitOp(dwarf::DW_OP_reg0 + DwarfReg, Comment);
5053 EmitOp(dwarf::DW_OP_deref);
5154 }
5255
53 void DwarfExpression::AddOpPiece(unsigned SizeInBits,
54 unsigned OffsetInBits) {
56 void DwarfExpression::AddOpPiece(unsigned SizeInBits, unsigned OffsetInBits) {
5557 assert(SizeInBits > 0 && "piece has size zero");
5658 const unsigned SizeOfByte = 8;
5759 if (OffsetInBits > 0 || SizeInBits % SizeOfByte) {
163165 // FIXME: We have no reasonable way of handling errors in here.
164166 EmitOp(dwarf::DW_OP_nop, "nop (could not find a dwarf register number)");
165167 }
168
169 void DwarfExpression::AddSignedConstant(int Value) {
170 EmitOp(dwarf::DW_OP_consts);
171 EmitSigned(Value);
172 // The proper way to describe a constant value is
173 // DW_OP_constu , DW_OP_stack_value.
174 // Unfortunately, DW_OP_stack_value was not available until DWARF-4,
175 // so we will continue to generate DW_OP_constu for DWARF-2
176 // and DWARF-3. Technically, this is incorrect since DW_OP_const
177 // actually describes a value at a constant addess, not a constant value.
178 // However, in the past there was no better way to describe a constant
179 // value, so the producers and consumers started to rely on heuristics
180 // to disambiguate the value vs. location status of the expression.
181 // See PR21176 for more details.
182 if (getDwarfVersion() >= 4)
183 EmitOp(dwarf::DW_OP_stack_value);
184 }
185
186 void DwarfExpression::AddUnsignedConstant(unsigned Value) {
187 EmitOp(dwarf::DW_OP_constu);
188 EmitUnsigned(Value);
189 // cf. comment in DwarfExpression::AddSignedConstant().
190 if (getDwarfVersion() >= 4)
191 EmitOp(dwarf::DW_OP_stack_value);
192 }
1818 namespace llvm {
1919
2020 class AsmPrinter;
21 class ByteStreamer;
2122 class TargetRegisterInfo;
2223
2324 /// Base class containing the logic for constructing DWARF expressions
2829 const AsmPrinter &AP;
2930 // Various convenience accessors that extract things out of AsmPrinter.
3031 const TargetRegisterInfo *getTRI() const;
32 unsigned getDwarfVersion() const;
3133
3234 public:
3335 DwarfExpression(const AsmPrinter &AP) : AP(AP) {}
7072 void AddMachineRegPiece(unsigned MachineReg,
7173 unsigned PieceSizeInBits = 0,
7274 unsigned PieceOffsetInBits = 0);
75
76 /// Emit a signed constant.
77 void AddSignedConstant(int Value);
78 /// Emit an unsigned constant.
79 void AddUnsignedConstant(unsigned Value);
80 };
81
82
83 /// DwarfExpression implementation for .debug_loc entries.
84 class DebugLocDwarfExpression : public DwarfExpression {
85 ByteStreamer &BS;
86
87 public:
88 DebugLocDwarfExpression(const AsmPrinter &AP, ByteStreamer &BS)
89 : DwarfExpression(AP), BS(BS) {}
90
91 void EmitOp(uint8_t Op, const char *Comment) override;
92 void EmitSigned(int Value) override;
93 void EmitUnsigned(unsigned Value) override;
94 unsigned getFrameRegister() override;
7395 };
7496
7597 }