summaryrefslogtreecommitdiff
path: root/DevTools/UserspaceEmulator/MallocTracer.cpp
diff options
context:
space:
mode:
authorAnotherTest <ali.mpfard@gmail.com>2020-10-24 11:15:51 +0330
committerAndreas Kling <kling@serenityos.org>2020-10-25 10:13:03 +0100
commit9afe9069a9febfcae9c9d8cb9d592e45fff654ec (patch)
tree51d407ff9a66c4545a69cc07c633e68d68e45274 /DevTools/UserspaceEmulator/MallocTracer.cpp
parent201d34f6cdb9581ad0c0ba50f118ff0d2f1a2acf (diff)
downloadserenity-9afe9069a9febfcae9c9d8cb9d592e45fff654ec.zip
UserspaceEmulator: Optionally write reports to the debug log
...and take a flag '--report-to-debug' that determines this behaviour.
Diffstat (limited to 'DevTools/UserspaceEmulator/MallocTracer.cpp')
-rw-r--r--DevTools/UserspaceEmulator/MallocTracer.cpp38
1 files changed, 19 insertions, 19 deletions
diff --git a/DevTools/UserspaceEmulator/MallocTracer.cpp b/DevTools/UserspaceEmulator/MallocTracer.cpp
index bfafb777a1..48cff29c37 100644
--- a/DevTools/UserspaceEmulator/MallocTracer.cpp
+++ b/DevTools/UserspaceEmulator/MallocTracer.cpp
@@ -71,8 +71,8 @@ void MallocTracer::target_did_free(Badge<SoftCPU>, FlatPtr address)
for (auto& mallocation : m_mallocations) {
if (mallocation.address == address) {
if (mallocation.freed) {
- warnln("\n=={}== \033[31;1mDouble free()\033[0m, {:p}", getpid(), address);
- warnln("=={}== Address {} has already been passed to free()", getpid(), address);
+ reportln("\n=={}== \033[31;1mDouble free()\033[0m, {:p}", getpid(), address);
+ reportln("=={}== Address {} has already been passed to free()", getpid(), address);
Emulator::the().dump_backtrace();
} else {
mallocation.freed = true;
@@ -82,8 +82,8 @@ void MallocTracer::target_did_free(Badge<SoftCPU>, FlatPtr address)
}
}
- warnln("\n=={}== \033[31;1mInvalid free()\033[0m, {:p}", getpid(), address);
- warnln("=={}== Address {} has never been returned by malloc()", getpid(), address);
+ reportln("\n=={}== \033[31;1mInvalid free()\033[0m, {:p}", getpid(), address);
+ reportln("=={}== Address {} has never been returned by malloc()", getpid(), address);
Emulator::the().dump_backtrace();
}
@@ -119,11 +119,11 @@ void MallocTracer::audit_read(FlatPtr address, size_t size)
auto* mallocation = find_mallocation(address);
if (!mallocation) {
- warnln("\n=={}== \033[31;1mHeap buffer overflow\033[0m, invalid {}-byte read at address {:p}", getpid(), size, address);
+ reportln("\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;
- warnln("=={}== Address is {} byte(s) after block of size {}, allocated at:", getpid(), offset_into_mallocation - mallocation->size, mallocation->size);
+ reportln("=={}== 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;
@@ -132,11 +132,11 @@ void MallocTracer::audit_read(FlatPtr address, size_t size)
size_t offset_into_mallocation = address - mallocation->address;
if (mallocation->freed) {
- warnln("\n=={}== \033[31;1mUse-after-free\033[0m, invalid {}-byte read at address {:p}", getpid(), size, address);
+ reportln("\n=={}== \033[31;1mUse-after-free\033[0m, invalid {}-byte read at address {:p}", getpid(), size, address);
Emulator::the().dump_backtrace();
- warnln("=={}== Address is {} byte(s) into block of size {}, allocated at:", getpid(), offset_into_mallocation, mallocation->size);
+ reportln("=={}== Address is {} byte(s) into block of size {}, allocated at:", getpid(), offset_into_mallocation, mallocation->size);
Emulator::the().dump_backtrace(mallocation->malloc_backtrace);
- warnln("=={}== Later freed at:", getpid());
+ reportln("=={}== Later freed at:", getpid());
Emulator::the().dump_backtrace(mallocation->free_backtrace);
return;
}
@@ -152,11 +152,11 @@ void MallocTracer::audit_write(FlatPtr address, size_t size)
auto* mallocation = find_mallocation(address);
if (!mallocation) {
- warnln("\n=={}== \033[31;1mHeap buffer overflow\033[0m, invalid {}-byte write at address {:p}", getpid(), size, address);
+ reportln("\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;
- warnln("=={}== Address is {} byte(s) into block of size {}, allocated at:", getpid(), offset_into_mallocation, mallocation->size);
+ reportln("=={}== Address is {} byte(s) into block of size {}, allocated at:", getpid(), offset_into_mallocation, mallocation->size);
Emulator::the().dump_backtrace(mallocation->malloc_backtrace);
}
return;
@@ -165,11 +165,11 @@ void MallocTracer::audit_write(FlatPtr address, size_t size)
size_t offset_into_mallocation = address - mallocation->address;
if (mallocation->freed) {
- warnln("\n=={}== \033[31;1mUse-after-free\033[0m, invalid {}-byte write at address {:p}", getpid(), size, address);
+ reportln("\n=={}== \033[31;1mUse-after-free\033[0m, invalid {}-byte write at address {:p}", getpid(), size, address);
Emulator::the().dump_backtrace();
- warnln("=={}== Address is {} byte(s) into block of size {}, allocated at:", getpid(), offset_into_mallocation, mallocation->size);
+ reportln("=={}== Address is {} byte(s) into block of size {}, allocated at:", getpid(), offset_into_mallocation, mallocation->size);
Emulator::the().dump_backtrace(mallocation->malloc_backtrace);
- warnln("=={}== Later freed at:", getpid());
+ reportln("=={}== Later freed at:", getpid());
Emulator::the().dump_backtrace(mallocation->free_backtrace);
return;
}
@@ -190,7 +190,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
- warnln("mallocation {:p} is reachable from other mallocation {:p}", mallocation.address, other_mallocation.address);
+ reportln("mallocation {:p} is reachable from other mallocation {:p}", mallocation.address, other_mallocation.address);
#endif
return true;
}
@@ -215,7 +215,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
- warnln("mallocation {:p} is reachable from region {:p}-{:p}", mallocation.address, region.base(), region.end() - 1);
+ reportln("mallocation {:p} is reachable from region {:p}-{:p}", mallocation.address, region.base(), region.end() - 1);
#endif
reachable = true;
return IterationDecision::Break;
@@ -239,14 +239,14 @@ void MallocTracer::dump_leak_report()
continue;
++leaks_found;
bytes_leaked += mallocation.size;
- warnln("\n=={}== \033[31;1mLeak\033[0m, {}-byte allocation at address {:p}", getpid(), mallocation.size, mallocation.address);
+ reportln("\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)
- warnln("\n=={}== \033[32;1mNo leaks found!\033[0m", getpid());
+ reportln("\n=={}== \033[32;1mNo leaks found!\033[0m", getpid());
else
- warnln("\n=={}== \033[31;1m{} leak(s) found: {} byte(s) leaked\033[0m", getpid(), leaks_found, bytes_leaked);
+ reportln("\n=={}== \033[31;1m{} leak(s) found: {} byte(s) leaked\033[0m", getpid(), leaks_found, bytes_leaked);
}
}