VMManager: Make LogLayout log level configurable as a parameter

This commit is contained in:
Yuri Kunde Schlesner 2015-07-17 21:55:48 -03:00
parent 6d8607e4e9
commit b464ef0e15
4 changed files with 22 additions and 13 deletions

View File

@ -91,17 +91,16 @@ void LogMessage(Class log_class, Level log_level,
} // namespace Log } // namespace Log
#define LOG_GENERIC(log_class, log_level, ...) \ #define LOG_GENERIC(log_class, log_level, ...) \
::Log::LogMessage(::Log::Class::log_class, ::Log::Level::log_level, \ ::Log::LogMessage(log_class, log_level, __FILE__, __LINE__, __func__, __VA_ARGS__)
__FILE__, __LINE__, __func__, __VA_ARGS__)
#ifdef _DEBUG #ifdef _DEBUG
#define LOG_TRACE( log_class, ...) LOG_GENERIC(log_class, Trace, __VA_ARGS__) #define LOG_TRACE( log_class, ...) LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Trace, __VA_ARGS__)
#else #else
#define LOG_TRACE( log_class, ...) (void(0)) #define LOG_TRACE( log_class, ...) (void(0))
#endif #endif
#define LOG_DEBUG( log_class, ...) LOG_GENERIC(log_class, Debug, __VA_ARGS__) #define LOG_DEBUG( log_class, ...) LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Debug, __VA_ARGS__)
#define LOG_INFO( log_class, ...) LOG_GENERIC(log_class, Info, __VA_ARGS__) #define LOG_INFO( log_class, ...) LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Info, __VA_ARGS__)
#define LOG_WARNING( log_class, ...) LOG_GENERIC(log_class, Warning, __VA_ARGS__) #define LOG_WARNING( log_class, ...) LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Warning, __VA_ARGS__)
#define LOG_ERROR( log_class, ...) LOG_GENERIC(log_class, Error, __VA_ARGS__) #define LOG_ERROR( log_class, ...) LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Error, __VA_ARGS__)
#define LOG_CRITICAL(log_class, ...) LOG_GENERIC(log_class, Critical, __VA_ARGS__) #define LOG_CRITICAL(log_class, ...) LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Critical, __VA_ARGS__)

View File

@ -113,7 +113,7 @@ void Process::Run(s32 main_thread_priority, u32 stack_size) {
MapSegment(codeset->rodata, VMAPermission::Read, MemoryState::Code); MapSegment(codeset->rodata, VMAPermission::Read, MemoryState::Code);
MapSegment(codeset->data, VMAPermission::ReadWrite, MemoryState::Private); MapSegment(codeset->data, VMAPermission::ReadWrite, MemoryState::Private);
address_space->LogLayout(); address_space->LogLayout(Log::Level::Debug);
Kernel::SetupMainThread(codeset->entrypoint, main_thread_priority); Kernel::SetupMainThread(codeset->entrypoint, main_thread_priority);
} }

View File

@ -11,6 +11,15 @@
namespace Kernel { namespace Kernel {
static const char* GetMemoryStateName(MemoryState state) {
static const char* names[] = {
"Free", "Reserved", "IO", "Static", "Code", "Private", "Shared", "Continuous", "Aliased",
"Alias", "AliasCode", "Locked",
};
return names[(int)state];
}
bool VirtualMemoryArea::CanBeMergedWith(const VirtualMemoryArea& next) const { bool VirtualMemoryArea::CanBeMergedWith(const VirtualMemoryArea& next) const {
ASSERT(base + size == next.base); ASSERT(base + size == next.base);
if (permissions != next.permissions || if (permissions != next.permissions ||
@ -134,13 +143,14 @@ void VMManager::Reprotect(VMAHandle vma_handle, VMAPermission new_perms) {
MergeAdjacent(iter); MergeAdjacent(iter);
} }
void VMManager::LogLayout() const { void VMManager::LogLayout(Log::Level log_level) const {
for (const auto& p : vma_map) { for (const auto& p : vma_map) {
const VirtualMemoryArea& vma = p.second; const VirtualMemoryArea& vma = p.second;
LOG_DEBUG(Kernel, "%08X - %08X size: %8X %c%c%c", vma.base, vma.base + vma.size, vma.size, LOG_GENERIC(Log::Class::Kernel, log_level, "%08X - %08X size: %8X %c%c%c %s",
vma.base, vma.base + vma.size, vma.size,
(u8)vma.permissions & (u8)VMAPermission::Read ? 'R' : '-', (u8)vma.permissions & (u8)VMAPermission::Read ? 'R' : '-',
(u8)vma.permissions & (u8)VMAPermission::Write ? 'W' : '-', (u8)vma.permissions & (u8)VMAPermission::Write ? 'W' : '-',
(u8)vma.permissions & (u8)VMAPermission::Execute ? 'X' : '-'); (u8)vma.permissions & (u8)VMAPermission::Execute ? 'X' : '-', GetMemoryStateName(vma.meminfo_state));
} }
} }

View File

@ -170,7 +170,7 @@ public:
void Reprotect(VMAHandle vma, VMAPermission new_perms); void Reprotect(VMAHandle vma, VMAPermission new_perms);
/// Dumps the address space layout to the log, for debugging /// Dumps the address space layout to the log, for debugging
void LogLayout() const; void LogLayout(Log::Level log_level) const;
private: private:
using VMAIter = decltype(vma_map)::iterator; using VMAIter = decltype(vma_map)::iterator;