Commit 8fa509d3 authored by Deepti Gandluri's avatar Deepti Gandluri Committed by Commit Bot

[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/907489Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Deepti Gandluri <gdeepti@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51162}
parent 7fe83f31
...@@ -41,6 +41,13 @@ class Disassembler { ...@@ -41,6 +41,13 @@ class Disassembler {
// Returns the length of the disassembled machine instruction in bytes. // Returns the length of the disassembled machine instruction in bytes.
int InstructionDecode(v8::internal::Vector<char> buffer, byte* instruction); 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, // Returns -1 if instruction does not mark the beginning of a constant pool,
// or the number of entries in the constant pool beginning here. // or the number of entries in the constant pool beginning here.
int ConstantPoolSizeAt(byte* instruction); int ConstantPoolSizeAt(byte* instruction);
...@@ -48,6 +55,7 @@ class Disassembler { ...@@ -48,6 +55,7 @@ class Disassembler {
// Write disassembly into specified file 'f' using specified NameConverter // Write disassembly into specified file 'f' using specified NameConverter
// (see constructor). // (see constructor).
static void Disassemble(FILE* f, byte* begin, byte* end); static void Disassemble(FILE* f, byte* begin, byte* end);
private: private:
const NameConverter& converter_; const NameConverter& converter_;
......
...@@ -1840,6 +1840,8 @@ int DisassemblerX64::TwoByteOpcodeInstruction(byte* data) { ...@@ -1840,6 +1840,8 @@ int DisassemblerX64::TwoByteOpcodeInstruction(byte* data) {
} else if (opcode == 0xD9) { } else if (opcode == 0xD9) {
mnemonic = "psubusw"; mnemonic = "psubusw";
} else if (opcode == 0xDA) { } else if (opcode == 0xDA) {
mnemonic = "pand";
} else if (opcode == 0xDB) {
mnemonic = "pminub"; mnemonic = "pminub";
} else if (opcode == 0xDC) { } else if (opcode == 0xDC) {
mnemonic = "paddusb"; mnemonic = "paddusb";
...@@ -1857,6 +1859,8 @@ int DisassemblerX64::TwoByteOpcodeInstruction(byte* data) { ...@@ -1857,6 +1859,8 @@ int DisassemblerX64::TwoByteOpcodeInstruction(byte* data) {
mnemonic = "psubsw"; mnemonic = "psubsw";
} else if (opcode == 0xEA) { } else if (opcode == 0xEA) {
mnemonic = "pminsw"; mnemonic = "pminsw";
} else if (opcode == 0xEB) {
mnemonic = "por";
} else if (opcode == 0xEC) { } else if (opcode == 0xEC) {
mnemonic = "paddsb"; mnemonic = "paddsb";
} else if (opcode == 0xED) { } else if (opcode == 0xED) {
...@@ -2814,6 +2818,11 @@ int Disassembler::InstructionDecode(v8::internal::Vector<char> buffer, ...@@ -2814,6 +2818,11 @@ int Disassembler::InstructionDecode(v8::internal::Vector<char> buffer,
return d.InstructionDecode(buffer, instruction); 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. // The X64 assembler does not use constant pools.
int Disassembler::ConstantPoolSizeAt(byte* instruction) { int Disassembler::ConstantPoolSizeAt(byte* instruction) {
......
...@@ -47,6 +47,26 @@ namespace internal { ...@@ -47,6 +47,26 @@ namespace internal {
static void DummyStaticFunction(Object* result) { 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) { TEST(DisasmX64) {
CcTest::InitializeVM(); CcTest::InitializeVM();
...@@ -960,7 +980,7 @@ TEST(DisasmX64) { ...@@ -960,7 +980,7 @@ TEST(DisasmX64) {
code->Print(os); code->Print(os);
byte* begin = code->instruction_start(); byte* begin = code->instruction_start();
byte* end = begin + code->instruction_size(); byte* end = begin + code->instruction_size();
disasm::Disassembler::Disassemble(stdout, begin, end); Disassemble(stdout, begin, end);
#endif #endif
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment