1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 06:48:12 +00:00

LibX86+disasm: Use an output format closer to objdump

This mainly does two things,
1. Removes spaces after commas
2. Elides "0x" and leading zeros in most contexts

Remaining differences are:
1. objdump always has memory size annotations
   We lack these and probably have some annotations wrong
2. Boolean check names
   We use jump-zero, while objdump uses jump-equal for example
3. We sometimes add "00 00" symbols, which objdump elides
4. We always demangle (This is a good thing)
5. We always resolve relocations (This is a good thing)
6. We seem to detect some symbols differently/incorrectly
This commit is contained in:
Hendiadyoin1 2022-04-07 14:53:19 +02:00 committed by Andreas Kling
parent 5ee85aaa5d
commit f602bbf135
2 changed files with 128 additions and 130 deletions

View file

@ -1490,7 +1490,7 @@ String MemoryOrRegisterReference::to_string_a32() const
break;
case 5:
if (mod() == 0)
base = String::formatted("{:#08x}", m_displacement32);
base = String::formatted("{:x}", m_displacement32);
else
base = "ebp";
break;
@ -1513,18 +1513,18 @@ String MemoryOrRegisterReference::to_string_a32() const
static String relative_address(u32 origin, bool x32, i8 imm)
{
if (x32)
return String::formatted("{:#08x}", origin + imm);
return String::formatted("{:x}", origin + imm);
u16 w = origin & 0xffff;
return String::formatted("{:#04x}", w + imm);
return String::formatted("{:x}", w + imm);
}
static String relative_address(u32 origin, bool x32, i32 imm)
{
if (x32)
return String::formatted("{:#08x}", origin + imm);
return String::formatted("{:x}", origin + imm);
u16 w = origin & 0xffff;
i16 si = imm;
return String::formatted("{:#04x}", w + si);
return String::formatted("{:x}", w + si);
}
String Instruction::to_string(u32 origin, SymbolProvider const* symbol_provider, bool x32) const
@ -1556,10 +1556,8 @@ void Instruction::to_string_internal(StringBuilder& builder, u32 origin, SymbolP
String mnemonic = String(m_descriptor->mnemonic).to_lowercase();
auto append_mnemonic = [&] { builder.append(mnemonic); };
auto append_mnemonic_space = [&] {
builder.append(mnemonic);
builder.append(' ');
};
auto append_mnemonic_space = [&] { builder.appendff("{: <6} ", mnemonic); };
auto formatted_address = [&](FlatPtr origin, bool x32, auto offset) {
builder.append(relative_address(origin, x32, offset));
@ -1569,7 +1567,7 @@ void Instruction::to_string_internal(StringBuilder& builder, u32 origin, SymbolP
builder.append(" <");
builder.append(symbol);
if (symbol_offset)
builder.appendff("+{}", symbol_offset);
builder.appendff("+{:#x}", symbol_offset);
builder.append('>');
}
};
@ -1586,13 +1584,13 @@ void Instruction::to_string_internal(StringBuilder& builder, u32 origin, SymbolP
auto append_fpu_rm32 = [&] { builder.append(m_modrm.to_string_fpu32(*this)); };
auto append_fpu_rm64 = [&] { builder.append(m_modrm.to_string_fpu64(*this)); };
auto append_fpu_rm80 = [&] { builder.append(m_modrm.to_string_fpu80(*this)); };
auto append_imm8 = [&] { builder.appendff("{:#02x}", imm8()); };
auto append_imm8_2 = [&] { builder.appendff("{:#02x}", imm8_2()); };
auto append_imm16 = [&] { builder.appendff("{:#04x}", imm16()); };
auto append_imm16_1 = [&] { builder.appendff("{:#04x}", imm16_1()); };
auto append_imm16_2 = [&] { builder.appendff("{:#04x}", imm16_2()); };
auto append_imm32 = [&] { builder.appendff("{:#08x}", imm32()); };
auto append_imm32_2 = [&] { builder.appendff("{:#08x}", imm32_2()); };
auto append_imm8 = [&] { builder.appendff("{:#x}", imm8()); };
auto append_imm8_2 = [&] { builder.appendff("{:#x}", imm8_2()); };
auto append_imm16 = [&] { builder.appendff("{:#x}", imm16()); };
auto append_imm16_1 = [&] { builder.appendff("{:#x}", imm16_1()); };
auto append_imm16_2 = [&] { builder.appendff("{:#x}", imm16_2()); };
auto append_imm32 = [&] { builder.appendff("{:#x}", imm32()); };
auto append_imm32_2 = [&] { builder.appendff("{:#x}", imm32_2()); };
auto append_reg8 = [&] { builder.append(reg8_name()); };
auto append_reg16 = [&] { builder.append(reg16_name()); };
auto append_reg32 = [&] { builder.append(reg32_name()); };
@ -1779,7 +1777,7 @@ void Instruction::to_string_internal(StringBuilder& builder, u32 origin, SymbolP
append("gs");
break;
case OP:
append_mnemonic_space();
append_mnemonic();
break;
case OP_reg32:
append_mnemonic_space();

View file

@ -124,7 +124,7 @@ ErrorOr<int> serenity_main(Main::Arguments args)
outln();
++current_symbol;
current_instruction_is_in_symbol = true;
outln("{} ({:p}-{:p}):", current_symbol->name, current_symbol->address(), current_symbol->address_end());
outln("{:08x} <{}>:", current_symbol->address(), current_symbol->name);
}
is_first_symbol = false;