[PDB] Fix a bug in the explain subcommand.

We were trying to dig into the super block fields and print a
description of the field at the specified offset, but we were
printing the wrong field due to an off-by-one-field-error.

llvm-svn: 328804
This commit is contained in:
Zachary Turner 2018-03-29 17:11:14 +00:00
parent b458329327
commit 1b20416bfa
2 changed files with 14 additions and 12 deletions

View File

@ -33,17 +33,17 @@
ZERO: Block:Offset = 0:0000.
ZERO-NEXT: Address is in block 0 (allocated).
ZERO-NEXT: This corresponds to offset 0 of MSF super block,
ZERO-NEXT: This corresponds to offset 0 of the MSF super block,
ZERO-NEXT: which is part of the MSF file magic.
FORTY: Block:Offset = 0:0028.
FORTY-NEXT: Address is in block 0 (allocated).
FORTY-NEXT: This corresponds to offset 40 of MSF super block,
FORTY-NEXT: which contains the number of bytes in the stream directory.
FORTY-NEXT: This corresponds to offset 40 of the MSF super block,
FORTY-NEXT: which contains the number of blocks in the file.
SIXTY: Block:Offset = 0:003C.
SIXTY-NEXT: Address is in block 0 (allocated).
SIXTY-NEXT: This corresponds to offset 60 of MSF super block,
SIXTY-NEXT: This corresponds to offset 60 of the MSF super block,
SIXTY-NEXT: which is outside the range of valid data for the super block.
FPM1: Block:Offset = 1:0000.

View File

@ -96,22 +96,24 @@ bool ExplainOutputStyle::explainBlockStatus() {
return !IsFree;
}
#define endof(Class, Field) (offsetof(Class, Field) + sizeof(Class::Field))
void ExplainOutputStyle::explainSuperBlockOffset() {
P.formatLine("This corresponds to offset {0} of MSF super block, ",
P.formatLine("This corresponds to offset {0} of the MSF super block, ",
OffsetInBlock);
if (OffsetInBlock < sizeof(msf::Magic))
if (OffsetInBlock < endof(SuperBlock, MagicBytes))
P.printLine("which is part of the MSF file magic.");
else if (OffsetInBlock < offsetof(SuperBlock, BlockSize))
else if (OffsetInBlock < endof(SuperBlock, BlockSize))
P.printLine("which contains the block size of the file.");
else if (OffsetInBlock < offsetof(SuperBlock, FreeBlockMapBlock))
else if (OffsetInBlock < endof(SuperBlock, FreeBlockMapBlock))
P.printLine("which contains the index of the FPM block (e.g. 1 or 2).");
else if (OffsetInBlock < offsetof(SuperBlock, NumBlocks))
else if (OffsetInBlock < endof(SuperBlock, NumBlocks))
P.printLine("which contains the number of blocks in the file.");
else if (OffsetInBlock < offsetof(SuperBlock, NumDirectoryBytes))
else if (OffsetInBlock < endof(SuperBlock, NumDirectoryBytes))
P.printLine("which contains the number of bytes in the stream directory.");
else if (OffsetInBlock < offsetof(SuperBlock, Unknown1))
else if (OffsetInBlock < endof(SuperBlock, Unknown1))
P.printLine("whose purpose is unknown.");
else if (OffsetInBlock < offsetof(SuperBlock, BlockMapAddr))
else if (OffsetInBlock < endof(SuperBlock, BlockMapAddr))
P.printLine("which contains the file offset of the block map.");
else {
assert(OffsetInBlock > sizeof(SuperBlock));