Skip to content

Commit

Permalink
deps: add spdlog submodule
Browse files Browse the repository at this point in the history
TODO: fix segfault when using spdlog::get without logger initialization
  • Loading branch information
scribam committed May 9, 2024
1 parent 9bf60dd commit 90b8e6a
Show file tree
Hide file tree
Showing 67 changed files with 390 additions and 1,447 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@
[submodule "core/deps/rcheevos"]
path = core/deps/rcheevos
url = https://github.com/RetroAchievements/rcheevos.git
[submodule "core/deps/spdlog"]
path = core/deps/spdlog
url = https://github.com/gabime/spdlog.git
28 changes: 12 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,18 @@ endif()
cmrc_add_resource_library(flycast-resources ALIAS flycast::res NAMESPACE flycast)
target_link_libraries(${PROJECT_NAME} PRIVATE flycast::res)

if(NINTENDO_SWITCH)
# Trick to have fileno available
add_compile_options(-U__STRICT_ANSI__)
endif()
option(SPDLOG_NO_THREAD_ID "prevent spdlog from querying the thread id on each log call if thread id is not needed" ON)
option(SPDLOG_DISABLE_DEFAULT_LOGGER "Disable default logger creation" ON)
add_subdirectory(core/deps/spdlog)
target_link_libraries(${PROJECT_NAME} PRIVATE spdlog::spdlog)

target_compile_definitions(${PROJECT_NAME} PRIVATE SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_TRACE)
target_sources(${PROJECT_NAME} PRIVATE core/log/Log.h core/log/Log.cpp core/log/libretro_sink.h)

if(LIBRETRO)
target_include_directories(${PROJECT_NAME} PRIVATE core/deps/libretro-common/include)
target_sources(${PROJECT_NAME} PRIVATE
Expand Down Expand Up @@ -771,8 +783,6 @@ if(LIBRETRO)
shell/libretro/libretro_core_options_intl.h
shell/libretro/libretro_core_options.h
shell/libretro/libretro.cpp
shell/libretro/LogManager.cpp
shell/libretro/LogManager.h
shell/libretro/option.cpp
shell/libretro/oslib.cpp
shell/libretro/vmu_xhair.cpp)
Expand Down Expand Up @@ -1083,20 +1093,6 @@ if(NOT LIBRETRO)
core/linux-dist/x11_keyboard.h)
endif()

target_sources(${PROJECT_NAME} PRIVATE
core/log/BitSet.h
core/log/Log.h
core/log/StringUtil.h)
if(NOT LIBRETRO)
target_sources(${PROJECT_NAME} PRIVATE
core/log/ConsoleListener.h
core/log/ConsoleListenerDroid.cpp
core/log/ConsoleListenerNix.cpp
core/log/ConsoleListenerWin.cpp
core/log/LogManager.cpp
core/log/LogManager.h)
endif()

target_sources(${PROJECT_NAME} PRIVATE
core/network/alienfnt_modem.cpp
core/network/alienfnt_modem.h
Expand Down
2 changes: 1 addition & 1 deletion core/deps/ggpo/lib/ggpo/network/udp_proto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ UdpProtocol::OnInput(UdpMsg *msg, int len)
UdpProtocol::Event evt(UdpProtocol::Event::Input);
evt.u.input.input = _last_received_input;

if (LogTypes::LDEBUG <= MAX_LOGLEVEL)
if (SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_DEBUG)
_last_received_input.desc(desc, ARRAY_SIZE(desc));

_state.running.last_input_packet_recv_time = GGPOPlatform::GetCurrentTimeMS();
Expand Down
1 change: 1 addition & 0 deletions core/deps/spdlog
Submodule spdlog added at 27cb4c
2 changes: 1 addition & 1 deletion core/hw/aica/dsp_x64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class X64DSPAssembler : public Xbyak::CodeGenerator
void Compile(DSPState *DSP)
{
this->DSP = DSP;
DEBUG_LOG(AICA_ARM, "DSPAssembler::DSPCompile recompiling for x86/64 at %p", this->getCode());
DEBUG_LOG(AICA_ARM, "DSPAssembler::DSPCompile recompiling for x86/64 at %p", fmt::ptr(this->getCode()));

push(rbx);
push(rbp);
Expand Down
2 changes: 1 addition & 1 deletion core/hw/aica/dsp_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class X86DSPAssembler : public Xbyak::CodeGenerator
void Compile(DSPState *DSP)
{
this->DSP = DSP;
DEBUG_LOG(AICA_ARM, "X86DSPAssembler::Compile recompiling for x86 at %p", this->getCode());
DEBUG_LOG(AICA_ARM, "X86DSPAssembler::Compile recompiling for x86 at %p", fmt::ptr(this->getCode()));

push(esi);
push(edi);
Expand Down
2 changes: 1 addition & 1 deletion core/hw/arm7/arm7_rec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ void compile()

arm7backend_compile(block_ops, cycles);

arm_printf("arm7rec_compile done: %p,%p", rv, icPtr);
arm_printf("arm7rec_compile done: %p,%p", fmt::ptr(rv), fmt::ptr(icPtr));
}

void flush()
Expand Down
2 changes: 1 addition & 1 deletion core/hw/arm7/arm7_rec.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class ArmRegAlloc
}
}
verify(bestReg != (Arm7Reg)-1);
DEBUG_LOG(AICA_ARM, "Flushing dirty register r%d", bestReg);
DEBUG_LOG(AICA_ARM, "Flushing dirty register r%d", fmt::underlying(bestReg));
}
flushReg(allocs[bestReg]);
}
Expand Down
4 changes: 2 additions & 2 deletions core/hw/gdrom/gdromv3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ static void gd_process_spi_cmd()
die("SPI_CD_PLAY: unknown parameter");

DEBUG_LOG(GDROM, "CDDA StartAddr=%d EndAddr=%d repeats=%d status=%d CurrAddr=%d",cdda.StartAddr.FAD,
cdda.EndAddr.FAD, cdda.repeats, cdda.status, cdda.CurrAddr.FAD);
cdda.EndAddr.FAD, cdda.repeats, fmt::underlying(cdda.status), cdda.CurrAddr.FAD);

gd_set_state(gds_procpacketdone);
}
Expand Down Expand Up @@ -942,7 +942,7 @@ static void gd_process_spi_cmd()
die("SPI_CD_SEEK : not known parameter..");

DEBUG_LOG(GDROM, "CDDA StartAddr=%d EndAddr=%d repeats=%d status=%d CurrAddr=%d",cdda.StartAddr.FAD,
cdda.EndAddr.FAD, cdda.repeats, cdda.status, cdda.CurrAddr.FAD);
cdda.EndAddr.FAD, cdda.repeats, fmt::underlying(cdda.status), cdda.CurrAddr.FAD);

gd_set_state(gds_procpacketdone);
}
Expand Down
2 changes: 1 addition & 1 deletion core/hw/maple/maple_cfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ static void createDreamcastDevices()
break;

default:
WARN_LOG(MAPLE, "Invalid device type %d for port %d", (MapleDeviceType)config::MapleMainDevices[bus], bus);
WARN_LOG(MAPLE, "Invalid device type %d for port %d", fmt::underlying((MapleDeviceType)config::MapleMainDevices[bus]), bus);
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/hw/maple/maple_devs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1989,7 +1989,7 @@ maple_device* maple_Create(MapleDeviceType type)
break;

default:
ERROR_LOG(MAPLE, "Invalid device type %d", type);
ERROR_LOG(MAPLE, "Invalid device type %d", fmt::underlying(type));
die("Invalid maple device type");
break;
}
Expand Down
10 changes: 5 additions & 5 deletions core/hw/mem/addrspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ void initMappings()
}
else {
NOTICE_LOG(VMEM, "Info: nvmem is enabled");
INFO_LOG(VMEM, "Info: p_sh4rcb: %p ram_base: %p", p_sh4rcb, ram_base);
INFO_LOG(VMEM, "Info: p_sh4rcb: %p ram_base: %p", fmt::ptr(p_sh4rcb), fmt::ptr(ram_base));
// Map the different parts of the memory file into the new memory range we got.
const virtmem::Mapping mem_mappings[] = {
{0x00000000, 0x00800000, 0, 0, false}, // Area 0 -> unused
Expand Down Expand Up @@ -461,10 +461,10 @@ void initMappings()
vram.zero();
mem_b.zero();
NOTICE_LOG(VMEM, "BASE %p RAM(%d MB) %p VRAM64(%d MB) %p ARAM(%d MB) %p",
ram_base,
(u32)(RAM_SIZE / 1_MB), &mem_b[0],
(u32)(VRAM_SIZE / 1_MB), &vram[0],
(u32)(ARAM_SIZE / 1_MB), &aica::aica_ram[0]);
fmt::ptr(ram_base),
(u32)(RAM_SIZE / 1_MB), fmt::ptr(&mem_b[0]),
(u32)(VRAM_SIZE / 1_MB), fmt::ptr(&vram[0]),
(u32)(ARAM_SIZE / 1_MB), fmt::ptr(&aica::aica_ram[0]));
}

void release()
Expand Down
4 changes: 2 additions & 2 deletions core/hw/naomi/systemsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ class Touchscreen : public SerialPort::Pipe
sendPosition(1);
}
else
WARN_LOG(NAOMI, "Unknown command %.9s", &recvBuffer[0]);
WARN_LOG(NAOMI, "Unknown command %.9s", std::string(recvBuffer.begin(), recvBuffer.end()));
recvBuffer.clear();
}
else
Expand Down Expand Up @@ -2631,7 +2631,7 @@ void SystemSpCart::process()
{
u32 addr = readNetMem<u32>(0x208);
//u32 len = readNetMem<u32>(0x20c);
INFO_LOG(NAOMI, "process: modifyMyIPaddr(%s, %08x)", &netmem[addr & (sizeof(netmem) - 1)], readNetMem<u32>(0x210));
INFO_LOG(NAOMI, "process: modifyMyIPaddr(%s, %08x)", (const char *)&netmem[addr & (sizeof(netmem) - 1)], readNetMem<u32>(0x210));
writeNetMem(2, NET_OK);
}
break;
Expand Down
4 changes: 2 additions & 2 deletions core/hw/sh4/dyna/blockmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void bm_AddBlock(RuntimeBlockInfo* blk)
all_temp_blocks.insert(block);
auto iter = blkmap.find((void*)blk->code);
if (iter != blkmap.end()) {
ERROR_LOG(DYNAREC, "DUP: %08X %p %08X %p", iter->second->addr, iter->second->code, block->addr, block->code);
ERROR_LOG(DYNAREC, "DUP: %08X %p %08X %p", iter->second->addr, fmt::ptr(iter->second->code), block->addr, fmt::ptr(block->code));
die("Duplicated block");
}
blkmap[(void*)block->code] = block;
Expand Down Expand Up @@ -547,7 +547,7 @@ void print_blocks()
f=fopen(get_writable_data_path("blkmap.lst").c_str(),"w");
print_stats=false;

INFO_LOG(DYNAREC, "Writing blocks to %p", f);
INFO_LOG(DYNAREC, "Writing blocks to %p", fmt::ptr(f));
}

for (const auto& [_, blk] : blkmap)
Expand Down
2 changes: 1 addition & 1 deletion core/hw/sh4/dyna/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ void* DYNACALL rdv_LinkBlock(u8* code,u32 dpc)
}
else
{
INFO_LOG(DYNAREC, "null RBI: from %08X to %08X -- unlinked stale block -- code %p next %p", rbi->vaddr, next_pc, code, rv);
INFO_LOG(DYNAREC, "null RBI: from %08X to %08X -- unlinked stale block -- code %p next %p", rbi->vaddr, next_pc, fmt::ptr(code), fmt::ptr(rv));
}

return (void*)rv;
Expand Down
2 changes: 1 addition & 1 deletion core/hw/sh4/dyna/ssa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ bool SSAOptimizer::ExecuteConstOp(shil_opcode* op)
break;

default:
ERROR_LOG(DYNAREC, "unhandled constant op %d", op->op);
ERROR_LOG(DYNAREC, "unhandled constant op %d", fmt::underlying(op->op));
die("unhandled constant op");
break;
}
Expand Down
2 changes: 1 addition & 1 deletion core/hw/sh4/modules/serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void SCIFSerialPort::updateBaudRate()
frameSize = 1 + 8 - SCIF_SCSMR2.CHR + SCIF_SCSMR2.PE + 1 + SCIF_SCSMR2.STOP;
int bauds = SH4_MAIN_CLOCK / 4 / (SCIF_SCBRR2 + 1) / 32 / (1 << (SCIF_SCSMR2.CKS * 2));
cyclesPerBit = SH4_MAIN_CLOCK / bauds;
INFO_LOG(SH4, "SCIF: Frame size %d cycles/bit %d (%d bauds) pipe %p", frameSize, cyclesPerBit, bauds, pipe);
INFO_LOG(SH4, "SCIF: Frame size %d cycles/bit %d (%d bauds) pipe %p", frameSize, cyclesPerBit, bauds, fmt::ptr(pipe));
sh4_sched_request(schedId, frameSize * cyclesPerBit);
}

Expand Down
2 changes: 1 addition & 1 deletion core/hw/sh4/sh4_core_regs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ static u32* Sh4_int_GetRegisterPtr(Sh4RegType reg)
return &Sh4cntx.temp_reg;

default:
ERROR_LOG(SH4, "Unknown register ID %d", reg);
ERROR_LOG(SH4, "Unknown register ID %d", fmt::underlying(reg));
die("Invalid reg");
return 0;
break;
Expand Down
2 changes: 1 addition & 1 deletion core/imgread/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ void Disc::ReadSectors(u32 FAD, u32 count, u8* dst, u32 fmt, LoadProgress *progr
}
else
{
WARN_LOG(GDROM, "ERROR: UNABLE TO CONVERT SECTOR. THIS IS FATAL. Format: %d Sector format: %d", fmt, secfmt);
WARN_LOG(GDROM, "ERROR: UNABLE TO CONVERT SECTOR. THIS IS FATAL. Format: %d Sector format: %d", fmt, fmt::underlying(secfmt));
//verify(false);
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/input/gamepad_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ bool GamepadDevice::handleButtonInput(int port, DreamcastKey key, bool pressed)
return false;
}
}
DEBUG_LOG(INPUT, "%d: BUTTON %s %d. kcode=%x", port, pressed ? "down" : "up", key, port >= 0 ? kcode[port] : 0);
DEBUG_LOG(INPUT, "%d: BUTTON %s %d. kcode=%x", port, pressed ? "down" : "up", fmt::underlying(key), port >= 0 ? kcode[port] : 0);

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion core/input/mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ static const char *getKeyName(DreamcastKey key)
for (u32 i = 0; i < std::size(axis_list); i++)
if (key == axis_list[i].id)
return axis_list[i].option.c_str();
ERROR_LOG(INPUT, "Invalid key %x", key);
ERROR_LOG(INPUT, "Invalid key %x", fmt::underlying(key));

return nullptr;
}
Expand Down
1 change: 0 additions & 1 deletion core/linux-dist/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "types.h"

#if defined(__unix__)
#include "log/LogManager.h"
#include "emulator.h"
#include "ui/mainui.h"
#include "oslib/directory.h"
Expand Down
4 changes: 2 additions & 2 deletions core/linux/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ void fault_handler(int sn, siginfo_t * si, void *segfault_ctx)
return;
}

ERROR_LOG(COMMON, "SIGSEGV @ %p invalid access to %p", (void *)ctx.pc, si->si_addr);
ERROR_LOG(COMMON, "SIGSEGV @ %p invalid access to %p", fmt::ptr((void *)ctx.pc), fmt::ptr(si->si_addr));
#endif

#ifdef __SWITCH__
MemoryInfo meminfo;
u32 pageinfo;
svcQueryMemory(&meminfo, &pageinfo, (u64)&__start__);
ERROR_LOG(COMMON, ".text base: %p -> offset: %lx", (void*)meminfo.addr, ctx.pc - meminfo.addr);
ERROR_LOG(COMMON, ".text base: %p -> offset: %lx", fmt::ptr((void*)meminfo.addr), ctx.pc - meminfo.addr);
#else
if (next_segv_handler.sa_sigaction != nullptr)
next_segv_handler.sa_sigaction(sn, si, segfault_ctx);
Expand Down
2 changes: 1 addition & 1 deletion core/linux/posix_vmem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ bool prepare_jit_block(void *code_area, size_t size, void **code_area_rw, ptrdif
*code_area_rw = ptr_rw;
*rx_offset = (char*)ptr_rx - (char*)ptr_rw;
close(fd);
INFO_LOG(DYNAREC, "Info: Using NO_RWX mode, rx ptr: %p, rw ptr: %p, offset: %ld", ptr_rx, ptr_rw, (long)*rx_offset);
INFO_LOG(DYNAREC, "Info: Using NO_RWX mode, rx ptr: %p, rw ptr: %p, offset: %ld", fmt::ptr(ptr_rx), fmt::ptr(ptr_rw), (long)*rx_offset);

return (ptr_rw != MAP_FAILED);
}
Expand Down
2 changes: 1 addition & 1 deletion core/linux/unwind_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ size_t UnwindInfo::end(u32 offset, ptrdiff_t rwRxOffset)
registeredFrames.push_back(unwindInfoDest);
#endif
}
DEBUG_LOG(DYNAREC, "RegisterFrame %p sz %d tables: %d", startAddr, (u32)(endAddr - startAddr), (u32)registeredFrames.size());
DEBUG_LOG(DYNAREC, "RegisterFrame %p sz %d tables: %d", fmt::ptr(startAddr), (u32)(endAddr - startAddr), (u32)registeredFrames.size());

return (unwindInfoDest + unwindInfo.size()) - endAddr;
}
Expand Down
Loading

0 comments on commit 90b8e6a

Please sign in to comment.