Skip to content

Commit 4e22770

Browse files
committed
Changes to display code view debug info type records in hex format
llvm-svn: 366390
1 parent 749f556 commit 4e22770

File tree

7 files changed

+149
-122
lines changed

7 files changed

+149
-122
lines changed

llvm/include/llvm/MC/MCExpr.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,22 +134,30 @@ inline raw_ostream &operator<<(raw_ostream &OS, const MCExpr &E) {
134134
//// Represent a constant integer expression.
135135
class MCConstantExpr : public MCExpr {
136136
int64_t Value;
137+
bool PrintInHex = false;
137138

138-
explicit MCConstantExpr(int64_t Value)
139+
MCConstantExpr(int64_t Value)
139140
: MCExpr(MCExpr::Constant, SMLoc()), Value(Value) {}
140141

142+
MCConstantExpr(int64_t Value, bool PrintInHex)
143+
: MCExpr(MCExpr::Constant, SMLoc()), Value(Value),
144+
PrintInHex(PrintInHex) {}
145+
141146
public:
142147
/// \name Construction
143148
/// @{
144149

145-
static const MCConstantExpr *create(int64_t Value, MCContext &Ctx);
150+
static const MCConstantExpr *create(int64_t Value, MCContext &Ctx,
151+
bool PrintInHex = false);
146152

147153
/// @}
148154
/// \name Accessors
149155
/// @{
150156

151157
int64_t getValue() const { return Value; }
152158

159+
bool useHexFormat() const { return PrintInHex; }
160+
153161
/// @}
154162

155163
static bool classof(const MCExpr *E) {

llvm/include/llvm/MC/MCStreamer.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,13 @@ class MCStreamer {
626626
/// to pass in a MCExpr for constant integers.
627627
virtual void EmitIntValue(uint64_t Value, unsigned Size);
628628

629+
/// Special case of EmitValue that avoids the client having to pass
630+
/// in a MCExpr for constant integers & prints in Hex format for certain
631+
/// modes.
632+
virtual void EmitIntValueInHex(uint64_t Value, unsigned Size) {
633+
EmitIntValue(Value, Size);
634+
}
635+
629636
virtual void EmitULEB128Value(const MCExpr *Value);
630637

631638
virtual void EmitSLEB128Value(const MCExpr *Value);

llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class CVMCAdapter : public CodeViewRecordStreamer {
103103
void EmitBytes(StringRef Data) { OS->EmitBytes(Data); }
104104

105105
void EmitIntValue(uint64_t Value, unsigned Size) {
106-
OS->EmitIntValue(Value, Size);
106+
OS->EmitIntValueInHex(Value, Size);
107107
}
108108

109109
void EmitBinaryData(StringRef Data) { OS->EmitBinaryData(Data); }

llvm/lib/DebugInfo/CodeView/TypeRecordMapping.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ Error TypeRecordMapping::visitKnownRecord(CVType &CVR, VFTableRecord &Record) {
306306
for (auto Name : Record.MethodNames)
307307
NamesLen += Name.size() + 1;
308308
}
309-
error(IO.mapInteger(NamesLen, ""));
309+
error(IO.mapInteger(NamesLen));
310310
error(IO.mapVectorTail(
311311
Record.MethodNames,
312312
[](CodeViewRecordIO &IO, StringRef &S) {

llvm/lib/MC/MCAsmStreamer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ class MCAsmStreamer final : public MCStreamer {
188188
void EmitValueImpl(const MCExpr *Value, unsigned Size,
189189
SMLoc Loc = SMLoc()) override;
190190
void EmitIntValue(uint64_t Value, unsigned Size) override;
191+
void EmitIntValueInHex(uint64_t Value, unsigned Size) override;
191192

192193
void EmitULEB128Value(const MCExpr *Value) override;
193194

@@ -923,6 +924,10 @@ void MCAsmStreamer::EmitIntValue(uint64_t Value, unsigned Size) {
923924
EmitValue(MCConstantExpr::create(Value, getContext()), Size);
924925
}
925926

927+
void MCAsmStreamer::EmitIntValueInHex(uint64_t Value, unsigned Size) {
928+
EmitValue(MCConstantExpr::create(Value, getContext(), true), Size);
929+
}
930+
926931
void MCAsmStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
927932
SMLoc Loc) {
928933
assert(Size <= 8 && "Invalid size");

llvm/lib/MC/MCExpr.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "llvm/MC/MCExpr.h"
1010
#include "llvm/ADT/Statistic.h"
11+
#include "llvm/ADT/StringExtras.h"
1112
#include "llvm/ADT/StringSwitch.h"
1213
#include "llvm/Config/llvm-config.h"
1314
#include "llvm/MC/MCAsmBackend.h"
@@ -42,10 +43,15 @@ void MCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens) const {
4243
switch (getKind()) {
4344
case MCExpr::Target:
4445
return cast<MCTargetExpr>(this)->printImpl(OS, MAI);
45-
case MCExpr::Constant:
46-
OS << cast<MCConstantExpr>(*this).getValue();
46+
case MCExpr::Constant: {
47+
auto Value = cast<MCConstantExpr>(*this).getValue();
48+
auto PrintInHex = cast<MCConstantExpr>(*this).useHexFormat();
49+
if (PrintInHex)
50+
OS << "0x" << Twine::utohexstr(Value);
51+
else
52+
OS << Value;
4753
return;
48-
54+
}
4955
case MCExpr::SymbolRef: {
5056
const MCSymbolRefExpr &SRE = cast<MCSymbolRefExpr>(*this);
5157
const MCSymbol &Sym = SRE.getSymbol();
@@ -160,8 +166,9 @@ const MCUnaryExpr *MCUnaryExpr::create(Opcode Opc, const MCExpr *Expr,
160166
return new (Ctx) MCUnaryExpr(Opc, Expr, Loc);
161167
}
162168

163-
const MCConstantExpr *MCConstantExpr::create(int64_t Value, MCContext &Ctx) {
164-
return new (Ctx) MCConstantExpr(Value);
169+
const MCConstantExpr *MCConstantExpr::create(int64_t Value, MCContext &Ctx,
170+
bool PrintInHex) {
171+
return new (Ctx) MCConstantExpr(Value, PrintInHex);
165172
}
166173

167174
/* *** */

0 commit comments

Comments
 (0)