mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 13:17:36 +00:00
UserspaceEmulator: Use a report() function instead of dbgprintf()
Ultimately we'll want to make it a bit easier to add more reporting. This at least makes it easier to redirect the logging.
This commit is contained in:
parent
628b3badfb
commit
c7e4c0734b
4 changed files with 40 additions and 30 deletions
|
@ -225,10 +225,10 @@ void Emulator::dump_backtrace(const Vector<FlatPtr>& backtrace)
|
||||||
u32 offset = 0;
|
u32 offset = 0;
|
||||||
String symbol = m_elf->symbolicate(address, &offset);
|
String symbol = m_elf->symbolicate(address, &offset);
|
||||||
auto source_position = m_debug_info->get_source_position(address);
|
auto source_position = m_debug_info->get_source_position(address);
|
||||||
dbgprintf("==%d== %#08x %s +%#x", getpid(), address, symbol.characters(), offset);
|
report("==%d== %#08x %s +%#x", getpid(), address, symbol.characters(), offset);
|
||||||
if (source_position.has_value())
|
if (source_position.has_value())
|
||||||
dbgprintf(" (\033[34;1m%s\033[0m:%zu)", LexicalPath(source_position.value().file_path).basename().characters(), source_position.value().line_number);
|
report(" (\033[34;1m%s\033[0m:%zu)", LexicalPath(source_position.value().file_path).basename().characters(), source_position.value().line_number);
|
||||||
dbgprintf("\n");
|
report("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -844,7 +844,7 @@ u32 Emulator::virt$read(int fd, FlatPtr buffer, ssize_t size)
|
||||||
|
|
||||||
void Emulator::virt$exit(int status)
|
void Emulator::virt$exit(int status)
|
||||||
{
|
{
|
||||||
dbgprintf("\n==%d== \033[33;1mSyscall: exit(%d)\033[0m, shutting down!\n", getpid(), status);
|
report("\n==%d== \033[33;1mSyscall: exit(%d)\033[0m, shutting down!\n", getpid(), status);
|
||||||
m_exit_status = status;
|
m_exit_status = status;
|
||||||
m_shutdown = true;
|
m_shutdown = true;
|
||||||
}
|
}
|
||||||
|
@ -911,10 +911,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);
|
||||||
|
|
||||||
dbgprintf("\n");
|
report("\n");
|
||||||
dbgprintf("==%d== \033[33;1mSyscall:\033[0m execve\n", getpid());
|
report("==%d== \033[33;1mSyscall:\033[0m execve\n", getpid());
|
||||||
for (auto& argument : arguments)
|
for (auto& argument : arguments)
|
||||||
dbgprintf("==%d== - %s\n", getpid(), argument.characters());
|
report("==%d== - %s\n", getpid(), argument.characters());
|
||||||
|
|
||||||
Vector<char*> argv;
|
Vector<char*> argv;
|
||||||
Vector<char*> envp;
|
Vector<char*> envp;
|
||||||
|
@ -981,4 +981,12 @@ int Emulator::virt$gethostname(FlatPtr buffer, ssize_t buffer_size)
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void report(const char* format, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, format);
|
||||||
|
vfprintf(stderr, format, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,4 +140,6 @@ private:
|
||||||
FlatPtr m_free_symbol_end { 0 };
|
FlatPtr m_free_symbol_end { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void report(const char*, ...);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,9 +66,9 @@ 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) {
|
||||||
dbgprintf("\n");
|
report("\n");
|
||||||
dbgprintf("==%d== \033[31;1mDouble free()\033[0m, %p\n", getpid(), address);
|
report("==%d== \033[31;1mDouble free()\033[0m, %p\n", getpid(), address);
|
||||||
dbgprintf("==%d== Address %p has already been passed to free()\n", getpid(), address);
|
report("==%d== Address %p has already been passed to free()\n", getpid(), address);
|
||||||
Emulator::the().dump_backtrace();
|
Emulator::the().dump_backtrace();
|
||||||
} else {
|
} else {
|
||||||
mallocation.freed = true;
|
mallocation.freed = true;
|
||||||
|
@ -77,9 +77,9 @@ void MallocTracer::target_did_free(Badge<SoftCPU>, FlatPtr address)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dbgprintf("\n");
|
report("\n");
|
||||||
dbgprintf("==%d== \033[31;1mInvalid free()\033[0m, %p\n", getpid(), address);
|
report("==%d== \033[31;1mInvalid free()\033[0m, %p\n", getpid(), address);
|
||||||
dbgprintf("==%d== Address %p has never been returned by malloc()\n", getpid(), address);
|
report("==%d== Address %p has never been returned by malloc()\n", getpid(), address);
|
||||||
Emulator::the().dump_backtrace();
|
Emulator::the().dump_backtrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,12 +107,12 @@ 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) {
|
||||||
dbgprintf("\n");
|
report("\n");
|
||||||
dbgprintf("==%d== \033[31;1mUse-after-free\033[0m, invalid %zu-byte read at address %p\n", getpid(), size, address);
|
report("==%d== \033[31;1mUse-after-free\033[0m, invalid %zu-byte read at address %p\n", getpid(), size, address);
|
||||||
Emulator::the().dump_backtrace();
|
Emulator::the().dump_backtrace();
|
||||||
dbgprintf("==%d== Address is %zu bytes into block of size %zu, allocated at:\n", getpid(), offset_into_mallocation, mallocation->size);
|
report("==%d== Address is %zu bytes into block of size %zu, allocated at:\n", getpid(), offset_into_mallocation, mallocation->size);
|
||||||
Emulator::the().dump_backtrace(mallocation->malloc_backtrace);
|
Emulator::the().dump_backtrace(mallocation->malloc_backtrace);
|
||||||
dbgprintf("==%d== Later freed at:\n", getpid(), offset_into_mallocation, mallocation->size);
|
report("==%d== Later freed at:\n", getpid(), offset_into_mallocation, mallocation->size);
|
||||||
Emulator::the().dump_backtrace(mallocation->free_backtrace);
|
Emulator::the().dump_backtrace(mallocation->free_backtrace);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -133,12 +133,12 @@ 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) {
|
||||||
dbgprintf("\n");
|
report("\n");
|
||||||
dbgprintf("==%d== \033[31;1mUse-after-free\033[0m, invalid %zu-byte write at address %p\n", getpid(), size, address);
|
report("==%d== \033[31;1mUse-after-free\033[0m, invalid %zu-byte write at address %p\n", getpid(), size, address);
|
||||||
Emulator::the().dump_backtrace();
|
Emulator::the().dump_backtrace();
|
||||||
dbgprintf("==%d== Address is %zu bytes into block of size %zu, allocated at:\n", getpid(), offset_into_mallocation, mallocation->size);
|
report("==%d== Address is %zu bytes into block of size %zu, allocated at:\n", getpid(), offset_into_mallocation, mallocation->size);
|
||||||
Emulator::the().dump_backtrace(mallocation->malloc_backtrace);
|
Emulator::the().dump_backtrace(mallocation->malloc_backtrace);
|
||||||
dbgprintf("==%d== Later freed at:\n", getpid(), offset_into_mallocation, mallocation->size);
|
report("==%d== Later freed at:\n", getpid(), offset_into_mallocation, mallocation->size);
|
||||||
Emulator::the().dump_backtrace(mallocation->free_backtrace);
|
Emulator::the().dump_backtrace(mallocation->free_backtrace);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -159,7 +159,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
|
||||||
dbgprintf("mallocation %p is reachable from other mallocation %p\n", mallocation.address, other_mallocation.address);
|
report("mallocation %p is reachable from other mallocation %p\n", mallocation.address, other_mallocation.address);
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -184,7 +184,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
|
||||||
dbgprintf("mallocation %p is reachable from region %p-%p\n", mallocation.address, region.base(), region.end() - 1);
|
report("mallocation %p is reachable from region %p-%p\n", mallocation.address, region.base(), region.end() - 1);
|
||||||
#endif
|
#endif
|
||||||
reachable = true;
|
reachable = true;
|
||||||
return IterationDecision::Break;
|
return IterationDecision::Break;
|
||||||
|
@ -208,16 +208,16 @@ void MallocTracer::dump_leak_report()
|
||||||
continue;
|
continue;
|
||||||
++leaks_found;
|
++leaks_found;
|
||||||
bytes_leaked += mallocation.size;
|
bytes_leaked += mallocation.size;
|
||||||
dbgprintf("\n");
|
report("\n");
|
||||||
dbgprintf("==%d== \033[31;1mLeak\033[0m, %zu-byte allocation at address %#08x\n", getpid(), mallocation.size, mallocation.address);
|
report("==%d== \033[31;1mLeak\033[0m, %zu-byte allocation at address %#08x\n", getpid(), mallocation.size, mallocation.address);
|
||||||
Emulator::the().dump_backtrace(mallocation.malloc_backtrace);
|
Emulator::the().dump_backtrace(mallocation.malloc_backtrace);
|
||||||
}
|
}
|
||||||
|
|
||||||
dbgprintf("\n");
|
report("\n");
|
||||||
if (!leaks_found)
|
if (!leaks_found)
|
||||||
dbgprintf("==%d== \033[32;1mNo leaks found!\033[0m\n", getpid());
|
report("==%d== \033[32;1mNo leaks found!\033[0m\n", getpid());
|
||||||
else
|
else
|
||||||
dbgprintf("==%d== \033[31;1m%zu leak(s) found: %zu byte(s) leaked\033[0m\n", getpid(), leaks_found, bytes_leaked);
|
report("==%d== \033[31;1m%zu leak(s) found: %zu byte(s) leaked\033[0m\n", getpid(), leaks_found, bytes_leaked);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,8 +61,8 @@ 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) {
|
||||||
dbgprintf("\n");
|
report("\n");
|
||||||
dbgprintf("==%d== \033[31;1mConditional depends on uninitialized data\033[0m (%s)\n", getpid(), message);
|
report("==%d== \033[31;1mConditional depends on uninitialized data\033[0m (%s)\n", getpid(), message);
|
||||||
Emulator::the().dump_backtrace();
|
Emulator::the().dump_backtrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue