diff options
| author | 2018-01-05 00:45:13 -0500 | |
|---|---|---|
| committer | 2018-01-05 00:45:13 -0500 | |
| commit | d083c07c4622a73d1ff61cdc90354aa34e16e2ed (patch) | |
| tree | 11596f8626d8025d74b0eefe04c399270568bdc3 /src | |
| parent | cmake: Add script to find Unicorn. (diff) | |
| download | yuzu-d083c07c4622a73d1ff61cdc90354aa34e16e2ed.tar.gz yuzu-d083c07c4622a73d1ff61cdc90354aa34e16e2ed.tar.xz yuzu-d083c07c4622a73d1ff61cdc90354aa34e16e2ed.zip | |
lm: Improve Log() to format a useful string.
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/service/lm/lm.cpp | 85 |
1 files changed, 75 insertions, 10 deletions
diff --git a/src/core/hle/service/lm/lm.cpp b/src/core/hle/service/lm/lm.cpp index 210c1958e..9dac78536 100644 --- a/src/core/hle/service/lm/lm.cpp +++ b/src/core/hle/service/lm/lm.cpp | |||
| @@ -24,17 +24,31 @@ public: | |||
| 24 | 24 | ||
| 25 | private: | 25 | private: |
| 26 | struct MessageHeader { | 26 | struct MessageHeader { |
| 27 | enum Flags : u32_le { | ||
| 28 | IsHead = 1, | ||
| 29 | IsTail = 2, | ||
| 30 | }; | ||
| 31 | |||
| 27 | u64_le pid; | 32 | u64_le pid; |
| 28 | u64_le threadContext; | 33 | u64_le threadContext; |
| 29 | union { | 34 | union { |
| 30 | BitField<0, 16, u32_le> flags; | 35 | BitField<0, 16, Flags> flags; |
| 31 | BitField<16, 8, u32_le> severity; | 36 | BitField<16, 8, u32_le> severity; |
| 32 | BitField<24, 8, u32_le> verbosity; | 37 | BitField<24, 8, u32_le> verbosity; |
| 33 | }; | 38 | }; |
| 34 | u32_le payload_size; | 39 | u32_le payload_size; |
| 35 | INSERT_PADDING_WORDS(2); | ||
| 36 | }; | 40 | }; |
| 37 | static_assert(sizeof(MessageHeader) == 0x20, "MessageHeader is incorrect size"); | 41 | static_assert(sizeof(MessageHeader) == 0x18, "MessageHeader is incorrect size"); |
| 42 | |||
| 43 | /// Log field type | ||
| 44 | enum class Field : u8 { | ||
| 45 | Message = 2, | ||
| 46 | Line = 3, | ||
| 47 | Filename = 4, | ||
| 48 | Function = 5, | ||
| 49 | Module = 6, | ||
| 50 | Thread = 7, | ||
| 51 | }; | ||
| 38 | 52 | ||
| 39 | /** | 53 | /** |
| 40 | * LM::Initialize service function | 54 | * LM::Initialize service function |
| @@ -44,16 +58,67 @@ private: | |||
| 44 | * 0: ResultCode | 58 | * 0: ResultCode |
| 45 | */ | 59 | */ |
| 46 | void Log(Kernel::HLERequestContext& ctx) { | 60 | void Log(Kernel::HLERequestContext& ctx) { |
| 61 | // This function only succeeds - Get that out of the way | ||
| 62 | IPC::RequestBuilder rb{ctx, 1}; | ||
| 63 | rb.Push(RESULT_SUCCESS); | ||
| 64 | |||
| 65 | // Read MessageHeader, despite not doing anything with it right now | ||
| 47 | MessageHeader header{}; | 66 | MessageHeader header{}; |
| 48 | Memory::ReadBlock(ctx.BufferDescriptorX()[0].Address(), &header, sizeof(MessageHeader)); | 67 | VAddr addr{ctx.BufferDescriptorX()[0].Address()}; |
| 68 | const VAddr end_addr{addr + ctx.BufferDescriptorX()[0].size}; | ||
| 69 | Memory::ReadBlock(addr, &header, sizeof(MessageHeader)); | ||
| 70 | addr += sizeof(MessageHeader); | ||
| 49 | 71 | ||
| 50 | std::vector<char> string(header.payload_size); | 72 | // Parse out log metadata |
| 51 | Memory::ReadBlock(ctx.BufferDescriptorX()[0].Address() + sizeof(MessageHeader), | 73 | u32 line{}; |
| 52 | string.data(), header.payload_size); | 74 | std::string message, filename, function; |
| 53 | LOG_DEBUG(Debug_Emulated, "%.*s", header.payload_size, string.data()); | 75 | while (addr < end_addr) { |
| 76 | const Field field{static_cast<Field>(Memory::Read8(addr++))}; | ||
| 77 | size_t length{Memory::Read8(addr++)}; | ||
| 78 | switch (field) { | ||
| 79 | case Field::Message: | ||
| 80 | message = Memory::ReadCString(addr, length); | ||
| 81 | break; | ||
| 82 | case Field::Line: | ||
| 83 | line = Memory::Read32(addr); | ||
| 84 | break; | ||
| 85 | case Field::Filename: | ||
| 86 | filename = Memory::ReadCString(addr, length); | ||
| 87 | break; | ||
| 88 | case Field::Function: | ||
| 89 | function = Memory::ReadCString(addr, length); | ||
| 90 | break; | ||
| 91 | } | ||
| 92 | addr += length; | ||
| 93 | } | ||
| 54 | 94 | ||
| 55 | IPC::RequestBuilder rb{ctx, 1}; | 95 | // Empty log - nothing to do here |
| 56 | rb.Push(RESULT_SUCCESS); | 96 | if (message.size() <= 1) { |
| 97 | return; | ||
| 98 | } | ||
| 99 | |||
| 100 | // Remove trailing new line | ||
| 101 | if (message[message.length() - 1] == '\n') { | ||
| 102 | message.erase(message.length() - 1); | ||
| 103 | } | ||
| 104 | |||
| 105 | // Format a nicely printable string out of the log metadata | ||
| 106 | std::string output; | ||
| 107 | if (filename.size()) { | ||
| 108 | output += filename + ':'; | ||
| 109 | } | ||
| 110 | if (function.size()) { | ||
| 111 | output += function + ':'; | ||
| 112 | } | ||
| 113 | if (line) { | ||
| 114 | output += std::to_string(line) + ':'; | ||
| 115 | } | ||
| 116 | if (output.back() == ':') { | ||
| 117 | output += ' '; | ||
| 118 | } | ||
| 119 | output += message; | ||
| 120 | |||
| 121 | LOG_DEBUG(Debug_Emulated, "%s", output.c_str()); | ||
| 57 | } | 122 | } |
| 58 | }; | 123 | }; |
| 59 | 124 | ||