2
1
Fork 0
mirror of https://github.com/yuzu-emu/yuzu.git synced 2024-07-04 23:31:19 +01:00

Merge pull request #184 from mailwl/lm

Service/lm: add support to multiline logs
This commit is contained in:
bunnei 2018-02-13 10:29:33 -05:00 committed by GitHub
commit 87c3c93464
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <sstream>
#include <string> #include <string>
#include "common/logging/log.h" #include "common/logging/log.h"
#include "core/hle/ipc_helpers.h" #include "core/hle/ipc_helpers.h"
@ -28,19 +29,28 @@ private:
IsHead = 1, IsHead = 1,
IsTail = 2, IsTail = 2,
}; };
enum Severity : u32_le {
Trace,
Info,
Warning,
Error,
Critical,
};
u64_le pid; u64_le pid;
u64_le threadContext; u64_le threadContext;
union { union {
BitField<0, 16, Flags> flags; BitField<0, 16, Flags> flags;
BitField<16, 8, u32_le> severity; BitField<16, 8, Severity> severity;
BitField<24, 8, u32_le> verbosity; BitField<24, 8, u32_le> verbosity;
}; };
u32_le payload_size; u32_le payload_size;
/// Returns true if this is part of a single log message bool IsHeadLog() const {
bool IsSingleMessage() const { return flags & Flags::IsHead;
return (flags & Flags::IsHead) && (flags & Flags::IsTail); }
bool IsTailLog() const {
return flags & Flags::IsTail;
} }
}; };
static_assert(sizeof(MessageHeader) == 0x18, "MessageHeader is incorrect size"); static_assert(sizeof(MessageHeader) == 0x18, "MessageHeader is incorrect size");
@ -57,7 +67,7 @@ private:
}; };
/** /**
* LM::Initialize service function * LM::Log service function
* Inputs: * Inputs:
* 0: 0x00000000 * 0: 0x00000000
* Outputs: * Outputs:
@ -75,9 +85,9 @@ private:
Memory::ReadBlock(addr, &header, sizeof(MessageHeader)); Memory::ReadBlock(addr, &header, sizeof(MessageHeader));
addr += sizeof(MessageHeader); addr += sizeof(MessageHeader);
if (!header.IsSingleMessage()) { if (header.IsHeadLog()) {
LOG_WARNING(Service_LM, "Multi message logs are unimplemeneted"); log_stream.str("");
return; log_stream.clear();
} }
// Parse out log metadata // Parse out log metadata
@ -85,7 +95,7 @@ private:
std::string message, filename, function; std::string message, filename, function;
while (addr < end_addr) { while (addr < end_addr) {
const Field field{static_cast<Field>(Memory::Read8(addr++))}; const Field field{static_cast<Field>(Memory::Read8(addr++))};
size_t length{Memory::Read8(addr++)}; const size_t length{Memory::Read8(addr++)};
if (static_cast<Field>(Memory::Read8(addr)) == Field::Skip) { if (static_cast<Field>(Memory::Read8(addr)) == Field::Skip) {
++addr; ++addr;
@ -110,28 +120,47 @@ private:
} }
// Empty log - nothing to do here // Empty log - nothing to do here
if (message.empty()) { if (log_stream.str().empty() && message.empty()) {
return; return;
} }
// Format a nicely printable string out of the log metadata // Format a nicely printable string out of the log metadata
std::string output; if (!filename.empty()) {
if (filename.size()) { log_stream << filename << ':';
output += filename + ':';
} }
if (function.size()) { if (!function.empty()) {
output += function + ':'; log_stream << function << ':';
} }
if (line) { if (line) {
output += std::to_string(line) + ':'; log_stream << std::to_string(line) << ':';
} }
if (output.length() > 0 && output.back() == ':') { if (log_stream.str().length() > 0 && log_stream.str().back() == ':') {
output += ' '; log_stream << ' ';
} }
output += message; log_stream << message;
LOG_INFO(Debug_Emulated, "%s", output.c_str()); if (header.IsTailLog()) {
switch (header.severity) {
case MessageHeader::Severity::Trace:
LOG_TRACE(Debug_Emulated, "%s", log_stream.str().c_str());
break;
case MessageHeader::Severity::Info:
LOG_INFO(Debug_Emulated, "%s", log_stream.str().c_str());
break;
case MessageHeader::Severity::Warning:
LOG_WARNING(Debug_Emulated, "%s", log_stream.str().c_str());
break;
case MessageHeader::Severity::Error:
LOG_ERROR(Debug_Emulated, "%s", log_stream.str().c_str());
break;
case MessageHeader::Severity::Critical:
LOG_CRITICAL(Debug_Emulated, "%s", log_stream.str().c_str());
break;
}
}
} }
std::ostringstream log_stream;
}; };
void InstallInterfaces(SM::ServiceManager& service_manager) { void InstallInterfaces(SM::ServiceManager& service_manager) {