From ef37bc8ad238d9799938f7d0b848e597e4238de2 Mon Sep 17 00:00:00 2001 From: PatrickvL Date: Fri, 11 Nov 2016 15:17:29 +0100 Subject: [PATCH] Argument logging now works Experimenting with rendering specific types, it's starting to look good. --- src/Common/Logging.cpp | 42 ------------------ src/Common/Logging.h | 30 ++----------- src/CxbxKrnl/EmuKrnl.cpp | 95 ++++++++++++++++++++++++++++++++++++---- 3 files changed, 90 insertions(+), 77 deletions(-) diff --git a/src/Common/Logging.cpp b/src/Common/Logging.cpp index f75d2305a..c732649c3 100644 --- a/src/Common/Logging.cpp +++ b/src/Common/Logging.cpp @@ -32,52 +32,10 @@ // * // ****************************************************************** -#include - #include "Logging.h" -//#include "EmuNtDll.h" // For thread_local, see : http://en.cppreference.com/w/cpp/language/storage_duration thread_local const DWORD _CurrentThreadId = GetCurrentThreadId(); // TODO : Use Boost.Format http://www.boost.org/doc/libs/1_53_0/libs/format/index.html thread_local std::string _logPrefix; - -std::ostream& operator<<(std::ostream& os, const LARGE_INTEGER& value) -{ - return os << value.QuadPart; -} - -//std::ostream& operator<<(std::ostream& os, const LPCSTR& value); - -std::ostream& operator<<(std::ostream& os, const PULONG& value) -{ - os << "0x" << (void*)value; - if (value) - os << " (->0x" << (void*)*value << ")"; - - return os; -} - -// std::ostream& operator<<(std::ostream& os, const PMM_STATISTICS& value); // ->Length -// std::ostream& operator<<(std::ostream& os, const POBJECT_ATTRIBUTES& value); // ->ObjectName->Buffer -// std::ostream& operator<<(std::ostream& os, const PIO_STATUS_BLOCK& value); // ->u1.Pointer, ->Information -// std::ostream& operator<<(std::ostream& os, const PSTRING& value); // (value != 0) ? value->Buffer : "" - -std::ostream& operator<<(std::ostream& os, const PLARGE_INTEGER& value) -{ - os << "0x" << (void*)value; - if (value) - os << " (->0x" << value->QuadPart << ")"; - - return os; -} - -// std::ostream& operator<<(std::ostream& os, const PUNICODE_STRING& value); -// std::ostream& operator<<(std::ostream& os, const PVOID*& value); // * value, *value -// std::ostream& operator<<(std::ostream& os, const PXDEVICE_PREALLOC_TYPE& value); -// std::ostream& operator<<(std::ostream& os, const PXINPUT_CAPABILITIES& value); -// std::ostream& operator<<(std::ostream& os, const PXINPUT_STATE& value); -// std::ostream& operator<<(std::ostream& os, const PXPP_DEVICE_TYPE& value); -// std::ostream& operator<<(std::ostream& os, const PXTHREAD_NOTIFICATION& value); // -> pfnNotifyRoutine -// std::ostream& operator<<(std::ostream& os, const UCHAR& value); diff --git a/src/Common/Logging.h b/src/Common/Logging.h index cb0476d27..29676046b 100644 --- a/src/Common/Logging.h +++ b/src/Common/Logging.h @@ -74,21 +74,20 @@ extern thread_local std::string _logPrefix; tmp << __FILENAME__ << " (0x" << std::hex << std::uppercase << _CurrentThreadId << "): "; \ _logPrefix = tmp.str(); \ }; \ - bool had_args = false; \ std::stringstream msg; \ msg << _logPrefix << __func__ << "("; // LOG_FUNC_ARG_OUT writes output via all available ostream << operator overloads, adding detail where possible #define LOG_FUNC_ARG(arg) \ - had_args = true; \ - msg << "\n " << std::setw(18) << std::left << std::setfill(' ') << #arg << " : " << arg; + msg << "\n " << std::setw(26) << std::left << std::setfill(' ') << #arg << " : " << arg; // LOG_FUNC_ARG_OUT prevents expansion of types, by only rendering as a pointer #define LOG_FUNC_ARG_OUT(arg) \ - msg << "\n " << std::setw(18) << std::left << std::setfill(' ') << #arg << " : 0x" << (void*)arg; + msg << "\n " << std::setw(26) << std::left << std::setfill(' ') << #arg << " : 0x" << (void*)arg; +// LOG_FUNC_END closes off function and optional argument logging #define LOG_FUNC_END \ - if (had_args) msg << "\n"; \ + msg.seekg(-1, std::ios::end); if (msg.get() != '(') msg << '\n'; \ msg << ");\n"; \ std::cout << msg.str(); \ } } while (0) @@ -104,25 +103,4 @@ extern thread_local std::string _logPrefix; // Log function with one out argument #define LOG_FUNC_ONE_ARG_OUT(arg) LOG_FUNC_BEGIN LOG_FUNC_ARG_OUT(arg) LOG_FUNC_END -//#include "EmuNtDll.h" - -// TODO : -//std::ostream& operator<<(std::ostream&, const LARGE_INTEGER&); // .QuadPart -//std::ostream& operator<<(std::ostream&, const LPCSTR&); -std::ostream& operator<<(std::ostream&, const PLARGE_INTEGER&); -// std::ostream& operator<<(std::ostream&, const PMM_STATISTICS&); // ->Length -// std::ostream& operator<<(std::ostream&, const POBJECT_ATTRIBUTES&); // ->ObjectName->Buffer -// std::ostream& operator<<(std::ostream&, const PIO_STATUS_BLOCK&); // ->u1.Pointer, ->Information -// std::ostream& operator<<(std::ostream&, const PSTRING&); // (value != 0) ? value->Buffer : "" -std::ostream& operator<<(std::ostream&, const PULONG&); -// std::ostream& operator<<(std::ostream&, const PUNICODE_STRING&); -// std::ostream& operator<<(std::ostream&, const PVOID*&); // * value, *value -// std::ostream& operator<<(std::ostream&, const PXDEVICE_PREALLOC_TYPE&); -// std::ostream& operator<<(std::ostream&, const PXINPUT_CAPABILITIES&); -// std::ostream& operator<<(std::ostream&, const PXINPUT_STATE&); -// std::ostream& operator<<(std::ostream&, const PXPP_DEVICE_TYPE&); -// std::ostream& operator<<(std::ostream&, const PXTHREAD_NOTIFICATION&); // -> pfnNotifyRoutine -// std::ostream& operator<<(std::ostream&, const UCHAR&); - - #endif _LOGGING_H \ No newline at end of file diff --git a/src/CxbxKrnl/EmuKrnl.cpp b/src/CxbxKrnl/EmuKrnl.cpp index faef70135..b36aae4c6 100644 --- a/src/CxbxKrnl/EmuKrnl.cpp +++ b/src/CxbxKrnl/EmuKrnl.cpp @@ -45,6 +45,8 @@ namespace xboxkrnl #include #include +#include "Logging.h" + // prevent name collisions namespace NtDll { @@ -52,7 +54,6 @@ namespace NtDll }; #include "CxbxKrnl.h" -#include "Logging.h" #include "Emu.h" #include "EmuFS.h" #include "EmuFile.h" @@ -64,6 +65,71 @@ namespace NtDll #include #pragma warning(default:4005) +std::ostream& operator<<(std::ostream& os, const xboxkrnl::PSTRING& value); // forward + +std::ostream& operator<<(std::ostream& os, const xboxkrnl::LARGE_INTEGER& value) +{ + return os << value.QuadPart; +} + +//std::ostream& operator<<(std::ostream& os, const xboxkrnl::LPCSTR& value); + +std::ostream& operator<<(std::ostream& os, const PULONG& value) +{ + os << "0x" << (void*)value; + if (value) + os << " (*value: " << (void*)*value << ")"; + + return os; +} + +std::ostream& operator<<(std::ostream& os, const xboxkrnl::PMM_STATISTICS& value) +{ + os << "0x" << (void*)value; + if (value) + os << " (->Length: " << value->Length << ")"; + + return os; +} + +std::ostream& operator<<(std::ostream& os, const xboxkrnl::POBJECT_ATTRIBUTES& value) +{ + os << "0x" << (void*)value; + if (value) + os << " (->ObjectName: " << value->ObjectName << ")"; + + return os; +} + +// std::ostream& operator<<(std::ostream& os, const xboxkrnl::PIO_STATUS_BLOCK& value); // ->u1.Pointer, ->Information + +std::ostream& operator<<(std::ostream& os, const xboxkrnl::PSTRING& value) +{ + os << "0x" << (void*)value; + if (value) + os << " (->Buffer: \"" << value->Buffer << "\")"; + + return os; +} + +std::ostream& operator<<(std::ostream& os, const xboxkrnl::PLARGE_INTEGER& value) +{ + os << "0x" << (void*)value; + if (value) + os << " (->QuadPart: " << value->QuadPart << ")"; + + return os; +} + +// std::ostream& operator<<(std::ostream& os, const xboxkrnl::PUNICODE_STRING& value); +// std::ostream& operator<<(std::ostream& os, const PVOID*& value); // * value, *value +// std::ostream& operator<<(std::ostream& os, const xboxkrnl::PXDEVICE_PREALLOC_TYPE& value); +// std::ostream& operator<<(std::ostream& os, const xboxkrnl::PXINPUT_CAPABILITIES& value); +// std::ostream& operator<<(std::ostream& os, const xboxkrnl::PXINPUT_STATE& value); +// std::ostream& operator<<(std::ostream& os, const xboxkrnl::PXPP_DEVICE_TYPE& value); +// std::ostream& operator<<(std::ostream& os, const xboxkrnl::PXTHREAD_NOTIFICATION& value); // -> pfnNotifyRoutine +// std::ostream& operator<<(std::ostream& os, const xboxkrnl::UCHAR& value); + // PsCreateSystemThread proxy parameters typedef struct _PCSTProxyParam { @@ -1059,6 +1125,23 @@ static CHAR* NtStatusToString ( IN NTSTATUS Status ) } } +// Separate function for logging, otherwise in PCSTProxy __try wont work (Compiler Error C2712) +void PCSTProxy_log +( + uint32 StartContext1, + uint32 StartContext2, + uint32 StartRoutine, + BOOL StartSuspended, + HANDLE hStartedEvent +) +{ + LOG_FUNC_BEGIN + LOG_FUNC_ARG(StartContext1) + LOG_FUNC_ARG(StartContext2) + LOG_FUNC_ARG(StartRoutine) + LOG_FUNC_END; +} + // PsCreateSystemThread proxy procedure #pragma warning(push) #pragma warning(disable: 4731) // disable ebp modification warning @@ -1078,11 +1161,7 @@ static unsigned int WINAPI PCSTProxy // Once deleted, unable to directly access iPCSTProxyParam in remainder of function. delete iPCSTProxyParam; - LOG_FUNC_BEGIN - LOG_FUNC_ARG(StartContext1) - LOG_FUNC_ARG(StartContext2) - LOG_FUNC_ARG(StartRoutine) - LOG_FUNC_END; + PCSTProxy_log(StartContext1, StartContext2, StartRoutine, StartSuspended, hStartedEvent); if(StartSuspended == TRUE) SuspendThread(GetCurrentThread()); @@ -1115,9 +1194,7 @@ static unsigned int WINAPI PCSTProxy { SetEvent(hStartedEvent); - - - __asm + __asm { mov esi, StartRoutine push StartContext2