[x64] Fix Disassembler tests to actually test disassembly

Currently the disassembler tests continue on unimplemented instructions, fix
to abort instead as most bugs in the disassemblers will appear as unimplemented
instructions.

 - Localize testing disassembler method to abort on unimplemented
 - Fix failing x64 disassembler tests

Change-Id: I703cca9709c528327ec381d05a78cf3314ea4fa9
Reviewed-on: https://chromium-review.googlesource.com/907489
Reviewed-by: Ben Titzer <titzer@chromium.org>
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Deepti Gandluri <gdeepti@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51162}
This commit is contained in:
Deepti Gandluri 2018-02-07 12:29:17 -08:00 committed by Commit Bot
parent 7fe83f31e1
commit 8fa509d311
3 changed files with 38 additions and 1 deletions

View File

@ -41,6 +41,13 @@ class Disassembler {
// Returns the length of the disassembled machine instruction in bytes.
int InstructionDecode(v8::internal::Vector<char> buffer, byte* instruction);
// Disassemblers on ia32/x64 need a separate method for testing, as
// instruction decode method above continues on unimplemented opcodes, and
// does not test the disassemblers. Basic functionality of the method remains
// the same.
int InstructionDecodeForTesting(v8::internal::Vector<char> buffer,
byte* instruction);
// Returns -1 if instruction does not mark the beginning of a constant pool,
// or the number of entries in the constant pool beginning here.
int ConstantPoolSizeAt(byte* instruction);
@ -48,6 +55,7 @@ class Disassembler {
// Write disassembly into specified file 'f' using specified NameConverter
// (see constructor).
static void Disassemble(FILE* f, byte* begin, byte* end);
private:
const NameConverter& converter_;

View File

@ -1840,6 +1840,8 @@ int DisassemblerX64::TwoByteOpcodeInstruction(byte* data) {
} else if (opcode == 0xD9) {
mnemonic = "psubusw";
} else if (opcode == 0xDA) {
mnemonic = "pand";
} else if (opcode == 0xDB) {
mnemonic = "pminub";
} else if (opcode == 0xDC) {
mnemonic = "paddusb";
@ -1857,6 +1859,8 @@ int DisassemblerX64::TwoByteOpcodeInstruction(byte* data) {
mnemonic = "psubsw";
} else if (opcode == 0xEA) {
mnemonic = "pminsw";
} else if (opcode == 0xEB) {
mnemonic = "por";
} else if (opcode == 0xEC) {
mnemonic = "paddsb";
} else if (opcode == 0xED) {
@ -2814,6 +2818,11 @@ int Disassembler::InstructionDecode(v8::internal::Vector<char> buffer,
return d.InstructionDecode(buffer, instruction);
}
int Disassembler::InstructionDecodeForTesting(v8::internal::Vector<char> buffer,
byte* instruction) {
DisassemblerX64 d(converter_, ABORT_ON_UNIMPLEMENTED_OPCODE);
return d.InstructionDecode(buffer, instruction);
}
// The X64 assembler does not use constant pools.
int Disassembler::ConstantPoolSizeAt(byte* instruction) {

View File

@ -47,6 +47,26 @@ namespace internal {
static void DummyStaticFunction(Object* result) {
}
void Disassemble(FILE* f, byte* begin, byte* end) {
disasm::NameConverter converter;
disasm::Disassembler d(converter);
for (byte* pc = begin; pc < end;) {
v8::internal::EmbeddedVector<char, 128> buffer;
buffer[0] = '\0';
byte* prev_pc = pc;
pc += d.InstructionDecodeForTesting(buffer, pc);
fprintf(f, "%p", static_cast<void*>(prev_pc));
fprintf(f, " ");
for (byte* bp = prev_pc; bp < pc; bp++) {
fprintf(f, "%02x", *bp);
}
for (int i = 6 - static_cast<int>(pc - prev_pc); i >= 0; i--) {
fprintf(f, " ");
}
fprintf(f, " %s\n", buffer.start());
}
}
TEST(DisasmX64) {
CcTest::InitializeVM();
@ -960,7 +980,7 @@ TEST(DisasmX64) {
code->Print(os);
byte* begin = code->instruction_start();
byte* end = begin + code->instruction_size();
disasm::Disassembler::Disassemble(stdout, begin, end);
Disassemble(stdout, begin, end);
#endif
}