This is an archive of the discontinued LLVM Phabricator instance.

[codeview] Improve readability of type record assembly
ClosedPublic

Authored by rnk on May 26 2016, 4:09 PM.

Details

Summary

Adds the method MCStreamer::EmitBinaryData, which is usually an alias
for EmitBytes. In the MCAsmStreamer case, it is overridden to emit hex
dump output like this:

.byte   0x0e, 0x00, 0x08, 0x10
.byte   0x03, 0x00, 0x00, 0x00
.byte   0x00, 0x00, 0x00, 0x00
.byte   0x00, 0x10, 0x00, 0x00

Also, when verbose asm comments are enabled, this patch prints the dump
output for each comment before its record, like this:

  1. ArgList (0x1000) {
  2. TypeLeafKind: LF_ARGLIST (0x1201)
  3. NumArgs: 0
  4. Arguments [
  5. ]
  6. } .byte 0x06, 0x00, 0x01, 0x12 .byte 0x00, 0x00, 0x00, 0x00

This should make debugging easier and testing more convenient.

Diff Detail

Repository
rL LLVM

Event Timeline

rnk updated this revision to Diff 58716.May 26 2016, 4:09 PM
rnk retitled this revision from to [codeview] Improve readability of type record assembly.
rnk updated this object.
rnk added a reviewer: majnemer.
rnk added subscribers: llvm-commits, aaboud, amccarth, zturner.

Looks good to me.
Only few comments below.

lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
290 ↗(On Diff #58716)

Can you explain what we need the CommentPrefix string?
We are not going to print it after all, right?

lib/DebugInfo/CodeView/MemoryTypeTableBuilder.cpp
26 ↗(On Diff #58716)

How about defining two "static const" variables? Like this:
static const int Alignment = 4;
static const int SizeFieldLength = 2;

31 ↗(On Diff #58716)

The Padding is created in the wrong order (check how it is emitted in CodeViewDebug.cpp lines 299-300.
This should be like this:

for (int I = TotalSize - (Data.size() + 2) - 1; I >= 0; --I)
  Mem[I] = LF_PAD0 + I;
lib/MC/MCAsmStreamer.cpp
707 ↗(On Diff #58716)

Should not "Cols" be "static const"?

aaboud added inline comments.May 28 2016, 3:38 PM
lib/DebugInfo/CodeView/MemoryTypeTableBuilder.cpp
31 ↗(On Diff #58716)

It seems that LF_PAD0 should not be used in padding so the correct loop will look like this:

for (int I = TotalSize - (Data.size() + 2) ; I > 0; --I)
  Mem[I] = LF_PAD0 + I;
rnk marked an inline comment as done.May 31 2016, 11:47 AM

Thanks!

lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
290 ↗(On Diff #58716)

The comment block is multiple lines, and we only chop off the comment prefix of the first line.

lib/DebugInfo/CodeView/MemoryTypeTableBuilder.cpp
31 ↗(On Diff #58716)

I'm pretty sure this loop is correct, because it passes the tests in test/DebugInfo/COFF/inlining-padding.ll for this. We never emit LF_PAD0, because we exit the loop before I reaches TotalSize.

I thought it was easier to reason about a count-up loop than a count-down loop, so I went with this.

lib/MC/MCAsmStreamer.cpp
707 ↗(On Diff #58716)

I could const-ify it, but I don't generally like making readers think about whether or not local variables require static initialization.

This revision was automatically updated to reflect the committed changes.