1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 17:44:58 +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

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