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

@@ -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;
}