Skip to content
Permalink
Browse files
Merge pull request #9265 from lioncash/core-log3
Core: Convert logging over to fmt pt.3
  • Loading branch information
leoetlino committed Nov 23, 2020
2 parents b53127a + cbbf044 commit b555f0f
Show file tree
Hide file tree
Showing 36 changed files with 572 additions and 541 deletions.
@@ -22,10 +22,10 @@ bool GCIFile::LoadHeader()
if (!save_file)
return false;

INFO_LOG(EXPANSIONINTERFACE, "Reading header from disk for %s", m_filename.c_str());
INFO_LOG_FMT(EXPANSIONINTERFACE, "Reading header from disk for {}", m_filename);
if (!save_file.ReadBytes(&m_gci_header, sizeof(m_gci_header)))
{
ERROR_LOG(EXPANSIONINTERFACE, "Failed to read header for %s", m_filename.c_str());
ERROR_LOG_FMT(EXPANSIONINTERFACE, "Failed to read header for {}", m_filename);
return false;
}

@@ -43,25 +43,25 @@ bool GCIFile::LoadSaveBlocks()
if (!save_file)
return false;

INFO_LOG(EXPANSIONINTERFACE, "Reading savedata from disk for %s", m_filename.c_str());
u16 num_blocks = m_gci_header.m_block_count;
INFO_LOG_FMT(EXPANSIONINTERFACE, "Reading savedata from disk for {}", m_filename);
const u16 num_blocks = m_gci_header.m_block_count;

const u32 size = num_blocks * BLOCK_SIZE;
u64 file_size = save_file.GetSize();
const u64 file_size = save_file.GetSize();
if (file_size != size + DENTRY_SIZE)
{
ERROR_LOG(EXPANSIONINTERFACE,
"%s\nwas not loaded because it is an invalid GCI.\n File size (0x%" PRIx64
") does not match the size recorded in the header (0x%x)",
m_filename.c_str(), file_size, size + DENTRY_SIZE);
ERROR_LOG_FMT(EXPANSIONINTERFACE,
"{}\nwas not loaded because it is an invalid GCI.\n File size ({:#x}) does not "
"match the size recorded in the header ({:#x})",
m_filename.c_str(), file_size, size + DENTRY_SIZE);
return false;
}

m_save_data.resize(num_blocks);
save_file.Seek(DENTRY_SIZE, SEEK_SET);
if (!save_file.ReadBytes(m_save_data.data(), size))
{
ERROR_LOG(EXPANSIONINTERFACE, "Failed to read data from GCI file %s", m_filename.c_str());
ERROR_LOG_FMT(EXPANSIONINTERFACE, "Failed to read data from GCI file {}", m_filename);
m_save_data.clear();
return false;
}
@@ -889,7 +889,7 @@ GCMemcardImportFileRetVal GCMemcard::ImportFile(const DEntry& direntry,
for (int i = 0; i < fileBlocks; ++i)
{
if (firstBlock == 0xFFFF)
PanicAlert("Fatal Error");
PanicAlertFmt("Fatal Error");
m_data_blocks[firstBlock - MC_FST_BLOCKS] = saveBlocks[i];
if (i == fileBlocks - 1)
nextBlock = 0xFFFF;
@@ -44,10 +44,10 @@ bool GCMemcardDirectory::LoadGCI(Memcard::GCIFile gci)
{
if (gci.m_gci_header.GCI_FileName() == already_loaded_gci.m_gci_header.GCI_FileName())
{
ERROR_LOG(EXPANSIONINTERFACE,
"%s\nwas not loaded because it has the same internal filename as previously "
"loaded save\n%s",
gci.m_filename.c_str(), already_loaded_gci.m_filename.c_str());
ERROR_LOG_FMT(EXPANSIONINTERFACE,
"{}\nwas not loaded because it has the same internal filename as previously "
"loaded save\n{}",
gci.m_filename, already_loaded_gci.m_filename);
return false;
}
}
@@ -58,26 +58,27 @@ bool GCMemcardDirectory::LoadGCI(Memcard::GCIFile gci)
const u16 num_blocks = gci.m_gci_header.m_block_count;
if (num_blocks > 2043)
{
ERROR_LOG(EXPANSIONINTERFACE,
"%s\nwas not loaded because it is an invalid GCI.\nNumber of blocks claimed to be %u",
gci.m_filename.c_str(), num_blocks);
ERROR_LOG_FMT(
EXPANSIONINTERFACE,
"{}\nwas not loaded because it is an invalid GCI.\nNumber of blocks claimed to be {}",
gci.m_filename, num_blocks);
return false;
}

if (!gci.LoadSaveBlocks())
{
ERROR_LOG(EXPANSIONINTERFACE, "Failed to load data of %s", gci.m_filename.c_str());
ERROR_LOG_FMT(EXPANSIONINTERFACE, "Failed to load data of {}", gci.m_filename);
return false;
}

// reserve storage for the save file in the BAT
u16 first_block = m_bat1.AssignBlocksContiguous(num_blocks);
const u16 first_block = m_bat1.AssignBlocksContiguous(num_blocks);
if (first_block == 0xFFFF)
{
ERROR_LOG(
ERROR_LOG_FMT(
EXPANSIONINTERFACE,
"%s\nwas not loaded because there are not enough free blocks on the virtual memory card",
gci.m_filename.c_str());
"{}\nwas not loaded because there are not enough free blocks on the virtual memory card",
gci.m_filename);
return false;
}
gci.m_gci_header.m_first_block = first_block;
@@ -174,7 +175,7 @@ GCMemcardDirectory::GCMemcardDirectory(const std::string& directory, int slot,
gci.m_dirty = false;
if (!gci.LoadHeader())
{
ERROR_LOG(EXPANSIONINTERFACE, "Failed to load header of %s", filename.c_str());
ERROR_LOG_FMT(EXPANSIONINTERFACE, "Failed to load header of {}", filename);
continue;
}

@@ -329,7 +330,7 @@ s32 GCMemcardDirectory::Write(u32 dest_address, s32 length, const u8* src_addres
{
std::unique_lock<std::mutex> l(m_write_mutex);
if (length != 0x80)
INFO_LOG(EXPANSIONINTERFACE, "Writing to 0x%x. Length: 0x%x", dest_address, length);
INFO_LOG_FMT(EXPANSIONINTERFACE, "Writing to {:#x}. Length: {:#x}", dest_address, length);
s32 block = dest_address / Memcard::BLOCK_SIZE;
u32 offset = dest_address % Memcard::BLOCK_SIZE;
s32 extra = 0; // used for write calls that are across multiple blocks
@@ -377,7 +378,7 @@ s32 GCMemcardDirectory::Write(u32 dest_address, s32 length, const u8* src_addres
m_last_block = SaveAreaRW(block, true);
if (m_last_block == -1)
{
PanicAlertT("Report: GCIFolder Writing to unallocated block 0x%x", block);
PanicAlertFmtT("Report: GCIFolder Writing to unallocated block {0:#x}", block);
exit(0);
}
}
@@ -397,12 +398,12 @@ void GCMemcardDirectory::ClearBlock(u32 address)
{
if (address % Memcard::BLOCK_SIZE)
{
PanicAlertT("GCMemcardDirectory: ClearBlock called with invalid block address");
PanicAlertFmtT("GCMemcardDirectory: ClearBlock called with invalid block address");
return;
}

u32 block = address / Memcard::BLOCK_SIZE;
INFO_LOG(EXPANSIONINTERFACE, "Clearing block %u", block);
const u32 block = address / Memcard::BLOCK_SIZE;
INFO_LOG_FMT(EXPANSIONINTERFACE, "Clearing block {}", block);
switch (block)
{
case 0:
@@ -446,8 +447,8 @@ inline void GCMemcardDirectory::SyncSaves()
{
if (current->m_dir_entries[i].m_gamecode != Memcard::DEntry::UNINITIALIZED_GAMECODE)
{
INFO_LOG(EXPANSIONINTERFACE, "Syncing save 0x%x",
Common::swap32(current->m_dir_entries[i].m_gamecode.data()));
INFO_LOG_FMT(EXPANSIONINTERFACE, "Syncing save {:#x}",
Common::swap32(current->m_dir_entries[i].m_gamecode.data()));
bool added = false;
while (i >= m_saves.size())
{
@@ -467,15 +468,16 @@ inline void GCMemcardDirectory::SyncSaves()

if ((gamecode != 0xFFFFFFFF) && (gamecode != new_gamecode))
{
PanicAlertT("Game overwrote with another games save. Data corruption ahead 0x%x, 0x%x",
Common::swap32(m_saves[i].m_gci_header.m_gamecode.data()),
Common::swap32(current->m_dir_entries[i].m_gamecode.data()));
PanicAlertFmtT(
"Game overwrote with another games save. Data corruption ahead {0:#x}, {1:#x}",
Common::swap32(m_saves[i].m_gci_header.m_gamecode.data()),
Common::swap32(current->m_dir_entries[i].m_gamecode.data()));
}
memcpy((u8*)&(m_saves[i].m_gci_header), (u8*)&(current->m_dir_entries[i]),
Memcard::DENTRY_SIZE);
if (old_start != new_start)
{
INFO_LOG(EXPANSIONINTERFACE, "Save moved from 0x%x to 0x%x", old_start, new_start);
INFO_LOG_FMT(EXPANSIONINTERFACE, "Save moved from {:#x} to {:#x}", old_start, new_start);
m_saves[i].m_used_blocks.clear();
m_saves[i].m_save_data.clear();
}
@@ -487,8 +489,8 @@ inline void GCMemcardDirectory::SyncSaves()
}
else if ((i < m_saves.size()) && (*(u32*)&(m_saves[i].m_gci_header) != 0xFFFFFFFF))
{
INFO_LOG(EXPANSIONINTERFACE, "Clearing and/or deleting save 0x%x",
Common::swap32(m_saves[i].m_gci_header.m_gamecode.data()));
INFO_LOG_FMT(EXPANSIONINTERFACE, "Clearing and/or deleting save {:#x}",
Common::swap32(m_saves[i].m_gci_header.m_gamecode.data()));
m_saves[i].m_gci_header.m_gamecode = Memcard::DEntry::UNINITIALIZED_GAMECODE;
m_saves[i].m_save_data.clear();
m_saves[i].m_used_blocks.clear();
@@ -570,18 +572,19 @@ bool GCMemcardDirectory::SetUsedBlocks(int save_index)
block = current_bat->GetNextBlock(block);
if (block == 0)
{
PanicAlertT("BAT incorrect. Dolphin will now exit");
PanicAlertFmtT("BAT incorrect. Dolphin will now exit");
exit(0);
}
}

u16 num_blocks = m_saves[save_index].m_gci_header.m_block_count;
u16 blocks_from_bat = (u16)m_saves[save_index].m_used_blocks.size();
const u16 num_blocks = m_saves[save_index].m_gci_header.m_block_count;
const u16 blocks_from_bat = static_cast<u16>(m_saves[save_index].m_used_blocks.size());
if (blocks_from_bat != num_blocks)
{
PanicAlertT("Warning: Number of blocks indicated by the BAT (%u) does not match that of the "
"loaded file header (%u)",
blocks_from_bat, num_blocks);
PanicAlertFmtT(
"Warning: Number of blocks indicated by the BAT ({0}) does not match that of the "
"loaded file header ({1})",
blocks_from_bat, num_blocks);
return false;
}

@@ -605,8 +608,8 @@ void GCMemcardDirectory::FlushToFile()
// The save's header has been changed but the actual save blocks haven't been read/written
// to
// skip flushing this file until actual save data is modified
ERROR_LOG(EXPANSIONINTERFACE,
"GCI header modified without corresponding save data changes");
ERROR_LOG_FMT(EXPANSIONINTERFACE,
"GCI header modified without corresponding save data changes");
continue;
}
if (save.m_filename.empty())
@@ -621,8 +624,10 @@ void GCMemcardDirectory::FlushToFile()
default_save_name.insert(default_save_name.end() - 4, '0');
}
if (File::Exists(default_save_name))
PanicAlertT("Failed to find new filename.\n%s\n will be overwritten",
default_save_name.c_str());
{
PanicAlertFmtT("Failed to find new filename.\n{0}\n will be overwritten",
default_save_name);
}
save.m_filename = default_save_name;
}
File::IOFile gci(save.m_filename, "wb");
@@ -641,7 +646,7 @@ void GCMemcardDirectory::FlushToFile()
++errors;
Core::DisplayMessage(
fmt::format("Failed to write save contents to {}", save.m_filename), 4000);
ERROR_LOG(EXPANSIONINTERFACE, "Failed to save data to %s", save.m_filename.c_str());
ERROR_LOG_FMT(EXPANSIONINTERFACE, "Failed to save data to {}", save.m_filename);
}
}
}
@@ -667,7 +672,7 @@ void GCMemcardDirectory::FlushToFile()
const u32 gamecode = Common::swap32(save.m_gci_header.m_gamecode.data());
if (gamecode != m_game_id && gamecode != 0xFFFFFFFF && !save.m_save_data.empty())
{
INFO_LOG(EXPANSIONINTERFACE, "Flushing savedata to disk for %s", save.m_filename.c_str());
INFO_LOG_FMT(EXPANSIONINTERFACE, "Flushing savedata to disk for {}", save.m_filename);
save.m_save_data.clear();
}
}
@@ -45,7 +45,7 @@ MemoryCard::MemoryCard(const std::string& filename, int card_index, u16 size_mbi
m_memcard_data = std::make_unique<u8[]>(m_memory_card_size);
memset(&m_memcard_data[0], 0xFF, m_memory_card_size);

INFO_LOG(EXPANSIONINTERFACE, "Reading memory card %s", m_filename.c_str());
INFO_LOG_FMT(EXPANSIONINTERFACE, "Reading memory card {}", m_filename);
file.ReadBytes(&m_memcard_data[0], m_memory_card_size);
}
else
@@ -69,7 +69,7 @@ MemoryCard::MemoryCard(const std::string& filename, int card_index, u16 size_mbi
// Fills in the remaining blocks
memset(&m_memcard_data[MC_HDR_SIZE], 0xFF, m_memory_card_size - MC_HDR_SIZE);

INFO_LOG(EXPANSIONINTERFACE, "No memory card found. A new one was created instead.");
INFO_LOG_FMT(EXPANSIONINTERFACE, "No memory card found. A new one was created instead.");
}

// Class members (including inherited ones) have now been initialized, so
@@ -113,15 +113,15 @@ void MemoryCard::CheckPath(std::string& memcardPath, const std::string& gameRegi
// If the old file exists we are polite and ask if we should copy it
std::string oldFilename = filename;
filename.replace(filename.size() - 4, 4, ext);
if (PanicYesNoT("Memory Card filename in Slot %c is incorrect\n"
"Region not specified\n\n"
"Slot %c path was changed to\n"
"%s\n"
"Would you like to copy the old file to this new location?\n",
isSlotA ? 'A' : 'B', isSlotA ? 'A' : 'B', filename.c_str()))
if (PanicYesNoFmtT("Memory Card filename in Slot {0} is incorrect\n"
"Region not specified\n\n"
"Slot {1} path was changed to\n"
"{2}\n"
"Would you like to copy the old file to this new location?\n",
isSlotA ? 'A' : 'B', isSlotA ? 'A' : 'B', filename))
{
if (!File::Copy(oldFilename, filename))
PanicAlertT("Copy failed");
PanicAlertFmtT("Copy failed");
}
}
memcardPath = filename; // Always correct the path!
@@ -178,12 +178,12 @@ void MemoryCard::FlushThread()
// Note - file may have changed above, after ctor
if (!file)
{
PanicAlertT(
"Could not write memory card file %s.\n\n"
PanicAlertFmtT(
"Could not write memory card file {0}.\n\n"
"Are you running Dolphin from a CD/DVD, or is the save file maybe write protected?\n\n"
"Are you receiving this after moving the emulator directory?\nIf so, then you may "
"need to re-specify your memory card location in the options.",
m_filename.c_str());
m_filename);

// Exit the flushing thread - further flushes will be ignored unless
// the thread is recreated.
@@ -214,7 +214,7 @@ s32 MemoryCard::Read(u32 src_address, s32 length, u8* dest_address)
{
if (!IsAddressInBounds(src_address))
{
PanicAlertT("MemoryCard: Read called with invalid source address (0x%x)", src_address);
PanicAlertFmtT("MemoryCard: Read called with invalid source address ({0:#x})", src_address);
return -1;
}

@@ -226,7 +226,8 @@ s32 MemoryCard::Write(u32 dest_address, s32 length, const u8* src_address)
{
if (!IsAddressInBounds(dest_address))
{
PanicAlertT("MemoryCard: Write called with invalid destination address (0x%x)", dest_address);
PanicAlertFmtT("MemoryCard: Write called with invalid destination address ({0:#x})",
dest_address);
return -1;
}

@@ -242,7 +243,7 @@ void MemoryCard::ClearBlock(u32 address)
{
if (address & (Memcard::BLOCK_SIZE - 1) || !IsAddressInBounds(address))
{
PanicAlertT("MemoryCard: ClearBlock called on invalid address (0x%x)", address);
PanicAlertFmtT("MemoryCard: ClearBlock called on invalid address ({0:#x})", address);
return;
}
else
@@ -14,6 +14,7 @@

#include "Common/ChunkFile.h"
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
#include "Common/Swap.h"
#include "Core/ConfigManager.h"
#include "Core/CoreTiming.h"
@@ -294,28 +295,29 @@ static void RunSIBuffer(u64 user_data, s64 cycles_late)
{
if (s_com_csr.TSTART)
{
u32 request_length = ConvertSILengthField(s_com_csr.OUTLNGTH);
u32 expected_response_length = ConvertSILengthField(s_com_csr.INLNGTH);
std::vector<u8> request_copy(s_si_buffer.data(), s_si_buffer.data() + request_length);

std::unique_ptr<ISIDevice>& device = s_channel[s_com_csr.CHANNEL].device;
u32 actual_response_length = device->RunBuffer(s_si_buffer.data(), request_length);

DEBUG_LOG(SERIALINTERFACE,
"RunSIBuffer chan: %d request_length: %u expected_response_length: %u "
"actual_response_length: %u",
s_com_csr.CHANNEL, request_length, expected_response_length, actual_response_length);
const u32 request_length = ConvertSILengthField(s_com_csr.OUTLNGTH);
const u32 expected_response_length = ConvertSILengthField(s_com_csr.INLNGTH);
const std::vector<u8> request_copy(s_si_buffer.data(), s_si_buffer.data() + request_length);

const std::unique_ptr<ISIDevice>& device = s_channel[s_com_csr.CHANNEL].device;
const u32 actual_response_length = device->RunBuffer(s_si_buffer.data(), request_length);

DEBUG_LOG_FMT(SERIALINTERFACE,
"RunSIBuffer chan: {} request_length: {} expected_response_length: {} "
"actual_response_length: {}",
s_com_csr.CHANNEL, request_length, expected_response_length,
actual_response_length);
if (expected_response_length != actual_response_length)
{
std::ostringstream ss;
for (u8 b : request_copy)
{
ss << std::hex << std::setw(2) << std::setfill('0') << (int)b << ' ';
}
DEBUG_LOG(
DEBUG_LOG_FMT(
SERIALINTERFACE,
"RunSIBuffer: expected_response_length(%u) != actual_response_length(%u): request: %s",
expected_response_length, actual_response_length, ss.str().c_str());
"RunSIBuffer: expected_response_length({}) != actual_response_length({}): request: {}",
expected_response_length, actual_response_length, ss.str());
}

// TODO:

0 comments on commit b555f0f

Please sign in to comment.