[DebugInfo] Fix printing of DW_LNS_set_isa

The Isa register is a uint8_t, but at least on Windows this is
internally an unsigned char, which meant that prior to this patch it got
formatted as an ASCII character, rather than a decimal number. This
patch fixes this by casting it to a uint64_t before printing. I did it
this way instead of using a uint8_t formatter because a) it is simpler,
and b) it allows us to change the internal type of Isa in the future
without this code breaking.

I also took the opportunity to test the printing of the other standard
opcodes.

Reviewed by: probinson

Differential Revision: https://reviews.llvm.org/D71274
This commit is contained in:
James Henderson 2019-12-11 12:14:11 +00:00
parent 8600bd1fe6
commit e971a824fd
2 changed files with 53 additions and 1 deletions

View File

@ -813,7 +813,7 @@ Error DWARFDebugLine::LineTable::parse(
// column register of the state machine.
State.Row.Isa = DebugLineData.getULEB128(OffsetPtr);
if (OS)
*OS << " (" << State.Row.Isa << ")";
*OS << " (" << (uint64_t)State.Row.Isa << ")";
break;
default:

View File

@ -675,4 +675,56 @@ TEST_F(DebugLineBasicFixture, ParserIgnoresNonPrologueErrorsWhenSkipping) {
EXPECT_FALSE(Unrecoverable);
}
TEST_F(DebugLineBasicFixture, ParserPrintsStandardOpcodesWhenRequested) {
if (!setupGenerator())
return;
using ValLen = dwarfgen::LineTable::ValueAndLength;
LineTable &LT = Gen->addLineTable(DWARF32);
LT.addStandardOpcode(DW_LNS_copy, {});
LT.addStandardOpcode(DW_LNS_advance_pc, {ValLen{11, LineTable::ULEB}});
LT.addStandardOpcode(DW_LNS_advance_line, {ValLen{22, LineTable::SLEB}});
LT.addStandardOpcode(DW_LNS_set_file, {ValLen{33, LineTable::ULEB}});
LT.addStandardOpcode(DW_LNS_set_column, {ValLen{44, LineTable::ULEB}});
LT.addStandardOpcode(DW_LNS_negate_stmt, {});
LT.addStandardOpcode(DW_LNS_set_basic_block, {});
LT.addStandardOpcode(DW_LNS_const_add_pc, {});
LT.addStandardOpcode(DW_LNS_fixed_advance_pc, {ValLen{55, LineTable::Half}});
LT.addStandardOpcode(DW_LNS_set_prologue_end, {});
LT.addStandardOpcode(DW_LNS_set_epilogue_begin, {});
LT.addStandardOpcode(DW_LNS_set_isa, {ValLen{66, LineTable::ULEB}});
LT.addExtendedOpcode(1, DW_LNE_end_sequence, {});
generate();
DWARFDebugLine::SectionParser Parser(LineData, *Context, CUs, TUs);
std::string Output;
raw_string_ostream OS(Output);
Parser.parseNext(RecordRecoverable, RecordUnrecoverable, &OS);
OS.flush();
EXPECT_FALSE(Recoverable);
EXPECT_FALSE(Unrecoverable);
auto InOutput = [&Output](char const *Str) {
return Output.find(Str) != std::string::npos;
};
EXPECT_TRUE(InOutput("0x0000002e: 01 DW_LNS_copy\n")) << Output;
EXPECT_TRUE(InOutput("0x0000002f: 02 DW_LNS_advance_pc (11)\n")) << Output;
// FIXME: The value printed after DW_LNS_advance_line is currently the result
// of the advance, but it should be the value being advanced by. See
// https://bugs.llvm.org/show_bug.cgi?id=44261 for details.
EXPECT_TRUE(InOutput("0x00000031: 03 DW_LNS_advance_line (23)\n")) << Output;
EXPECT_TRUE(InOutput("0x00000033: 04 DW_LNS_set_file (33)\n")) << Output;
EXPECT_TRUE(InOutput("0x00000035: 05 DW_LNS_set_column (44)\n")) << Output;
EXPECT_TRUE(InOutput("0x00000037: 06 DW_LNS_negate_stmt\n")) << Output;
EXPECT_TRUE(InOutput("0x00000038: 07 DW_LNS_set_basic_block\n")) << Output;
EXPECT_TRUE(
InOutput("0x00000039: 08 DW_LNS_const_add_pc (0x0000000000000011)\n"))
<< Output;
EXPECT_TRUE(InOutput("0x0000003a: 09 DW_LNS_fixed_advance_pc (0x0037)\n"))
<< Output;
EXPECT_TRUE(InOutput("0x0000003d: 0a DW_LNS_set_prologue_end\n")) << Output;
EXPECT_TRUE(InOutput("0x0000003e: 0b DW_LNS_set_epilogue_begin\n")) << Output;
EXPECT_TRUE(InOutput("0x0000003f: 0c DW_LNS_set_isa (66)\n")) << Output;
}
} // end anonymous namespace