Overhaul logging.

This commit is contained in:
gibbed
2020-02-28 14:30:48 -06:00
committed by Rick Gibbed
parent de3c91ab2c
commit a48bb71c2f
107 changed files with 954 additions and 854 deletions

View File

@@ -56,9 +56,10 @@ bool X64CodeCache::Initialize() {
if (!indirection_table_base_) {
XELOGE("Unable to allocate code cache indirection table");
XELOGE(
"This is likely because the %.8X-%.8X range is in use by some other "
"This is likely because the {:X}-{:X} range is in use by some other "
"system DLL",
kIndirectionTableBase, kIndirectionTableBase + kIndirectionTableSize);
static_cast<uint64_t>(kIndirectionTableBase),
kIndirectionTableBase + kIndirectionTableSize);
}
// Create mmap file. This allows us to share the code cache with the debugger.
@@ -79,9 +80,10 @@ bool X64CodeCache::Initialize() {
if (!generated_code_base_) {
XELOGE("Unable to allocate code cache generated code storage");
XELOGE(
"This is likely because the %.8X-%.8X range is in use by some other "
"This is likely because the {:X}-{:X} range is in use by some other "
"system DLL",
kGeneratedCodeBase, kGeneratedCodeBase + kGeneratedCodeSize);
static_cast<uint64_t>(kGeneratedCodeBase),
kGeneratedCodeBase + kGeneratedCodeSize);
return false;
}

View File

@@ -245,7 +245,7 @@ bool X64Emitter::Emit(HIRBuilder* builder, EmitFunctionInfo& func_info) {
// NOTE: If you encounter this after adding a new instruction, do a full
// rebuild!
assert_always();
XELOGE("Unable to process HIR opcode %s", instr->opcode->name);
XELOGE("Unable to process HIR opcode {}", instr->opcode->name);
break;
}
instr = new_tail;
@@ -328,10 +328,10 @@ uint64_t TrapDebugPrint(void* raw_context, uint64_t address) {
// uint16_t str_len = uint16_t(thread_state->context()->r[4]);
auto str = thread_state->memory()->TranslateVirtual<const char*>(str_ptr);
// TODO(benvanik): truncate to length?
XELOGD("(DebugPrint) %s", str);
XELOGD("(DebugPrint) {}", str);
if (cvars::debugprint_trap_log) {
debugging::DebugPrint("(DebugPrint) %s", str);
debugging::DebugPrint("(DebugPrint) {}", str);
}
return 0;
@@ -363,7 +363,7 @@ void X64Emitter::Trap(uint16_t trap_type) {
// ?
break;
default:
XELOGW("Unknown trap type %d", trap_type);
XELOGW("Unknown trap type {}", trap_type);
db(0xCC);
break;
}
@@ -481,8 +481,8 @@ uint64_t UndefinedCallExtern(void* raw_context, uint64_t function_ptr) {
xe::FatalError(fmt::format("undefined extern call to {:08X} {}",
function->address(), function->name().c_str()));
} else {
XELOGE("undefined extern call to %.8X %s", function->address(),
function->name().c_str());
XELOGE("undefined extern call to {:08X} {}", function->address(),
function->name());
}
return 0;
}

View File

@@ -3163,7 +3163,7 @@ bool SelectSequence(X64Emitter* e, const Instr* i, const Instr** new_tail) {
return true;
}
}
XELOGE("No sequence match for variant %s", i->opcode->name);
XELOGE("No sequence match for variant {}", i->opcode->name);
return false;
}

View File

@@ -32,12 +32,13 @@ bool trace_enabled = true;
#define THREAD_MATCH \
(!TARGET_THREAD || thread_state->thread_id() == TARGET_THREAD)
#define IFLUSH()
#define IPRINT(s) \
if (trace_enabled && THREAD_MATCH) xe::LogLine(xe::LogLevel::Debug, 't', s)
#define IPRINT(s) \
if (trace_enabled && THREAD_MATCH) \
xe::logging::AppendLogLine(xe::LogLevel::Debug, 't', s)
#define DFLUSH()
#define DPRINT(...) \
if (trace_enabled && THREAD_MATCH) \
xe::LogLineFormat(xe::LogLevel::Debug, 't', __VA_ARGS__)
xe::logging::AppendLogLineFormat(xe::LogLevel::Debug, 't', __VA_ARGS__)
uint32_t GetTracingMode() {
uint32_t mode = 0;
@@ -58,36 +59,35 @@ void TraceString(void* raw_context, const char* str) {
void TraceContextLoadI8(void* raw_context, uint64_t offset, uint8_t value) {
auto thread_state = *reinterpret_cast<ThreadState**>(raw_context);
DPRINT("%d (%X) = ctx i8 +%" PRIu64 "\n", (int8_t)value, value, offset);
DPRINT("{} ({:X}) = ctx i8 +{}\n", (int8_t)value, value, offset);
}
void TraceContextLoadI16(void* raw_context, uint64_t offset, uint16_t value) {
auto thread_state = *reinterpret_cast<ThreadState**>(raw_context);
DPRINT("%d (%X) = ctx i16 +%" PRIu64 "\n", (int16_t)value, value, offset);
DPRINT("{} ({:X}) = ctx i16 +{}\n", (int16_t)value, value, offset);
}
void TraceContextLoadI32(void* raw_context, uint64_t offset, uint32_t value) {
auto thread_state = *reinterpret_cast<ThreadState**>(raw_context);
DPRINT("%d (%X) = ctx i32 +%" PRIu64 "\n", (int32_t)value, value, offset);
DPRINT("{} ({:X}) = ctx i32 +{}\n", (int32_t)value, value, offset);
}
void TraceContextLoadI64(void* raw_context, uint64_t offset, uint64_t value) {
auto thread_state = *reinterpret_cast<ThreadState**>(raw_context);
DPRINT("%" PRId64 " (%" PRIX64 ") = ctx i64 +%" PRIu64 "\n", (int64_t)value,
value, offset);
DPRINT("{} ({:X}) = ctx i64 +{}\n", (int64_t)value, value, offset);
}
void TraceContextLoadF32(void* raw_context, uint64_t offset, __m128 value) {
auto thread_state = *reinterpret_cast<ThreadState**>(raw_context);
DPRINT("%e (%X) = ctx f32 +%" PRIu64 "\n", xe::m128_f32<0>(value),
DPRINT("{} ({:X}) = ctx f32 +{}\n", xe::m128_f32<0>(value),
xe::m128_i32<0>(value), offset);
}
void TraceContextLoadF64(void* raw_context, uint64_t offset,
const double* value) {
auto thread_state = *reinterpret_cast<ThreadState**>(raw_context);
auto v = _mm_loadu_pd(value);
DPRINT("%le (%" PRIX64 ") = ctx f64 +%" PRIu64 "\n", xe::m128_f64<0>(v),
xe::m128_i64<0>(v), offset);
DPRINT("{} ({:X}) = ctx f64 +{}\n", xe::m128_f64<0>(v), xe::m128_i64<0>(v),
offset);
}
void TraceContextLoadV128(void* raw_context, uint64_t offset, __m128 value) {
auto thread_state = *reinterpret_cast<ThreadState**>(raw_context);
DPRINT("[%e, %e, %e, %e] [%.8X, %.8X, %.8X, %.8X] = ctx v128 +%" PRIu64 "\n",
DPRINT("[{}, {}, {}, {}] [{:08X}, {:08X}, {:08X}, {:08X}] = ctx v128 +{}\n",
xe::m128_f32<0>(value), xe::m128_f32<1>(value), xe::m128_f32<2>(value),
xe::m128_f32<3>(value), xe::m128_i32<0>(value), xe::m128_i32<1>(value),
xe::m128_i32<2>(value), xe::m128_i32<3>(value), offset);
@@ -95,36 +95,35 @@ void TraceContextLoadV128(void* raw_context, uint64_t offset, __m128 value) {
void TraceContextStoreI8(void* raw_context, uint64_t offset, uint8_t value) {
auto thread_state = *reinterpret_cast<ThreadState**>(raw_context);
DPRINT("ctx i8 +%" PRIu64 " = %d (%X)\n", offset, (int8_t)value, value);
DPRINT("ctx i8 +{} = {} ({:X})\n", offset, (int8_t)value, value);
}
void TraceContextStoreI16(void* raw_context, uint64_t offset, uint16_t value) {
auto thread_state = *reinterpret_cast<ThreadState**>(raw_context);
DPRINT("ctx i16 +%" PRIu64 " = %d (%X)\n", offset, (int16_t)value, value);
DPRINT("ctx i16 +{} = {} ({:X})\n", offset, (int16_t)value, value);
}
void TraceContextStoreI32(void* raw_context, uint64_t offset, uint32_t value) {
auto thread_state = *reinterpret_cast<ThreadState**>(raw_context);
DPRINT("ctx i32 +%" PRIu64 " = %d (%X)\n", offset, (int32_t)value, value);
DPRINT("ctx i32 +{} = {} ({:X})\n", offset, (int32_t)value, value);
}
void TraceContextStoreI64(void* raw_context, uint64_t offset, uint64_t value) {
auto thread_state = *reinterpret_cast<ThreadState**>(raw_context);
DPRINT("ctx i64 +%" PRIu64 " = %" PRId64 " (%" PRIX64 ")\n", offset,
(int64_t)value, value);
DPRINT("ctx i64 +{} = {} ({:X})\n", offset, (int64_t)value, value);
}
void TraceContextStoreF32(void* raw_context, uint64_t offset, __m128 value) {
auto thread_state = *reinterpret_cast<ThreadState**>(raw_context);
DPRINT("ctx f32 +%" PRIu64 " = %e (%X)\n", offset, xe::m128_f32<0>(value),
DPRINT("ctx f32 +{} = {} ({:X})\n", offset, xe::m128_f32<0>(value),
xe::m128_i32<0>(value));
}
void TraceContextStoreF64(void* raw_context, uint64_t offset,
const double* value) {
auto thread_state = *reinterpret_cast<ThreadState**>(raw_context);
auto v = _mm_loadu_pd(value);
DPRINT("ctx f64 +%" PRIu64 " = %le (%" PRIX64 ")\n", offset,
xe::m128_f64<0>(v), xe::m128_i64<0>(v));
DPRINT("ctx f64 +{} = {} ({:X})\n", offset, xe::m128_f64<0>(v),
xe::m128_i64<0>(v));
}
void TraceContextStoreV128(void* raw_context, uint64_t offset, __m128 value) {
auto thread_state = *reinterpret_cast<ThreadState**>(raw_context);
DPRINT("ctx v128 +%" PRIu64 " = [%e, %e, %e, %e] [%.8X, %.8X, %.8X, %.8X]\n",
DPRINT("ctx v128 +{} = [{}, {}, {}, {}] [{:08X}, {:08X}, {:08X}, {:08X}]\n",
offset, xe::m128_f32<0>(value), xe::m128_f32<1>(value),
xe::m128_f32<2>(value), xe::m128_f32<3>(value), xe::m128_i32<0>(value),
xe::m128_i32<1>(value), xe::m128_i32<2>(value),
@@ -133,80 +132,79 @@ void TraceContextStoreV128(void* raw_context, uint64_t offset, __m128 value) {
void TraceMemoryLoadI8(void* raw_context, uint32_t address, uint8_t value) {
auto thread_state = *reinterpret_cast<ThreadState**>(raw_context);
DPRINT("%d (%X) = load.i8 %.8X\n", (int8_t)value, value, address);
DPRINT("{} ({:X}) = load.i8 {:08X}\n", (int8_t)value, value, address);
}
void TraceMemoryLoadI16(void* raw_context, uint32_t address, uint16_t value) {
auto thread_state = *reinterpret_cast<ThreadState**>(raw_context);
DPRINT("%d (%X) = load.i16 %.8X\n", (int16_t)value, value, address);
DPRINT("{} ({:X}) = load.i16 {:08X}\n", (int16_t)value, value, address);
}
void TraceMemoryLoadI32(void* raw_context, uint32_t address, uint32_t value) {
auto thread_state = *reinterpret_cast<ThreadState**>(raw_context);
DPRINT("%d (%X) = load.i32 %.8X\n", (int32_t)value, value, address);
DPRINT("{} ({:X}) = load.i32 {:08X}\n", (int32_t)value, value, address);
}
void TraceMemoryLoadI64(void* raw_context, uint32_t address, uint64_t value) {
auto thread_state = *reinterpret_cast<ThreadState**>(raw_context);
DPRINT("%" PRId64 " (%" PRIX64 ") = load.i64 %.8X\n", (int64_t)value, value,
address);
DPRINT("{} ({:X}) = load.i64 {:08X}\n", (int64_t)value, value, address);
}
void TraceMemoryLoadF32(void* raw_context, uint32_t address, __m128 value) {
auto thread_state = *reinterpret_cast<ThreadState**>(raw_context);
DPRINT("%e (%X) = load.f32 %.8X\n", xe::m128_f32<0>(value),
DPRINT("{} ({:X}) = load.f32 {:08X}\n", xe::m128_f32<0>(value),
xe::m128_i32<0>(value), address);
}
void TraceMemoryLoadF64(void* raw_context, uint32_t address, __m128 value) {
auto thread_state = *reinterpret_cast<ThreadState**>(raw_context);
DPRINT("%le (%" PRIX64 ") = load.f64 %.8X\n", xe::m128_f64<0>(value),
DPRINT("{} ({:X}) = load.f64 {:08X}\n", xe::m128_f64<0>(value),
xe::m128_i64<0>(value), address);
}
void TraceMemoryLoadV128(void* raw_context, uint32_t address, __m128 value) {
auto thread_state = *reinterpret_cast<ThreadState**>(raw_context);
DPRINT("[%e, %e, %e, %e] [%.8X, %.8X, %.8X, %.8X] = load.v128 %.8X\n",
xe::m128_f32<0>(value), xe::m128_f32<1>(value), xe::m128_f32<2>(value),
xe::m128_f32<3>(value), xe::m128_i32<0>(value), xe::m128_i32<1>(value),
xe::m128_i32<2>(value), xe::m128_i32<3>(value), address);
DPRINT(
"[{}, {}, {}, {}] [{:08X}, {:08X}, {:08X}, {:08X}] = load.v128 {:08X}\n",
xe::m128_f32<0>(value), xe::m128_f32<1>(value), xe::m128_f32<2>(value),
xe::m128_f32<3>(value), xe::m128_i32<0>(value), xe::m128_i32<1>(value),
xe::m128_i32<2>(value), xe::m128_i32<3>(value), address);
}
void TraceMemoryStoreI8(void* raw_context, uint32_t address, uint8_t value) {
auto thread_state = *reinterpret_cast<ThreadState**>(raw_context);
DPRINT("store.i8 %.8X = %d (%X)\n", address, (int8_t)value, value);
DPRINT("store.i8 {:08X} = {} ({:X})\n", address, (int8_t)value, value);
}
void TraceMemoryStoreI16(void* raw_context, uint32_t address, uint16_t value) {
auto thread_state = *reinterpret_cast<ThreadState**>(raw_context);
DPRINT("store.i16 %.8X = %d (%X)\n", address, (int16_t)value, value);
DPRINT("store.i16 {:08X} = {} ({:X})\n", address, (int16_t)value, value);
}
void TraceMemoryStoreI32(void* raw_context, uint32_t address, uint32_t value) {
auto thread_state = *reinterpret_cast<ThreadState**>(raw_context);
DPRINT("store.i32 %.8X = %d (%X)\n", address, (int32_t)value, value);
DPRINT("store.i32 {:08X} = {} ({:X})\n", address, (int32_t)value, value);
}
void TraceMemoryStoreI64(void* raw_context, uint32_t address, uint64_t value) {
auto thread_state = *reinterpret_cast<ThreadState**>(raw_context);
DPRINT("store.i64 %.8X = %" PRId64 " (%" PRIX64 ")\n", address,
(int64_t)value, value);
DPRINT("store.i64 {:08X} = {} ({:X})\n", address, (int64_t)value, value);
}
void TraceMemoryStoreF32(void* raw_context, uint32_t address, __m128 value) {
auto thread_state = *reinterpret_cast<ThreadState**>(raw_context);
DPRINT("store.f32 %.8X = %e (%X)\n", address, xe::m128_f32<0>(value),
DPRINT("store.f32 {:08X} = {} ({:X})\n", address, xe::m128_f32<0>(value),
xe::m128_i32<0>(value));
}
void TraceMemoryStoreF64(void* raw_context, uint32_t address, __m128 value) {
auto thread_state = *reinterpret_cast<ThreadState**>(raw_context);
DPRINT("store.f64 %.8X = %le (%" PRIX64 ")\n", address,
xe::m128_f64<0>(value), xe::m128_i64<0>(value));
DPRINT("store.f64 {:08X} = {} ({:X})\n", address, xe::m128_f64<0>(value),
xe::m128_i64<0>(value));
}
void TraceMemoryStoreV128(void* raw_context, uint32_t address, __m128 value) {
auto thread_state = *reinterpret_cast<ThreadState**>(raw_context);
DPRINT("store.v128 %.8X = [%e, %e, %e, %e] [%.8X, %.8X, %.8X, %.8X]\n",
address, xe::m128_f32<0>(value), xe::m128_f32<1>(value),
xe::m128_f32<2>(value), xe::m128_f32<3>(value), xe::m128_i32<0>(value),
xe::m128_i32<1>(value), xe::m128_i32<2>(value),
xe::m128_i32<3>(value));
DPRINT(
"store.v128 {:08X} = [{}, {}, {}, {}] [{:08X}, {:08X}, {:08X}, {:08X}]\n",
address, xe::m128_f32<0>(value), xe::m128_f32<1>(value),
xe::m128_f32<2>(value), xe::m128_f32<3>(value), xe::m128_i32<0>(value),
xe::m128_i32<1>(value), xe::m128_i32<2>(value), xe::m128_i32<3>(value));
}
void TraceMemset(void* raw_context, uint32_t address, uint8_t value,
uint32_t length) {
auto thread_state = *reinterpret_cast<ThreadState**>(raw_context);
DPRINT("memset %.8X-%.8X (%d) = %.2X", address, address + length, length,
value);
DPRINT("memset {:08X}-{:08X} ({}) = {:02X}", address, address + length,
length, value);
}
} // namespace x64

View File

@@ -83,7 +83,7 @@ bool ElfModule::Load(const std::string_view name, const std::string_view path,
// Not a PPC ELF!
XELOGE(
"ELF: Could not load ELF because target machine is not PPC! (target: "
"%d)",
"{})",
uint32_t(hdr->e_machine));
return false;
}
@@ -114,7 +114,7 @@ bool ElfModule::Load(const std::string_view name, const std::string_view path,
// Allocate and copy into memory.
// Base address @ 0x80000000
if (phdr[i].p_vaddr < 0x80000000 || phdr[i].p_vaddr > 0x9FFFFFFF) {
XELOGE("ELF: Could not allocate memory for section @ address 0x%.8X",
XELOGE("ELF: Could not allocate memory for section @ address {:#08X}",
uint32_t(phdr[i].p_vaddr));
return false;
}

View File

@@ -32,16 +32,16 @@ FunctionDebugInfo::~FunctionDebugInfo() {
void FunctionDebugInfo::Dump() {
if (source_disasm_) {
XELOGD("PPC:\n%s\n", source_disasm_);
XELOGD("PPC:\n{}\n", source_disasm_);
}
if (raw_hir_disasm_) {
XELOGD("Unoptimized HIR:\n%s\n", raw_hir_disasm_);
XELOGD("Unoptimized HIR:\n{}\n", raw_hir_disasm_);
}
if (hir_disasm_) {
XELOGD("Optimized HIR:\n%s\n", hir_disasm_);
XELOGD("Optimized HIR:\n{}\n", hir_disasm_);
}
if (machine_code_disasm_) {
XELOGD("Machine Code:\n%s\n", machine_code_disasm_);
XELOGD("Machine Code:\n{}\n", machine_code_disasm_);
}
}

View File

@@ -339,7 +339,7 @@ bool MMIOHandler::ExceptionCallback(Exception* ex) {
DecodedMov mov = {0};
bool decoded = TryDecodeMov(p, &mov);
if (!decoded) {
XELOGE("Unable to decode MMIO mov at %p", p);
XELOGE("Unable to decode MMIO mov at {}", p);
assert_always("Unknown MMIO instruction type");
return false;
}

View File

@@ -22,8 +22,8 @@ namespace ppc {
#define XEREGISTERINSTR(name) \
RegisterOpcodeEmitter(PPCOpcode::name, InstrEmit_##name);
#define XEINSTRNOTIMPLEMENTED() \
XELOGE("Unimplemented instruction: %s", __FUNCTION__); \
#define XEINSTRNOTIMPLEMENTED() \
XELOGE("Unimplemented instruction: {}", __func__); \
assert_always("Instruction not implemented");
} // namespace ppc

View File

@@ -146,7 +146,7 @@ bool PPCHIRBuilder::Emit(GuestFunction* function, uint32_t flags) {
instr_offset_list_[offset] = first_instr;
if (opcode == PPCOpcode::kInvalid) {
XELOGE("Invalid instruction %.8llX %.8X", address, code);
XELOGE("Invalid instruction {:08X} {:08X}", address, code);
Comment("INVALID!");
// TraceInvalidInstruction(i);
continue;
@@ -169,7 +169,7 @@ bool PPCHIRBuilder::Emit(GuestFunction* function, uint32_t flags) {
i.opcode_info = &opcode_info;
if (!opcode_info.emit || opcode_info.emit(*this, i)) {
auto& disasm_info = GetOpcodeDisasmInfo(opcode);
XELOGE("Unimplemented instr %.8llX %.8X %s", address, code,
XELOGE("Unimplemented instr {:08X} {:08X} {}", address, code,
disasm_info.name);
Comment("UNIMPLEMENTED!");
DebugBreak();

View File

@@ -51,7 +51,7 @@ bool PPCScanner::Scan(GuestFunction* function, FunctionDebugInfo* debug_info) {
Memory* memory = frontend_->memory();
LOGPPC("Analyzing function %.8X...", function->address());
LOGPPC("Analyzing function {:08X}...", function->address());
// For debug info, only if needed.
uint32_t address_reference_count = 0;
@@ -71,7 +71,7 @@ bool PPCScanner::Scan(GuestFunction* function, FunctionDebugInfo* debug_info) {
// If we fetched 0 assume that we somehow hit one of the awesome
// 'no really we meant to end after that bl' functions.
if (!code) {
LOGPPC("function end %.8X (0x00000000 read)", address);
LOGPPC("function end {:08X} (0x00000000 read)", address);
// Don't include the 0's.
address -= 4;
break;
@@ -106,16 +106,17 @@ bool PPCScanner::Scan(GuestFunction* function, FunctionDebugInfo* debug_info) {
// Invalid instruction.
// We can just ignore it because there's (very little)/no chance it'll
// affect flow control.
LOGPPC("Invalid instruction at %.8X: %.8X", address, code);
LOGPPC("Invalid instruction at {:08X}: {:08X}", address, code);
} else if (code == 0x4E800020) {
// blr -- unconditional branch to LR.
// This is generally a return.
if (furthest_target > address) {
// Remaining targets within function, not end.
LOGPPC("ignoring blr %.8X (branch to %.8X)", address, furthest_target);
LOGPPC("ignoring blr {:08X} (branch to {:08X})", address,
furthest_target);
} else {
// Function end point.
LOGPPC("function end %.8X", address);
LOGPPC("function end {:08X}", address);
ends_fn = true;
}
ends_block = true;
@@ -126,10 +127,11 @@ bool PPCScanner::Scan(GuestFunction* function, FunctionDebugInfo* debug_info) {
// TODO(benvanik): decode jump tables.
if (furthest_target > address) {
// Remaining targets within function, not end.
LOGPPC("ignoring bctr %.8X (branch to %.8X)", address, furthest_target);
LOGPPC("ignoring bctr {:08X} (branch to {:08X})", address,
furthest_target);
} else {
// Function end point.
LOGPPC("function end %.8X", address);
LOGPPC("function end {:08X}", address);
ends_fn = true;
}
ends_block = true;
@@ -137,25 +139,25 @@ bool PPCScanner::Scan(GuestFunction* function, FunctionDebugInfo* debug_info) {
// b/ba/bl/bla
uint32_t target = d.I.ADDR();
if (d.I.LK()) {
LOGPPC("bl %.8X -> %.8X", address, target);
LOGPPC("bl {:08X} -> {:08X}", address, target);
// Queue call target if needed.
// GetOrInsertFunction(target);
} else {
LOGPPC("b %.8X -> %.8X", address, target);
LOGPPC("b {:08X} -> {:08X}", address, target);
// If the target is back into the function and there's no further target
// we are at the end of a function.
// (Indirect branches may still go beyond, but no way of knowing).
if (target >= start_address && target < address &&
furthest_target <= address) {
LOGPPC("function end %.8X (back b)", address);
LOGPPC("function end {:08X} (back b)", address);
ends_fn = true;
}
// If the target is not a branch and it goes to before the current
// address it's definitely a tail call.
if (!ends_fn && target < start_address && furthest_target <= address) {
LOGPPC("function end %.8X (back b before addr)", address);
LOGPPC("function end {:08X} (back b before addr)", address);
ends_fn = true;
}
@@ -164,7 +166,7 @@ bool PPCScanner::Scan(GuestFunction* function, FunctionDebugInfo* debug_info) {
// of the function somewhere, so ensure we don't have any branches over
// it.
if (!ends_fn && furthest_target <= address && IsRestGprLr(target)) {
LOGPPC("function end %.8X (__restgprlr_*)", address);
LOGPPC("function end {:08X} (__restgprlr_*)", address);
ends_fn = true;
}
@@ -176,7 +178,7 @@ bool PPCScanner::Scan(GuestFunction* function, FunctionDebugInfo* debug_info) {
// This check may hit on functions that jump over data code, so only
// trigger this check in leaf functions (no mfspr lr/prolog).
if (!ends_fn && !starts_with_mfspr_lr && blocks_found == 1) {
LOGPPC("HEURISTIC: ending at simple leaf thunk %.8X", address);
LOGPPC("HEURISTIC: ending at simple leaf thunk {:08X}", address);
ends_fn = true;
}
@@ -213,14 +215,14 @@ bool PPCScanner::Scan(GuestFunction* function, FunctionDebugInfo* debug_info) {
// bc/bca/bcl/bcla
uint32_t target = d.B.ADDR();
if (d.B.LK()) {
LOGPPC("bcl %.8X -> %.8X", address, target);
LOGPPC("bcl {:08X} -> {:08X}", address, target);
// Queue call target if needed.
// TODO(benvanik): see if this is correct - not sure anyone makes
// function calls with bcl.
// GetOrInsertFunction(target);
} else {
LOGPPC("bc %.8X -> %.8X", address, target);
LOGPPC("bc {:08X} -> {:08X}", address, target);
// TODO(benvanik): GetOrInsertFunction? it's likely a BB
@@ -232,17 +234,17 @@ bool PPCScanner::Scan(GuestFunction* function, FunctionDebugInfo* debug_info) {
} else if (opcode == PPCOpcode::bclrx) {
// bclr/bclrl
if (d.XL.LK()) {
LOGPPC("bclrl %.8X", address);
LOGPPC("bclrl {:08X}", address);
} else {
LOGPPC("bclr %.8X", address);
LOGPPC("bclr {:08X}", address);
}
ends_block = true;
} else if (opcode == PPCOpcode::bcctrx) {
// bcctr/bcctrl
if (d.XL.LK()) {
LOGPPC("bcctrl %.8X", address);
LOGPPC("bcctrl {:08X}", address);
} else {
LOGPPC("bcctr %.8X", address);
LOGPPC("bcctr {:08X}", address);
}
ends_block = true;
}
@@ -257,7 +259,8 @@ bool PPCScanner::Scan(GuestFunction* function, FunctionDebugInfo* debug_info) {
address += 4;
if (end_address && address > end_address) {
// Hmm....
LOGPPC("Ran over function bounds! %.8X-%.8X", start_address, end_address);
LOGPPC("Ran over function bounds! {:08X}-{:08X}", start_address,
end_address);
break;
}
}
@@ -267,7 +270,7 @@ bool PPCScanner::Scan(GuestFunction* function, FunctionDebugInfo* debug_info) {
// from someplace valid (like method hints) this may indicate an error.
// It's also possible that we guessed in hole-filling and there's another
// function below this one.
LOGPPC("Function ran under: %.8X-%.8X ended at %.8X", start_address,
LOGPPC("Function ran under: {:08X}-{:08X} ended at {:08X}", start_address,
end_address, address + 4);
}
function->set_end_address(address);
@@ -285,7 +288,7 @@ bool PPCScanner::Scan(GuestFunction* function, FunctionDebugInfo* debug_info) {
debug_info->set_instruction_result_count(instruction_result_count);
}
LOGPPC("Finished analyzing %.8X", start_address);
LOGPPC("Finished analyzing {:08X}", start_address);
return true;
}

View File

@@ -61,13 +61,13 @@ class TestSuite {
bool Load() {
if (!ReadMap()) {
XELOGE("Unable to read map for test %s",
xe::path_to_utf8(src_file_path_).c_str());
XELOGE("Unable to read map for test {}",
xe::path_to_utf8(src_file_path_));
return false;
}
if (!ReadAnnotations()) {
XELOGE("Unable to read annotations for test %s",
xe::path_to_utf8(src_file_path_).c_str());
XELOGE("Unable to read annotations for test {}",
xe::path_to_utf8(src_file_path_));
return false;
}
return true;
@@ -144,8 +144,8 @@ class TestSuite {
std::string label(start + strlen("test_"), strchr(start, ':'));
current_test_case = FindTestCase(label);
if (!current_test_case) {
XELOGE("Test case %s not found in corresponding map for %s",
label.c_str(), xe::path_to_utf8(src_file_path_).c_str());
XELOGE("Test case {} not found in corresponding map for {}", label,
xe::path_to_utf8(src_file_path_));
return false;
}
} else if (strlen(start) > 3 && start[0] == '#' && start[1] == '_') {
@@ -160,8 +160,8 @@ class TestSuite {
value.erase(value.end() - 1);
}
if (!current_test_case) {
XELOGE("Annotation outside of test case in %s",
xe::path_to_utf8(src_file_path_).c_str());
XELOGE("Annotation outside of test case in {}",
xe::path_to_utf8(src_file_path_));
return false;
}
current_test_case->annotations.emplace_back(key, value);
@@ -214,8 +214,8 @@ class TestRunner {
// Load the binary module.
auto module = std::make_unique<xe::cpu::RawModule>(processor_.get());
if (!module->LoadFile(START_ADDRESS, suite.bin_file_path())) {
XELOGE("Unable to load test binary %s",
xe::path_to_utf8(suite.bin_file_path).c_str());
XELOGE("Unable to load test binary {}",
xe::path_to_utf8(suite.bin_file_path()));
return false;
}
processor_->AddModule(std::move(module));
@@ -313,9 +313,9 @@ class TestRunner {
if (!ppc_context->CompareRegWithString(
reg_name.c_str(), reg_value.c_str(), actual_value)) {
any_failed = true;
XELOGE("Register %s assert failed:\n", reg_name.c_str());
XELOGE(" Expected: %s == %s\n", reg_name.c_str(), reg_value.c_str());
XELOGE(" Actual: %s == %s\n", reg_name.c_str(), actual_value);
XELOGE("Register {} assert failed:\n", reg_name);
XELOGE(" Expected: {} == {}\n", reg_name, reg_value);
XELOGE(" Actual: {} == {}\n", reg_name, actual_value);
}
} else if (it.first == "MEMORY_OUT") {
size_t space_pos = it.second.find(" ");
@@ -338,9 +338,9 @@ class TestRunner {
uint8_t actual = *p;
if (expected != actual) {
any_failed = true;
XELOGE("Memory %s assert failed:\n", address_str.c_str());
XELOGE(" Expected: %.8X %.2X\n", current_address, expected);
XELOGE(" Actual: %.8X %.2X\n", current_address, actual);
XELOGE("Memory {} assert failed:\n", address_str);
XELOGE(" Expected: {:08X} {:02X}\n", current_address, expected);
XELOGE(" Actual: {:08X} {:02X}\n", current_address, actual);
}
++p;
}
@@ -418,7 +418,7 @@ bool RunTests(const std::string_view test_name) {
XELOGE("No tests discovered - invalid path?");
return false;
}
XELOGI("%d tests discovered.", (int)test_files.size());
XELOGI("{} tests discovered.", test_files.size());
XELOGI("");
std::vector<TestSuite> test_suites;
@@ -429,8 +429,7 @@ bool RunTests(const std::string_view test_name) {
continue;
}
if (!test_suite.Load()) {
XELOGE("TEST SUITE %s FAILED TO LOAD",
xe::path_to_utf8(test_path).c_str());
XELOGE("TEST SUITE {} FAILED TO LOAD", xe::path_to_utf8(test_path));
load_failed = true;
continue;
}
@@ -440,13 +439,13 @@ bool RunTests(const std::string_view test_name) {
XELOGE("One or more test suites failed to load.");
}
XELOGI("%d tests loaded.", (int)test_suites.size());
XELOGI("{} tests loaded.", test_suites.size());
TestRunner runner;
for (auto& test_suite : test_suites) {
XELOGI("%s.s:", xe::path_to_utf8(test_suite.name()).c_str());
XELOGI("{}.s:", test_suite.name());
for (auto& test_case : test_suite.test_cases()) {
XELOGI(" - %s", test_case.name.c_str());
XELOGI(" - {}", test_case.name);
ProtectedRunTest(test_suite, runner, test_case, failed_count,
passed_count);
}
@@ -455,9 +454,9 @@ bool RunTests(const std::string_view test_name) {
}
XELOGI("");
XELOGI("Total tests: %d", failed_count + passed_count);
XELOGI("Passed: %d", passed_count);
XELOGI("Failed: %d", failed_count);
XELOGI("Total tests: {}", failed_count + passed_count);
XELOGI("Passed: {}", passed_count);
XELOGI("Failed: {}", failed_count);
return failed_count ? false : true;
}

View File

@@ -323,7 +323,7 @@ bool Processor::Execute(ThreadState* thread_state, uint32_t address) {
auto function = ResolveFunction(address);
if (!function) {
// Symbol not found in any module.
XELOGCPU("Execute(%.8X): failed to find function", address);
XELOGCPU("Execute({:08X}): failed to find function", address);
return false;
}
@@ -354,7 +354,7 @@ bool Processor::ExecuteRaw(ThreadState* thread_state, uint32_t address) {
auto function = ResolveFunction(address);
if (!function) {
// Symbol not found in any module.
XELOGCPU("Execute(%.8X): failed to find function", address);
XELOGCPU("Execute({:08X}): failed to find function", address);
return false;
}
@@ -973,8 +973,9 @@ bool Processor::StepToGuestAddress(uint32_t thread_id, uint32_t pc) {
if (functions.empty()) {
// Function hasn't been generated yet. Generate it.
if (!ResolveFunction(pc)) {
XELOGE("Processor::StepToAddress(%.8X) - Function could not be resolved",
pc);
XELOGE(
"Processor::StepToAddress({:08X}) - Function could not be resolved",
pc);
return false;
}
}

View File

@@ -128,7 +128,7 @@ uint32_t XexModule::GetProcAddress(uint16_t ordinal) const {
ordinal -= export_table->base;
if (ordinal > export_table->count) {
XELOGE("GetProcAddress(%.3X): ordinal out of bounds", ordinal);
XELOGE("GetProcAddress({:03X}): ordinal out of bounds", ordinal);
return 0;
}
@@ -290,7 +290,7 @@ int XexModule::ApplyPatch(XexModule* module) {
&patch_header->info, headerpatch_size,
file_format_header->compression_info.normal.window_size, header_ptr);
if (result_code) {
XELOGE("XEX header patch application failed, error code %d", result_code);
XELOGE("XEX header patch application failed, error code {}", result_code);
return result_code;
}
@@ -315,7 +315,7 @@ int XexModule::ApplyPatch(XexModule* module) {
xe::kMemoryProtectRead | xe::kMemoryProtectWrite);
if (!alloc_result) {
XELOGE("Unable to allocate XEX memory at %.8X-%.8X.", addr_new_mem,
XELOGE("Unable to allocate XEX memory at {:08X}-{:08X}.", addr_new_mem,
size_delta);
assert_always();
return 6;
@@ -440,7 +440,7 @@ int XexModule::ApplyPatch(XexModule* module) {
->Decommit(addr_free_mem, size_delta);
if (!free_result) {
XELOGE("Unable to decommit XEX memory at %.8X-%.8X.", addr_free_mem,
XELOGE("Unable to decommit XEX memory at {:08X}-{:08X}.", addr_free_mem,
size_delta);
assert_always();
}
@@ -455,12 +455,12 @@ int XexModule::ApplyPatch(XexModule* module) {
xe::byte_swap<uint32_t>(patch_header->target_version.value);
XELOGI(
"XEX patch applied successfully: base version: %d.%d.%d.%d, new "
"version: %d.%d.%d.%d",
"XEX patch applied successfully: base version: {}.{}.{}.{}, new "
"version: {}.{}.{}.{}",
source_ver.major, source_ver.minor, source_ver.build, source_ver.qfe,
target_ver.major, target_ver.minor, target_ver.build, target_ver.qfe);
} else {
XELOGE("XEX patch application failed, error code %d", result_code);
XELOGE("XEX patch application failed, error code {}", result_code);
}
if (free_input) {
@@ -536,7 +536,7 @@ int XexModule::ReadImageUncompressed(const void* xex_addr, size_t xex_length) {
xe::kMemoryAllocationReserve | xe::kMemoryAllocationCommit,
xe::kMemoryProtectRead | xe::kMemoryProtectWrite);
if (!alloc_result) {
XELOGE("Unable to allocate XEX memory at %.8X-%.8X.", base_address_,
XELOGE("Unable to allocate XEX memory at {:08X}-{:08X}.", base_address_,
uncompressed_size);
return 2;
}
@@ -603,7 +603,7 @@ int XexModule::ReadImageBasicCompressed(const void* xex_addr,
xe::kMemoryAllocationReserve | xe::kMemoryAllocationCommit,
xe::kMemoryProtectRead | xe::kMemoryProtectWrite);
if (!alloc_result) {
XELOGE("Unable to allocate XEX memory at %.8X-%.8X.", base_address_,
XELOGE("Unable to allocate XEX memory at {:08X}-{:08X}.", base_address_,
uncompressed_size);
return 1;
}
@@ -761,7 +761,7 @@ int XexModule::ReadImageCompressed(const void* xex_addr, size_t xex_length) {
compress_buffer, d - compress_buffer, buffer, uncompressed_size,
compression_info->normal.window_size, nullptr, 0);
} else {
XELOGE("Unable to allocate XEX memory at %.8X-%.8X.", base_address_,
XELOGE("Unable to allocate XEX memory at {:08X}-{:08X}.", base_address_,
uncompressed_size);
result_code = 3;
}
@@ -933,12 +933,12 @@ bool XexModule::Load(const std::string_view name, const std::string_view path,
// We'll try using both XEX2 keys to see if any give a valid PE
int result_code = ReadImage(xex_addr, xex_length, false);
if (result_code) {
XELOGW("XEX load failed with code %d, trying with devkit encryption key...",
XELOGW("XEX load failed with code {}, trying with devkit encryption key...",
result_code);
result_code = ReadImage(xex_addr, xex_length, true);
if (result_code) {
XELOGE("XEX load failed with code %d, tried both encryption keys",
XELOGE("XEX load failed with code {}, tried both encryption keys",
result_code);
return false;
}
@@ -1132,9 +1132,9 @@ bool XexModule::SetupLibraryImports(const std::string_view name,
// Import not resolved?
if (!kernel_export && !user_export_addr) {
XELOGW(
"WARNING: an import variable was not resolved! (library: %s, import "
"lib: %s, ordinal: %.3X)",
name_.c_str(), name.c_str(), ordinal);
"WARNING: an import variable was not resolved! (library: {}, import "
"lib: {}, ordinal: {:03X})",
name_, name, ordinal);
}
StringBuffer import_name;
@@ -1166,7 +1166,7 @@ bool XexModule::SetupLibraryImports(const std::string_view name,
} else {
// Not implemented - write with a dummy value.
*record_slot = 0xD000BEEF | (kernel_export->ordinal & 0xFFF) << 16;
XELOGCPU("WARNING: imported a variable with no value: %s",
XELOGCPU("WARNING: imported a variable with no value: {}",
kernel_export->name);
}
}
@@ -1251,8 +1251,8 @@ bool XexModule::SetupLibraryImports(const std::string_view name,
(GuestFunction::ExternHandler)kernel_export->function_data.shim;
}
} else {
XELOGW("WARNING: Imported kernel function %s is unimplemented!",
import_name.buffer());
XELOGW("WARNING: Imported kernel function {} is unimplemented!",
import_name.to_string_view());
}
static_cast<GuestFunction*>(function)->SetupExtern(handler,
kernel_export);