mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +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:
parent
4237089a21
commit
d5ffb51a83
Notes:
sideshowbarker
2024-07-19 02:04:25 +09:00
Author: https://github.com/asynts Commit: https://github.com/SerenityOS/serenity/commit/d5ffb51a832 Pull-request: https://github.com/SerenityOS/serenity/pull/3680
16 changed files with 202 additions and 96 deletions
|
@ -30,6 +30,14 @@
|
|||
#include <AK/StringBuilder.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#ifdef KERNEL
|
||||
# include <Kernel/Process.h>
|
||||
# include <Kernel/Thread.h>
|
||||
#else
|
||||
# include <stdio.h>
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
namespace AK {
|
||||
|
||||
namespace {
|
||||
|
@ -540,6 +548,81 @@ void Formatter<bool>::format(TypeErasedFormatParams& params, FormatBuilder& buil
|
|||
}
|
||||
}
|
||||
|
||||
#ifndef KERNEL
|
||||
void raw_out(StringView string)
|
||||
{
|
||||
const auto retval = ::fwrite(string.characters_without_null_termination(), 1, string.length(), stdout);
|
||||
ASSERT(retval == string.length());
|
||||
}
|
||||
void vout(StringView fmtstr, TypeErasedFormatParams params, bool newline)
|
||||
{
|
||||
StringBuilder builder;
|
||||
vformat(builder, fmtstr, params);
|
||||
|
||||
if (newline && !builder.is_empty())
|
||||
builder.append('\n');
|
||||
|
||||
raw_out(builder.to_string());
|
||||
}
|
||||
|
||||
void raw_warn(StringView string)
|
||||
{
|
||||
const auto retval = ::write(STDERR_FILENO, string.characters_without_null_termination(), string.length());
|
||||
ASSERT(static_cast<size_t>(retval) == string.length());
|
||||
}
|
||||
void vwarn(StringView fmtstr, TypeErasedFormatParams params, bool newline)
|
||||
{
|
||||
StringBuilder builder;
|
||||
vformat(builder, fmtstr, params);
|
||||
|
||||
if (newline && !builder.is_empty())
|
||||
builder.append('\n');
|
||||
|
||||
raw_warn(builder.to_string());
|
||||
}
|
||||
#endif
|
||||
|
||||
void raw_dbg(StringView string)
|
||||
{
|
||||
const auto retval = dbgputstr(string.characters_without_null_termination(), string.length());
|
||||
ASSERT(static_cast<size_t>(retval) == string.length());
|
||||
}
|
||||
void vdbg(StringView fmtstr, TypeErasedFormatParams params, bool newline)
|
||||
{
|
||||
StringBuilder builder;
|
||||
|
||||
// FIXME: This logic is redundant with the stuff in LogStream.cpp.
|
||||
#if defined(__serenity__)
|
||||
# ifdef KERNEL
|
||||
if (Kernel::Processor::is_initialized() && Kernel::Thread::current()) {
|
||||
auto& thread = *Kernel::Thread::current();
|
||||
builder.appendff("\033[34;1m[{}({}:{})]\033[0m: ", thread.process().name(), thread.pid().value(), thread.tid().value());
|
||||
} else {
|
||||
builder.appendff("\033[34;1m[Kernel]\033[0m: ");
|
||||
}
|
||||
# else
|
||||
static TriState got_process_name = TriState::Unknown;
|
||||
static char process_name_buffer[256];
|
||||
|
||||
if (got_process_name == TriState::Unknown) {
|
||||
if (get_process_name(process_name_buffer, sizeof(process_name_buffer)) == 0)
|
||||
got_process_name = TriState::True;
|
||||
else
|
||||
got_process_name = TriState::False;
|
||||
}
|
||||
if (got_process_name == TriState::True)
|
||||
builder.appendff("\033[33;1m{}({})\033[0m: ", process_name_buffer, getpid());
|
||||
# endif
|
||||
#endif
|
||||
|
||||
vformat(builder, fmtstr, params);
|
||||
|
||||
if (newline && !builder.is_empty())
|
||||
builder.append('\n');
|
||||
|
||||
raw_dbg(builder.to_string());
|
||||
}
|
||||
|
||||
template struct Formatter<unsigned char, void>;
|
||||
template struct Formatter<unsigned short, void>;
|
||||
template struct Formatter<unsigned int, void>;
|
||||
|
|
43
AK/Format.h
43
AK/Format.h
|
@ -299,4 +299,47 @@ struct Formatter<bool> : StandardFormatter {
|
|||
void vformat(StringBuilder& builder, StringView fmtstr, TypeErasedFormatParams);
|
||||
void vformat(const LogStream& stream, StringView fmtstr, TypeErasedFormatParams);
|
||||
|
||||
#ifndef KERNEL
|
||||
void vout(StringView fmtstr, TypeErasedFormatParams, bool newline = false);
|
||||
void raw_out(StringView string);
|
||||
|
||||
// FIXME: Rename this function to 'out' when that name becomes avaliable.
|
||||
template<typename... Parameters>
|
||||
void new_out(StringView fmtstr, const Parameters&... parameters) { vout(fmtstr, VariadicFormatParams { parameters... }); }
|
||||
template<typename... Parameters>
|
||||
void outln(StringView fmtstr, const Parameters&... parameters) { vout(fmtstr, VariadicFormatParams { parameters... }, true); }
|
||||
|
||||
void vwarn(StringView fmtstr, TypeErasedFormatParams, bool newline = false);
|
||||
void raw_warn(StringView string);
|
||||
|
||||
// FIXME: Rename this function to 'warn' when that name becomes avaliable.
|
||||
template<typename... Parameters>
|
||||
void new_warn(StringView fmtstr, const Parameters&... parameters) { vwarn(fmtstr, VariadicFormatParams { parameters... }); }
|
||||
template<typename... Parameters>
|
||||
void warnln(StringView fmtstr, const Parameters&... parameters) { vwarn(fmtstr, VariadicFormatParams { parameters... }, true); }
|
||||
#endif
|
||||
|
||||
void vdbg(StringView fmtstr, TypeErasedFormatParams, bool newline = false);
|
||||
void raw_dbg(StringView string);
|
||||
|
||||
// FIXME: Rename this function to 'dbg' when that name becomes avaliable.
|
||||
template<typename... Parameters>
|
||||
void new_dbg(StringView fmtstr, const Parameters&... parameters) { vdbg(fmtstr, VariadicFormatParams { parameters... }); }
|
||||
template<typename... Parameters>
|
||||
void dbgln(StringView fmtstr, const Parameters&... parameters) { vdbg(fmtstr, VariadicFormatParams { parameters... }, true); }
|
||||
|
||||
} // namespace AK
|
||||
|
||||
#ifndef KERNEL
|
||||
using AK::new_out;
|
||||
using AK::outln;
|
||||
using AK::raw_out;
|
||||
|
||||
using AK::new_warn;
|
||||
using AK::raw_warn;
|
||||
using AK::warnln;
|
||||
#endif
|
||||
|
||||
using AK::dbgln;
|
||||
using AK::new_dbg;
|
||||
using AK::raw_dbg;
|
||||
|
|
|
@ -115,6 +115,8 @@ static char process_name_buffer[256];
|
|||
DebugLogStream dbg()
|
||||
{
|
||||
DebugLogStream stream;
|
||||
|
||||
// FIXME: This logic is redundant with the stuff in Format.cpp.
|
||||
#if defined(__serenity__) && !defined(KERNEL)
|
||||
if (got_process_name == TriState::Unknown) {
|
||||
if (get_process_name(process_name_buffer, sizeof(process_name_buffer)) == 0)
|
||||
|
|
|
@ -207,35 +207,13 @@ DebugLogStream klog();
|
|||
|
||||
void dump_bytes(ReadonlyBytes);
|
||||
|
||||
#ifndef KERNEL
|
||||
template<typename... Parameters>
|
||||
void outf(StringView fmtstr, const Parameters&... parameters)
|
||||
{
|
||||
vformat(out(), fmtstr, VariadicFormatParams { parameters... });
|
||||
}
|
||||
template<typename... Parameters>
|
||||
void warnf(StringView fmtstr, const Parameters&... parameters)
|
||||
{
|
||||
vformat(warn(), fmtstr, VariadicFormatParams { parameters... });
|
||||
}
|
||||
#endif
|
||||
|
||||
template<typename... Parameters>
|
||||
void dbgf(StringView fmtstr, const Parameters&... parameters)
|
||||
{
|
||||
vformat(dbg(), fmtstr, VariadicFormatParams { parameters... });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
using AK::dbg;
|
||||
using AK::dbgf;
|
||||
using AK::klog;
|
||||
using AK::LogStream;
|
||||
|
||||
#if !defined(KERNEL)
|
||||
using AK::out;
|
||||
using AK::outf;
|
||||
using AK::warn;
|
||||
using AK::warnf;
|
||||
#endif
|
||||
|
|
|
@ -199,13 +199,13 @@ void TestSuite::run(const NonnullRefPtrVector<TestCase>& tests)
|
|||
for (const auto& t : tests) {
|
||||
const auto test_type = t.is_benchmark() ? "benchmark" : "test";
|
||||
|
||||
warnf("Running {} '{}'.", test_type, t.name());
|
||||
warnln("Running {} '{}'.", test_type, t.name());
|
||||
|
||||
TestElapsedTimer timer;
|
||||
t.func()();
|
||||
const auto time = timer.elapsed_milliseconds();
|
||||
|
||||
dbgf("Completed {} '{}' in {}ms", test_type, t.name(), time);
|
||||
dbgln("Completed {} '{}' in {}ms", test_type, t.name(), time);
|
||||
|
||||
if (t.is_benchmark()) {
|
||||
m_benchtime += time;
|
||||
|
|
|
@ -258,14 +258,14 @@ void IRCClient::send_whois(const String& nick)
|
|||
void IRCClient::handle(const Message& msg)
|
||||
{
|
||||
#ifdef IRC_DEBUG
|
||||
outf("IRCClient::execute: prefix='{}', command='{}', arguments={}",
|
||||
outln("IRCClient::execute: prefix='{}', command='{}', arguments={}",
|
||||
msg.prefix,
|
||||
msg.command,
|
||||
msg.arguments.size());
|
||||
|
||||
size_t index = 0;
|
||||
for (auto& arg : msg.arguments)
|
||||
outf(" [{}]: {}", index++, arg);
|
||||
outln(" [{}]: {}", index++, arg);
|
||||
#endif
|
||||
|
||||
auto numeric = msg.command.to_uint();
|
||||
|
@ -489,7 +489,7 @@ void IRCClient::handle_privmsg_or_notice(const Message& msg, PrivmsgOrNotice typ
|
|||
bool is_ctcp = has_ctcp_payload(msg.arguments[1]);
|
||||
|
||||
#ifdef IRC_DEBUG
|
||||
outf("handle_privmsg_or_notice: type='{}'{}, sender_nick='{}', target='{}'",
|
||||
outln("handle_privmsg_or_notice: type='{}'{}, sender_nick='{}', target='{}'",
|
||||
type == PrivmsgOrNotice::Privmsg ? "privmsg" : "notice",
|
||||
is_ctcp ? " (ctcp)" : "",
|
||||
sender_nick,
|
||||
|
@ -671,11 +671,11 @@ void IRCClient::handle_rpl_welcome(const Message& msg)
|
|||
auto channel_str = m_config->read_entry("Connection", "AutoJoinChannels", "");
|
||||
if (channel_str.is_empty())
|
||||
return;
|
||||
dbgf("IRCClient: Channels to autojoin: {}", channel_str);
|
||||
dbgln("IRCClient: Channels to autojoin: {}", channel_str);
|
||||
auto channels = channel_str.split(',');
|
||||
for (auto& channel : channels) {
|
||||
join_channel(channel);
|
||||
dbgf("IRCClient: Auto joining channel: {}", channel);
|
||||
dbgln("IRCClient: Auto joining channel: {}", channel);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1153,7 +1153,7 @@ void IRCClient::send_ctcp_request(const StringView& peer, const StringView& payl
|
|||
|
||||
void IRCClient::handle_ctcp_request(const StringView& peer, const StringView& payload)
|
||||
{
|
||||
dbgf("handle_ctcp_request: {}", payload);
|
||||
dbgln("handle_ctcp_request: {}", payload);
|
||||
|
||||
if (payload == "VERSION") {
|
||||
auto version = ctcp_version_reply();
|
||||
|
@ -1187,5 +1187,5 @@ void IRCClient::handle_ctcp_request(const StringView& peer, const StringView& pa
|
|||
|
||||
void IRCClient::handle_ctcp_response(const StringView& peer, const StringView& payload)
|
||||
{
|
||||
dbgf("handle_ctcp_response({}): {}", peer, payload);
|
||||
dbgln("handle_ctcp_response({}): {}", peer, payload);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -126,7 +126,7 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
if (!server->listen({}, port)) {
|
||||
warnf("Listening on 0.0.0.0:{} failed", port);
|
||||
warnln("Listening on 0.0.0.0:{} failed", port);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
|
|
@ -74,11 +74,11 @@ int main(int argc, char** argv)
|
|||
};
|
||||
|
||||
if (!server->listen({}, port)) {
|
||||
warnf("Failed to listen on 0.0.0.0:{}", port);
|
||||
warnln("Failed to listen on 0.0.0.0:{}", port);
|
||||
return 1;
|
||||
}
|
||||
|
||||
outf("Listening on 0.0.0.0:{}", port);
|
||||
outln("Listening on 0.0.0.0:{}", port);
|
||||
|
||||
if (unveil("/res/icons", "r") < 0) {
|
||||
perror("unveil");
|
||||
|
|
|
@ -1414,11 +1414,11 @@ void Shell::notify_child_event()
|
|||
|
||||
int wstatus = 0;
|
||||
#ifdef SH_DEBUG
|
||||
dbgf("waitpid({}) = ...", job.pid());
|
||||
dbgln("waitpid({}) = ...", job.pid());
|
||||
#endif
|
||||
auto child_pid = waitpid(job.pid(), &wstatus, WNOHANG | WUNTRACED);
|
||||
#ifdef SH_DEBUG
|
||||
dbgf("... = {} - {}", child_pid, wstatus);
|
||||
dbgln("... = {} - {}", child_pid, wstatus);
|
||||
#endif
|
||||
|
||||
if (child_pid < 0) {
|
||||
|
|
|
@ -140,14 +140,14 @@ int main(int argc, char** argv)
|
|||
}
|
||||
} else if (sid != pid) {
|
||||
if (getpgid(pid) != pid) {
|
||||
dbgf("We were already in a session with sid={} (we are {}), let's do some gymnastics", sid, pid);
|
||||
dbgln("We were already in a session with sid={} (we are {}), let's do some gymnastics", sid, pid);
|
||||
if (setpgid(pid, sid) < 0) {
|
||||
auto strerr = strerror(errno);
|
||||
dbgf("couldn't setpgid: {}", strerr);
|
||||
dbgln("couldn't setpgid: {}", strerr);
|
||||
}
|
||||
if (setsid() < 0) {
|
||||
auto strerr = strerror(errno);
|
||||
dbgf("couldn't setsid: {}", strerr);
|
||||
dbgln("couldn't setsid: {}", strerr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ int main(int argc, char** argv)
|
|||
args_parser.parse(argc, argv);
|
||||
|
||||
if (create + extract + list != 1) {
|
||||
warnf("exactly one of -c, -x, and -t can be used");
|
||||
warnln("exactly one of -c, -x, and -t can be used");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ int main(int argc, char** argv)
|
|||
if (archive_file) {
|
||||
auto maybe_file = Core::File::open(archive_file, Core::IODevice::OpenMode::ReadOnly);
|
||||
if (maybe_file.is_error()) {
|
||||
warnf("Core::File::open: {}", maybe_file.error());
|
||||
warnln("Core::File::open: {}", maybe_file.error());
|
||||
return 1;
|
||||
}
|
||||
file = maybe_file.value();
|
||||
|
|
Loading…
Reference in a new issue