1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 13:05:07 +00:00

AK: Don't add newline for outf/dbgf/warnf.

In the future all (normal) output should be written by any of the
following functions:

    out    (currently called new_out)
    outln
    dbg    (currently called new_dbg)
    dbgln
    warn   (currently called new_warn)
    warnln

However, there are still a ton of uses of the old out/warn/dbg in the
code base so the new functions are called new_out/new_warn/new_dbg. I am
going to rename them as soon as all the other usages are gone (this
might take a while.)

I also added raw_out/raw_dbg/raw_warn which don't do any escaping,
this should be useful if no formatting is required and if the input
contains tons of curly braces. (I am not entirely sure if this function
will stay, but I am adding it for now.)
This commit is contained in:
asynts 2020-10-04 15:35:43 +02:00 committed by Andreas Kling
parent 4237089a21
commit d5ffb51a83
16 changed files with 202 additions and 96 deletions

View file

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

View file

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

View file

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

View file

@ -60,7 +60,7 @@ template<typename T>
void warn_if_uninitialized(T value_with_shadow, const char* message)
{
if (value_with_shadow.is_uninitialized()) {
dbgf("\033[31;1mWarning! Use of uninitialized value: {}\033[0m\n", message);
dbgln("\033[31;1mWarning! Use of uninitialized value: {}\033[0m\n", message);
Emulator::the().dump_backtrace();
}
}
@ -68,7 +68,7 @@ void warn_if_uninitialized(T value_with_shadow, const char* message)
void SoftCPU::warn_if_flags_tainted(const char* message) const
{
if (m_flags_tainted) {
warnf("\n=={}== \033[31;1mConditional depends on uninitialized data\033[0m ({})\n", getpid(), message);
warnln("\n=={}== \033[31;1mConditional depends on uninitialized data\033[0m ({})\n", getpid(), message);
Emulator::the().dump_backtrace();
}
}
@ -96,9 +96,9 @@ SoftCPU::SoftCPU(Emulator& emulator)
void SoftCPU::dump() const
{
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}",
outln(" 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={}",
outln("#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);
}
@ -130,7 +130,7 @@ ValueWithShadow<u8> SoftCPU::read_memory8(X86::LogicalAddress address)
ASSERT(address.selector() == 0x18 || address.selector() == 0x20 || address.selector() == 0x28);
auto value = m_emulator.mmu().read8(address);
#ifdef MEMORY_DEBUG
outf("\033[36;1mread_memory8: @{:04x}:{:08x} -> {:02x} ({:02x})\033[0m", address.selector(), address.offset(), value, value.shadow());
outln("\033[36;1mread_memory8: @{:04x}:{:08x} -> {:02x} ({:02x})\033[0m", address.selector(), address.offset(), value, value.shadow());
#endif
return value;
}
@ -140,7 +140,7 @@ ValueWithShadow<u16> SoftCPU::read_memory16(X86::LogicalAddress address)
ASSERT(address.selector() == 0x18 || address.selector() == 0x20 || address.selector() == 0x28);
auto value = m_emulator.mmu().read16(address);
#ifdef MEMORY_DEBUG
outf("\033[36;1mread_memory16: @{:04x}:{:08x} -> {:04x} ({:04x})\033[0m", address.selector(), address.offset(), value, value.shadow());
outln("\033[36;1mread_memory16: @{:04x}:{:08x} -> {:04x} ({:04x})\033[0m", address.selector(), address.offset(), value, value.shadow());
#endif
return value;
}
@ -150,7 +150,7 @@ ValueWithShadow<u32> SoftCPU::read_memory32(X86::LogicalAddress address)
ASSERT(address.selector() == 0x18 || address.selector() == 0x20 || address.selector() == 0x28);
auto value = m_emulator.mmu().read32(address);
#ifdef MEMORY_DEBUG
outf("\033[36;1mread_memory32: @{:04x}:{:08x} -> {:08x} ({:08x})\033[0m", address.selector(), address.offset(), value, value.shadow());
outln("\033[36;1mread_memory32: @{:04x}:{:08x} -> {:08x} ({:08x})\033[0m", address.selector(), address.offset(), value, value.shadow());
#endif
return value;
}
@ -160,7 +160,7 @@ ValueWithShadow<u64> SoftCPU::read_memory64(X86::LogicalAddress address)
ASSERT(address.selector() == 0x18 || address.selector() == 0x20 || address.selector() == 0x28);
auto value = m_emulator.mmu().read64(address);
#ifdef MEMORY_DEBUG
outf("\033[36;1mread_memory64: @{:04x}:{:08x} -> {:016x} ({:016x})\033[0m", address.selector(), address.offset(), value, value.shadow());
outln("\033[36;1mread_memory64: @{:04x}:{:08x} -> {:016x} ({:016x})\033[0m", address.selector(), address.offset(), value, value.shadow());
#endif
return value;
}
@ -169,7 +169,7 @@ void SoftCPU::write_memory8(X86::LogicalAddress address, ValueWithShadow<u8> val
{
ASSERT(address.selector() == 0x20 || address.selector() == 0x28);
#ifdef MEMORY_DEBUG
outf("\033[36;1mwrite_memory8: @{:04x}:{:08x} <- {:02x} ({:02x})\033[0m", address.selector(), address.offset(), value, value.shadow());
outln("\033[36;1mwrite_memory8: @{:04x}:{:08x} <- {:02x} ({:02x})\033[0m", address.selector(), address.offset(), value, value.shadow());
#endif
m_emulator.mmu().write8(address, value);
}
@ -178,7 +178,7 @@ void SoftCPU::write_memory16(X86::LogicalAddress address, ValueWithShadow<u16> v
{
ASSERT(address.selector() == 0x20 || address.selector() == 0x28);
#ifdef MEMORY_DEBUG
outf("\033[36;1mwrite_memory16: @{:04x}:{:08x} <- {:04x} ({:04x})\033[0m", address.selector(), address.offset(), value, value.shadow());
outln("\033[36;1mwrite_memory16: @{:04x}:{:08x} <- {:04x} ({:04x})\033[0m", address.selector(), address.offset(), value, value.shadow());
#endif
m_emulator.mmu().write16(address, value);
}
@ -187,7 +187,7 @@ void SoftCPU::write_memory32(X86::LogicalAddress address, ValueWithShadow<u32> v
{
ASSERT(address.selector() == 0x20 || address.selector() == 0x28);
#ifdef MEMORY_DEBUG
outf("\033[36;1mwrite_memory32: @{:04x}:{:08x} <- {:08x} ({:08x})\033[0m", address.selector(), address.offset(), value, value.shadow());
outln("\033[36;1mwrite_memory32: @{:04x}:{:08x} <- {:08x} ({:08x})\033[0m", address.selector(), address.offset(), value, value.shadow());
#endif
m_emulator.mmu().write32(address, value);
}
@ -196,7 +196,7 @@ void SoftCPU::write_memory64(X86::LogicalAddress address, ValueWithShadow<u64> v
{
ASSERT(address.selector() == 0x20 || address.selector() == 0x28);
#ifdef MEMORY_DEBUG
outf("\033[36;1mwrite_memory64: @{:04x}:{:08x} <- {:016x} ({:016x})\033[0m", address.selector(), address.offset(), value, value.shadow());
outln("\033[36;1mwrite_memory64: @{:04x}:{:08x} <- {:016x} ({:016x})\033[0m", address.selector(), address.offset(), value, value.shadow());
#endif
m_emulator.mmu().write64(address, value);
}

View file

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