Przeglądaj źródła

UserspaceEmulator: Replace printf usages with format.

This replaces almost all usages. Some have to remain because 'outf'
always appends a newline. (It inherits this behaviour from LogStream.)
asynts 4 lat temu
rodzic
commit
ba3488a6d5

+ 8 - 9
DevTools/UserspaceEmulator/Emulator.cpp

@@ -234,7 +234,7 @@ void Emulator::dump_backtrace()
 u32 Emulator::virt_syscall(u32 function, u32 arg1, u32 arg2, u32 arg3)
 u32 Emulator::virt_syscall(u32 function, u32 arg1, u32 arg2, u32 arg3)
 {
 {
 #ifdef DEBUG_SPAM
 #ifdef DEBUG_SPAM
-    dbgprintf("Syscall: %s (%x)\n", Syscall::to_string((Syscall::Function)function), function);
+    dbgf("Syscall: {} ({:x})", Syscall::to_string((Syscall::Function)function), function);
 #endif
 #endif
     switch (function) {
     switch (function) {
     case SC_chdir:
     case SC_chdir:
@@ -379,7 +379,7 @@ u32 Emulator::virt_syscall(u32 function, u32 arg1, u32 arg2, u32 arg3)
     case SC_fork:
     case SC_fork:
         return virt$fork();
         return virt$fork();
     default:
     default:
-        report("\n==%d==  \033[31;1mUnimplemented syscall: %s\033[0m, %p\n", getpid(), Syscall::to_string((Syscall::Function)function));
+        warnf("\n=={}==  \033[31;1mUnimplemented syscall: {}\033[0m, {:p}", getpid(), Syscall::to_string((Syscall::Function)function), function);
         dump_backtrace();
         dump_backtrace();
         TODO();
         TODO();
     }
     }
@@ -950,7 +950,7 @@ int Emulator::virt$ioctl(int fd, unsigned request, FlatPtr arg)
         mmu().copy_from_vm(&termios, arg, sizeof(termios));
         mmu().copy_from_vm(&termios, arg, sizeof(termios));
         return syscall(SC_ioctl, fd, request, &termios);
         return syscall(SC_ioctl, fd, request, &termios);
     }
     }
-    dbg() << "Unsupported ioctl: " << request;
+    dbgf("Unsupported ioctl: {}", request);
     dump_backtrace();
     dump_backtrace();
     TODO();
     TODO();
 }
 }
@@ -983,11 +983,10 @@ int Emulator::virt$execve(FlatPtr params_addr)
     copy_string_list(arguments, params.arguments);
     copy_string_list(arguments, params.arguments);
     copy_string_list(environment, params.environment);
     copy_string_list(environment, params.environment);
 
 
-    report("\n");
-    report("==%d==  \033[33;1mSyscall:\033[0m execve\n", getpid());
-    report("==%d==  @ %s\n", getpid(), path.characters());
+    warnf("\n=={}==  \033[33;1mSyscall:\033[0m execve", getpid());
+    warnf("=={}==  @ {}", getpid(), path);
     for (auto& argument : arguments)
     for (auto& argument : arguments)
-        report("==%d==    - %s\n", getpid(), argument.characters());
+        warnf("=={}==    - {}", getpid(), argument);
 
 
     Vector<char*> argv;
     Vector<char*> argv;
     Vector<char*> envp;
     Vector<char*> envp;
@@ -1200,7 +1199,7 @@ void Emulator::dispatch_one_pending_signal()
         auto action = default_signal_action(signum);
         auto action = default_signal_action(signum);
         if (action == DefaultSignalAction::Ignore)
         if (action == DefaultSignalAction::Ignore)
             return;
             return;
-        report("\n==%d== Got signal %d (%s), no handler registered\n", getpid(), signum, strsignal(signum));
+        warnf("\n=={}== Got signal {} ({}), no handler registered", getpid(), signum, strsignal(signum));
         m_shutdown = true;
         m_shutdown = true;
         return;
         return;
     }
     }
@@ -1210,7 +1209,7 @@ void Emulator::dispatch_one_pending_signal()
         return;
         return;
     }
     }
 
 
-    report("\n==%d== Got signal %d (%s), handler at %p\n", getpid(), signum, strsignal(signum), handler.handler);
+    warnf("\n=={}== Got signal {} ({}), handler at {:p}", getpid(), signum, strsignal(signum), handler.handler);
 
 
     auto old_esp = m_cpu.esp();
     auto old_esp = m_cpu.esp();
 
 

+ 20 - 27
DevTools/UserspaceEmulator/MallocTracer.cpp

@@ -70,9 +70,8 @@ void MallocTracer::target_did_free(Badge<SoftCPU>, FlatPtr address)
     for (auto& mallocation : m_mallocations) {
     for (auto& mallocation : m_mallocations) {
         if (mallocation.address == address) {
         if (mallocation.address == address) {
             if (mallocation.freed) {
             if (mallocation.freed) {
-                report("\n");
-                report("==%d==  \033[31;1mDouble free()\033[0m, %p\n", getpid(), address);
-                report("==%d==  Address %p has already been passed to free()\n", getpid(), address);
+                warnf("\n=={}==  \033[31;1mDouble free()\033[0m, {:p}", getpid(), address);
+                warnf("=={}==  Address {} has already been passed to free()", getpid(), address);
                 Emulator::the().dump_backtrace();
                 Emulator::the().dump_backtrace();
             } else {
             } else {
                 mallocation.freed = true;
                 mallocation.freed = true;
@@ -81,9 +80,9 @@ void MallocTracer::target_did_free(Badge<SoftCPU>, FlatPtr address)
             return;
             return;
         }
         }
     }
     }
-    report("\n");
-    report("==%d==  \033[31;1mInvalid free()\033[0m, %p\n", getpid(), address);
-    report("==%d==  Address %p has never been returned by malloc()\n", getpid(), address);
+
+    warnf("\n=={}==  \033[31;1mInvalid free()\033[0m, {:p}", getpid(), address);
+    warnf("=={}==  Address {} has never been returned by malloc()", getpid(), address);
     Emulator::the().dump_backtrace();
     Emulator::the().dump_backtrace();
 }
 }
 
 
@@ -119,12 +118,11 @@ void MallocTracer::audit_read(FlatPtr address, size_t size)
     auto* mallocation = find_mallocation(address);
     auto* mallocation = find_mallocation(address);
 
 
     if (!mallocation) {
     if (!mallocation) {
-        report("\n");
-        report("==%d==  \033[31;1mHeap buffer overflow\033[0m, invalid %zu-byte read at address %p\n", getpid(), size, address);
+        warnf("\n=={}==  \033[31;1mHeap buffer overflow\033[0m, invalid {}-byte read at address {:p}", getpid(), size, address);
         Emulator::the().dump_backtrace();
         Emulator::the().dump_backtrace();
         if ((mallocation = find_mallocation_before(address))) {
         if ((mallocation = find_mallocation_before(address))) {
             size_t offset_into_mallocation = address - mallocation->address;
             size_t offset_into_mallocation = address - mallocation->address;
-            report("==%d==  Address is %zu byte(s) after block of size %zu, allocated at:\n", getpid(), offset_into_mallocation - mallocation->size, mallocation->size);
+            warnf("=={}==  Address is {} byte(s) after block of size {}, allocated at:", getpid(), offset_into_mallocation - mallocation->size, mallocation->size);
             Emulator::the().dump_backtrace(mallocation->malloc_backtrace);
             Emulator::the().dump_backtrace(mallocation->malloc_backtrace);
         }
         }
         return;
         return;
@@ -133,12 +131,11 @@ void MallocTracer::audit_read(FlatPtr address, size_t size)
     size_t offset_into_mallocation = address - mallocation->address;
     size_t offset_into_mallocation = address - mallocation->address;
 
 
     if (mallocation->freed) {
     if (mallocation->freed) {
-        report("\n");
-        report("==%d==  \033[31;1mUse-after-free\033[0m, invalid %zu-byte read at address %p\n", getpid(), size, address);
+        warnf("\n=={}==  \033[31;1mUse-after-free\033[0m, invalid {}-byte read at address {:p}", getpid(), size, address);
         Emulator::the().dump_backtrace();
         Emulator::the().dump_backtrace();
-        report("==%d==  Address is %zu byte(s) into block of size %zu, allocated at:\n", getpid(), offset_into_mallocation, mallocation->size);
+        warnf("=={}==  Address is {} byte(s) into block of size {}, allocated at:", getpid(), offset_into_mallocation, mallocation->size);
         Emulator::the().dump_backtrace(mallocation->malloc_backtrace);
         Emulator::the().dump_backtrace(mallocation->malloc_backtrace);
-        report("==%d==  Later freed at:\n", getpid());
+        warnf("=={}==  Later freed at:", getpid());
         Emulator::the().dump_backtrace(mallocation->free_backtrace);
         Emulator::the().dump_backtrace(mallocation->free_backtrace);
         return;
         return;
     }
     }
@@ -154,12 +151,11 @@ void MallocTracer::audit_write(FlatPtr address, size_t size)
 
 
     auto* mallocation = find_mallocation(address);
     auto* mallocation = find_mallocation(address);
     if (!mallocation) {
     if (!mallocation) {
-        report("\n");
-        report("==%d==  \033[31;1mHeap buffer overflow\033[0m, invalid %zu-byte write at address %p\n", getpid(), size, address);
+        warnf("\n=={}==  \033[31;1mHeap buffer overflow\033[0m, invalid {}-byte write at address {:p}", getpid(), size, address);
         Emulator::the().dump_backtrace();
         Emulator::the().dump_backtrace();
         if ((mallocation = find_mallocation_before(address))) {
         if ((mallocation = find_mallocation_before(address))) {
             size_t offset_into_mallocation = address - mallocation->address;
             size_t offset_into_mallocation = address - mallocation->address;
-            report("==%d==  Address is %zu byte(s) after block of size %zu, allocated at:\n", getpid(), offset_into_mallocation - mallocation->size, mallocation->size);
+            warnf("=={}==  Address is {} byte(s) into block of size {}, allocated at:", getpid(), offset_into_mallocation, mallocation->size);
             Emulator::the().dump_backtrace(mallocation->malloc_backtrace);
             Emulator::the().dump_backtrace(mallocation->malloc_backtrace);
         }
         }
         return;
         return;
@@ -168,12 +164,11 @@ void MallocTracer::audit_write(FlatPtr address, size_t size)
     size_t offset_into_mallocation = address - mallocation->address;
     size_t offset_into_mallocation = address - mallocation->address;
 
 
     if (mallocation->freed) {
     if (mallocation->freed) {
-        report("\n");
-        report("==%d==  \033[31;1mUse-after-free\033[0m, invalid %zu-byte write at address %p\n", getpid(), size, address);
+        warnf("\n=={}==  \033[31;1mUse-after-free\033[0m, invalid {}-byte write at address {:p}", getpid(), size, address);
         Emulator::the().dump_backtrace();
         Emulator::the().dump_backtrace();
-        report("==%d==  Address is %zu byte(s) into block of size %zu, allocated at:\n", getpid(), offset_into_mallocation, mallocation->size);
+        warnf("=={}==  Address is {} byte(s) into block of size {}, allocated at:", getpid(), offset_into_mallocation, mallocation->size);
         Emulator::the().dump_backtrace(mallocation->malloc_backtrace);
         Emulator::the().dump_backtrace(mallocation->malloc_backtrace);
-        report("==%d==  Later freed at:\n", getpid());
+        warnf("=={}==  Later freed at:", getpid());
         Emulator::the().dump_backtrace(mallocation->free_backtrace);
         Emulator::the().dump_backtrace(mallocation->free_backtrace);
         return;
         return;
     }
     }
@@ -194,7 +189,7 @@ bool MallocTracer::is_reachable(const Mallocation& mallocation) const
             auto value = Emulator::the().mmu().read32({ 0x20, other_mallocation.address + i * sizeof(u32) });
             auto value = Emulator::the().mmu().read32({ 0x20, other_mallocation.address + i * sizeof(u32) });
             if (value.value() == mallocation.address && !value.is_uninitialized()) {
             if (value.value() == mallocation.address && !value.is_uninitialized()) {
 #ifdef REACHABLE_DEBUG
 #ifdef REACHABLE_DEBUG
-                report("mallocation %p is reachable from other mallocation %p\n", mallocation.address, other_mallocation.address);
+                warnf("mallocation {:p} is reachable from other mallocation {:p}", mallocation.address, other_mallocation.address);
 #endif
 #endif
                 return true;
                 return true;
             }
             }
@@ -219,7 +214,7 @@ bool MallocTracer::is_reachable(const Mallocation& mallocation) const
             auto value = region.read32(i * sizeof(u32));
             auto value = region.read32(i * sizeof(u32));
             if (value.value() == mallocation.address && !value.is_uninitialized()) {
             if (value.value() == mallocation.address && !value.is_uninitialized()) {
 #ifdef REACHABLE_DEBUG
 #ifdef REACHABLE_DEBUG
-                report("mallocation %p is reachable from region %p-%p\n", mallocation.address, region.base(), region.end() - 1);
+                warnf("mallocation {:p} is reachable from region {:p}-{:p}", mallocation.address, region.base(), region.end() - 1);
 #endif
 #endif
                 reachable = true;
                 reachable = true;
                 return IterationDecision::Break;
                 return IterationDecision::Break;
@@ -243,16 +238,14 @@ void MallocTracer::dump_leak_report()
             continue;
             continue;
         ++leaks_found;
         ++leaks_found;
         bytes_leaked += mallocation.size;
         bytes_leaked += mallocation.size;
-        report("\n");
-        report("==%d==  \033[31;1mLeak\033[0m, %zu-byte allocation at address %#08x\n", getpid(), mallocation.size, mallocation.address);
+        warnf("\n=={}==  \033[31;1mLeak\033[0m, {}-byte allocation at address {:p}", getpid(), mallocation.size, mallocation.address);
         Emulator::the().dump_backtrace(mallocation.malloc_backtrace);
         Emulator::the().dump_backtrace(mallocation.malloc_backtrace);
     }
     }
 
 
-    report("\n");
     if (!leaks_found)
     if (!leaks_found)
-        report("==%d==  \033[32;1mNo leaks found!\033[0m\n", getpid());
+        warnf("\n=={}==  \033[32;1mNo leaks found!\033[0m", getpid());
     else
     else
-        report("==%d==  \033[31;1m%zu leak(s) found: %zu byte(s) leaked\033[0m\n", getpid(), leaks_found, bytes_leaked);
+        warnf("\n=={}==  \033[31;1m{} leak(s) found: {} byte(s) leaked\033[0m", getpid(), leaks_found, bytes_leaked);
 }
 }
 
 
 }
 }

+ 8 - 8
DevTools/UserspaceEmulator/MmapRegion.cpp

@@ -68,7 +68,7 @@ MmapRegion::~MmapRegion()
 ValueWithShadow<u8> MmapRegion::read8(FlatPtr offset)
 ValueWithShadow<u8> MmapRegion::read8(FlatPtr offset)
 {
 {
     if (!is_readable()) {
     if (!is_readable()) {
-        warn() << "8-bit read from unreadable MmapRegion @ " << (const void*)(base() + offset);
+        warnf("8-bit read from unreadable MmapRegion @ {:p}", base() + offset);
         Emulator::the().dump_backtrace();
         Emulator::the().dump_backtrace();
         TODO();
         TODO();
     }
     }
@@ -85,7 +85,7 @@ ValueWithShadow<u8> MmapRegion::read8(FlatPtr offset)
 ValueWithShadow<u16> MmapRegion::read16(u32 offset)
 ValueWithShadow<u16> MmapRegion::read16(u32 offset)
 {
 {
     if (!is_readable()) {
     if (!is_readable()) {
-        warn() << "16-bit from unreadable MmapRegion @ " << (const void*)(base() + offset);
+        warnf("16-bit read from unreadable MmapRegion @ {:p}", base() + offset);
         Emulator::the().dump_backtrace();
         Emulator::the().dump_backtrace();
         TODO();
         TODO();
     }
     }
@@ -102,7 +102,7 @@ ValueWithShadow<u16> MmapRegion::read16(u32 offset)
 ValueWithShadow<u32> MmapRegion::read32(u32 offset)
 ValueWithShadow<u32> MmapRegion::read32(u32 offset)
 {
 {
     if (!is_readable()) {
     if (!is_readable()) {
-        warn() << "32-bit read from unreadable MmapRegion @ " << (const void*)(base() + offset);
+        warnf("32-bit read from unreadable MmapRegion @ {:p}", base() + offset);
         Emulator::the().dump_backtrace();
         Emulator::the().dump_backtrace();
         TODO();
         TODO();
     }
     }
@@ -119,7 +119,7 @@ ValueWithShadow<u32> MmapRegion::read32(u32 offset)
 ValueWithShadow<u64> MmapRegion::read64(u32 offset)
 ValueWithShadow<u64> MmapRegion::read64(u32 offset)
 {
 {
     if (!is_readable()) {
     if (!is_readable()) {
-        warn() << "64-bit read from unreadable MmapRegion @ " << (const void*)(base() + offset);
+        warnf("64-bit read from unreadable MmapRegion @ {:p}", base() + offset);
         Emulator::the().dump_backtrace();
         Emulator::the().dump_backtrace();
         TODO();
         TODO();
     }
     }
@@ -136,7 +136,7 @@ ValueWithShadow<u64> MmapRegion::read64(u32 offset)
 void MmapRegion::write8(u32 offset, ValueWithShadow<u8> value)
 void MmapRegion::write8(u32 offset, ValueWithShadow<u8> value)
 {
 {
     if (!is_writable()) {
     if (!is_writable()) {
-        warn() << "8-bit write to unreadable MmapRegion @ " << (const void*)(base() + offset);
+        warnf("8-bit write from unwritable MmapRegion @ {:p}", base() + offset);
         Emulator::the().dump_backtrace();
         Emulator::the().dump_backtrace();
         TODO();
         TODO();
     }
     }
@@ -154,7 +154,7 @@ void MmapRegion::write8(u32 offset, ValueWithShadow<u8> value)
 void MmapRegion::write16(u32 offset, ValueWithShadow<u16> value)
 void MmapRegion::write16(u32 offset, ValueWithShadow<u16> value)
 {
 {
     if (!is_writable()) {
     if (!is_writable()) {
-        warn() << "16-bit write to unreadable MmapRegion @ " << (const void*)(base() + offset);
+        warnf("16-bit write from unwritable MmapRegion @ {:p}", base() + offset);
         Emulator::the().dump_backtrace();
         Emulator::the().dump_backtrace();
         TODO();
         TODO();
     }
     }
@@ -172,7 +172,7 @@ void MmapRegion::write16(u32 offset, ValueWithShadow<u16> value)
 void MmapRegion::write32(u32 offset, ValueWithShadow<u32> value)
 void MmapRegion::write32(u32 offset, ValueWithShadow<u32> value)
 {
 {
     if (!is_writable()) {
     if (!is_writable()) {
-        warn() << "32-bit write to unreadable MmapRegion @ " << (const void*)(base() + offset);
+        warnf("32-bit write from unwritable MmapRegion @ {:p}", base() + offset);
         Emulator::the().dump_backtrace();
         Emulator::the().dump_backtrace();
         TODO();
         TODO();
     }
     }
@@ -191,7 +191,7 @@ void MmapRegion::write32(u32 offset, ValueWithShadow<u32> value)
 void MmapRegion::write64(u32 offset, ValueWithShadow<u64> value)
 void MmapRegion::write64(u32 offset, ValueWithShadow<u64> value)
 {
 {
     if (!is_writable()) {
     if (!is_writable()) {
-        warn() << "64-bit write to unreadable MmapRegion @ " << (const void*)(base() + offset);
+        warnf("64-bit write from unwritable MmapRegion @ {:p}", base() + offset);
         Emulator::the().dump_backtrace();
         Emulator::the().dump_backtrace();
         TODO();
         TODO();
     }
     }

+ 14 - 17
DevTools/UserspaceEmulator/SoftCPU.cpp

@@ -60,7 +60,7 @@ template<typename T>
 void warn_if_uninitialized(T value_with_shadow, const char* message)
 void warn_if_uninitialized(T value_with_shadow, const char* message)
 {
 {
     if (value_with_shadow.is_uninitialized()) {
     if (value_with_shadow.is_uninitialized()) {
-        dbgprintf("\033[31;1mWarning! Use of uninitialized value: %s\033[0m\n", message);
+        dbgf("\033[31;1mWarning! Use of uninitialized value: {}\033[0m\n", message);
         Emulator::the().dump_backtrace();
         Emulator::the().dump_backtrace();
     }
     }
 }
 }
@@ -68,8 +68,7 @@ void warn_if_uninitialized(T value_with_shadow, const char* message)
 void SoftCPU::warn_if_flags_tainted(const char* message) const
 void SoftCPU::warn_if_flags_tainted(const char* message) const
 {
 {
     if (m_flags_tainted) {
     if (m_flags_tainted) {
-        report("\n");
-        report("==%d==  \033[31;1mConditional depends on uninitialized data\033[0m (%s)\n", getpid(), message);
+        warnf("\n=={}==  \033[31;1mConditional depends on uninitialized data\033[0m ({})\n", getpid(), message);
         Emulator::the().dump_backtrace();
         Emulator::the().dump_backtrace();
     }
     }
 }
 }
@@ -97,12 +96,10 @@ SoftCPU::SoftCPU(Emulator& emulator)
 
 
 void SoftCPU::dump() const
 void SoftCPU::dump() const
 {
 {
-    printf("eax=%08x ebx=%08x ecx=%08x edx=%08x ", eax().value(), ebx().value(), ecx().value(), edx().value());
-    printf("ebp=%08x esp=%08x esi=%08x edi=%08x ", ebp().value(), esp().value(), esi().value(), edi().value());
-    printf("o=%u s=%u z=%u a=%u p=%u c=%u\n", of(), sf(), zf(), af(), pf(), cf());
-    printf("#ax=%08x #bx=%08x #cx=%08x #dx=%08x ", eax().shadow(), ebx().shadow(), ecx().shadow(), edx().shadow());
-    printf("#bp=%08x #sp=%08x #si=%08x #di=%08x ", ebp().shadow(), esp().shadow(), esi().shadow(), edi().shadow());
-    printf("#f=%u\n", m_flags_tainted);
+    outf(" eax={:08x}  ebx={:08x}  ecx={:08x}  edx={:08x}  ebp={:08x}  esp={:08x}  esi={:08x}  edi={:08x} o={:d} s={:d} z={:d} a={:d} p={:d} c={:d}",
+        eax(), ebx(), ecx(), edx(), ebp(), esp(), esi(), edi(), of(), sf(), zf(), af(), pf(), cf());
+    outf("#eax={:08x} #ebx={:08x} #ecx={:08x} #edx={:08x} #ebp={:08x} #esp={:08x} #esi={:08x} #edi={:08x} #f={}",
+        eax().shadow(), ebx().shadow(), ecx().shadow(), edx().shadow(), m_flags_tainted);
     fflush(stdout);
     fflush(stdout);
 }
 }
 
 
@@ -133,7 +130,7 @@ ValueWithShadow<u8> SoftCPU::read_memory8(X86::LogicalAddress address)
     ASSERT(address.selector() == 0x18 || address.selector() == 0x20 || address.selector() == 0x28);
     ASSERT(address.selector() == 0x18 || address.selector() == 0x20 || address.selector() == 0x28);
     auto value = m_emulator.mmu().read8(address);
     auto value = m_emulator.mmu().read8(address);
 #ifdef MEMORY_DEBUG
 #ifdef MEMORY_DEBUG
-    printf("\033[36;1mread_memory8: @%08x:%08x -> %02x (%02x)\033[0m\n", address.selector(), address.offset(), value.value(), value.shadow());
+    outf("\033[36;1mread_memory8: @{:04x}:{:08x} -> {:02x} ({:02x})\033[0m", address.selector(), address.offset(), value, value.shadow());
 #endif
 #endif
     return value;
     return value;
 }
 }
@@ -143,7 +140,7 @@ ValueWithShadow<u16> SoftCPU::read_memory16(X86::LogicalAddress address)
     ASSERT(address.selector() == 0x18 || address.selector() == 0x20 || address.selector() == 0x28);
     ASSERT(address.selector() == 0x18 || address.selector() == 0x20 || address.selector() == 0x28);
     auto value = m_emulator.mmu().read16(address);
     auto value = m_emulator.mmu().read16(address);
 #ifdef MEMORY_DEBUG
 #ifdef MEMORY_DEBUG
-    printf("\033[36;1mread_memory16: @%04x:%08x -> %04x (%04x)\033[0m\n", address.selector(), address.offset(), value.value(), value.shadow());
+    outf("\033[36;1mread_memory16: @{:04x}:{:08x} -> {:04x} ({:04x})\033[0m", address.selector(), address.offset(), value, value.shadow());
 #endif
 #endif
     return value;
     return value;
 }
 }
@@ -153,7 +150,7 @@ ValueWithShadow<u32> SoftCPU::read_memory32(X86::LogicalAddress address)
     ASSERT(address.selector() == 0x18 || address.selector() == 0x20 || address.selector() == 0x28);
     ASSERT(address.selector() == 0x18 || address.selector() == 0x20 || address.selector() == 0x28);
     auto value = m_emulator.mmu().read32(address);
     auto value = m_emulator.mmu().read32(address);
 #ifdef MEMORY_DEBUG
 #ifdef MEMORY_DEBUG
-    printf("\033[36;1mread_memory32: @%04x:%08x -> %08x (%08x)\033[0m\n", address.selector(), address.offset(), value.value(), value.shadow());
+    outf("\033[36;1mread_memory32: @{:04x}:{:08x} -> {:08x} ({:08x})\033[0m", address.selector(), address.offset(), value, value.shadow());
 #endif
 #endif
     return value;
     return value;
 }
 }
@@ -163,7 +160,7 @@ ValueWithShadow<u64> SoftCPU::read_memory64(X86::LogicalAddress address)
     ASSERT(address.selector() == 0x18 || address.selector() == 0x20 || address.selector() == 0x28);
     ASSERT(address.selector() == 0x18 || address.selector() == 0x20 || address.selector() == 0x28);
     auto value = m_emulator.mmu().read64(address);
     auto value = m_emulator.mmu().read64(address);
 #ifdef MEMORY_DEBUG
 #ifdef MEMORY_DEBUG
-    printf("\033[36;1mread_memory64: @%04x:%08x -> %016llx (%016llx)\033[0m\n", address.selector(), address.offset(), value.value(), value.shadow());
+    outf("\033[36;1mread_memory64: @{:04x}:{:08x} -> {:016x} ({:016x})\033[0m", address.selector(), address.offset(), value, value.shadow());
 #endif
 #endif
     return value;
     return value;
 }
 }
@@ -172,7 +169,7 @@ void SoftCPU::write_memory8(X86::LogicalAddress address, ValueWithShadow<u8> val
 {
 {
     ASSERT(address.selector() == 0x20 || address.selector() == 0x28);
     ASSERT(address.selector() == 0x20 || address.selector() == 0x28);
 #ifdef MEMORY_DEBUG
 #ifdef MEMORY_DEBUG
-    printf("\033[35;1mwrite_memory8: @%04x:%08x <- %02x (%02x)\033[0m\n", address.selector(), address.offset(), value.value(), value.shadow());
+    outf("\033[36;1mwrite_memory8: @{:04x}:{:08x} <- {:02x} ({:02x})\033[0m", address.selector(), address.offset(), value, value.shadow());
 #endif
 #endif
     m_emulator.mmu().write8(address, value);
     m_emulator.mmu().write8(address, value);
 }
 }
@@ -181,7 +178,7 @@ void SoftCPU::write_memory16(X86::LogicalAddress address, ValueWithShadow<u16> v
 {
 {
     ASSERT(address.selector() == 0x20 || address.selector() == 0x28);
     ASSERT(address.selector() == 0x20 || address.selector() == 0x28);
 #ifdef MEMORY_DEBUG
 #ifdef MEMORY_DEBUG
-    printf("\033[35;1mwrite_memory16: @%04x:%08x <- %04x (%04x)\033[0m\n", address.selector(), address.offset(), value.value(), value.shadow());
+    outf("\033[36;1mwrite_memory16: @{:04x}:{:08x} <- {:04x} ({:04x})\033[0m", address.selector(), address.offset(), value, value.shadow());
 #endif
 #endif
     m_emulator.mmu().write16(address, value);
     m_emulator.mmu().write16(address, value);
 }
 }
@@ -190,7 +187,7 @@ void SoftCPU::write_memory32(X86::LogicalAddress address, ValueWithShadow<u32> v
 {
 {
     ASSERT(address.selector() == 0x20 || address.selector() == 0x28);
     ASSERT(address.selector() == 0x20 || address.selector() == 0x28);
 #ifdef MEMORY_DEBUG
 #ifdef MEMORY_DEBUG
-    printf("\033[35;1mwrite_memory32: @%04x:%08x <- %08x (%08x)\033[0m\n", address.selector(), address.offset(), value.value(), value.shadow());
+    outf("\033[36;1mwrite_memory32: @{:04x}:{:08x} <- {:08x} ({:08x})\033[0m", address.selector(), address.offset(), value, value.shadow());
 #endif
 #endif
     m_emulator.mmu().write32(address, value);
     m_emulator.mmu().write32(address, value);
 }
 }
@@ -199,7 +196,7 @@ void SoftCPU::write_memory64(X86::LogicalAddress address, ValueWithShadow<u64> v
 {
 {
     ASSERT(address.selector() == 0x20 || address.selector() == 0x28);
     ASSERT(address.selector() == 0x20 || address.selector() == 0x28);
 #ifdef MEMORY_DEBUG
 #ifdef MEMORY_DEBUG
-    printf("\033[35;1mwrite_memory64: @%04x:%08x <- %016llx (%016llx)\033[0m\n", address.selector(), address.offset(), value.value(), value.shadow());
+    outf("\033[36;1mwrite_memory64: @{:04x}:{:08x} <- {:016x} ({:016x})\033[0m", address.selector(), address.offset(), value, value.shadow());
 #endif
 #endif
     m_emulator.mmu().write64(address, value);
     m_emulator.mmu().write64(address, value);
 }
 }

+ 8 - 8
DevTools/UserspaceEmulator/SoftMMU.cpp

@@ -68,7 +68,7 @@ ValueWithShadow<u8> SoftMMU::read8(X86::LogicalAddress address)
 {
 {
     auto* region = find_region(address);
     auto* region = find_region(address);
     if (!region) {
     if (!region) {
-        warn() << "SoftMMU::read8: No region for @" << (const void*)address.offset();
+        warnf("SoftMMU::read8: No region for @ {:p}", address.offset());
         TODO();
         TODO();
     }
     }
 
 
@@ -79,7 +79,7 @@ ValueWithShadow<u16> SoftMMU::read16(X86::LogicalAddress address)
 {
 {
     auto* region = find_region(address);
     auto* region = find_region(address);
     if (!region) {
     if (!region) {
-        warn() << "SoftMMU::read16: No region for @" << (const void*)address.offset();
+        warnf("SoftMMU::read16: No region for @ {:p}", address.offset());
         TODO();
         TODO();
     }
     }
 
 
@@ -90,7 +90,7 @@ ValueWithShadow<u32> SoftMMU::read32(X86::LogicalAddress address)
 {
 {
     auto* region = find_region(address);
     auto* region = find_region(address);
     if (!region) {
     if (!region) {
-        warn() << "SoftMMU::read32: No region for @" << (const void*)address.offset();
+        warnf("SoftMMU::read32: No region for @ {:p}", address.offset());
         TODO();
         TODO();
     }
     }
 
 
@@ -101,7 +101,7 @@ ValueWithShadow<u64> SoftMMU::read64(X86::LogicalAddress address)
 {
 {
     auto* region = find_region(address);
     auto* region = find_region(address);
     if (!region) {
     if (!region) {
-        warn() << "SoftMMU::read64: No region for @" << (const void*)address.offset();
+        warnf("SoftMMU::read64: No region for @ {:p}", address.offset());
         TODO();
         TODO();
     }
     }
 
 
@@ -112,7 +112,7 @@ void SoftMMU::write8(X86::LogicalAddress address, ValueWithShadow<u8> value)
 {
 {
     auto* region = find_region(address);
     auto* region = find_region(address);
     if (!region) {
     if (!region) {
-        warn() << "SoftMMU::write8: No region for @" << (const void*)address.offset();
+        warnf("SoftMMU::write8: No region for @ {:p}", address.offset());
         TODO();
         TODO();
     }
     }
 
 
@@ -123,7 +123,7 @@ void SoftMMU::write16(X86::LogicalAddress address, ValueWithShadow<u16> value)
 {
 {
     auto* region = find_region(address);
     auto* region = find_region(address);
     if (!region) {
     if (!region) {
-        warn() << "SoftMMU::write16: No region for @" << (const void*)address.offset();
+        warnf("SoftMMU::write16: No region for @ {:p}", address.offset());
         TODO();
         TODO();
     }
     }
 
 
@@ -134,7 +134,7 @@ void SoftMMU::write32(X86::LogicalAddress address, ValueWithShadow<u32> value)
 {
 {
     auto* region = find_region(address);
     auto* region = find_region(address);
     if (!region) {
     if (!region) {
-        warn() << "SoftMMU::write32: No region for @" << (const void*)address.offset();
+        warnf("SoftMMU::write32: No region for @ {:p}", address.offset());
         TODO();
         TODO();
     }
     }
 
 
@@ -145,7 +145,7 @@ void SoftMMU::write64(X86::LogicalAddress address, ValueWithShadow<u64> value)
 {
 {
     auto* region = find_region(address);
     auto* region = find_region(address);
     if (!region) {
     if (!region) {
-        warn() << "SoftMMU::write64: No region for @" << (const void*)address.offset();
+        warnf("SoftMMU::write64: No region for @ {:p}", address.offset());
         TODO();
         TODO();
     }
     }
 
 

+ 9 - 0
DevTools/UserspaceEmulator/ValueWithShadow.h

@@ -24,6 +24,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
  */
 
 
+#include <AK/Format.h>
 #include <AK/Platform.h>
 #include <AK/Platform.h>
 
 
 #pragma once
 #pragma once
@@ -160,3 +161,11 @@ inline void ValueAndShadowReference<T>::operator=(const ValueWithShadow<T>& othe
 }
 }
 
 
 }
 }
+
+template<typename T>
+struct AK::Formatter<UserspaceEmulator::ValueWithShadow<T>> : AK::Formatter<T> {
+    void format(StringBuilder& builder, UserspaceEmulator::ValueWithShadow<T> value, FormatterContext& context)
+    {
+        return Formatter<T>::format(builder, value.value(), context);
+    }
+};