Skip to content

Commit

Permalink
Add more TraceLogging to ApiDispatchers (#17085)
Browse files Browse the repository at this point in the history
More TraceLogging = More better?
I made this change as I noticed that most calls are not being logged.
Even after this change some crucial information won't be logged
(for instance arrays of `INPUT_RECORD`), because I couldn't come up
with a clever way to do so, but I think this is better than nothing.

(cherry picked from commit f49cf44)
Service-Card-Id: 92374415
Service-Version: 1.20
  • Loading branch information
lhecker authored and DHowett committed Apr 22, 2024
1 parent 248665b commit c0b2f55
Show file tree
Hide file tree
Showing 5 changed files with 375 additions and 58 deletions.
1 change: 0 additions & 1 deletion src/host/_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ using Microsoft::Console::Interactivity::ServiceLocator;
// - <none>
void WriteToScreen(SCREEN_INFORMATION& screenInfo, const Viewport& region)
{
DBGOUTPUT(("WriteToScreen\n"));
const auto& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
// update to screen, if we're not iconic.
if (!screenInfo.IsActiveScreenBuffer() || WI_IsFlagSet(gci.Flags, CONSOLE_IS_ICONIC))
Expand Down
2 changes: 0 additions & 2 deletions src/host/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ int ConvertToOem(const UINT uiCodePage,
const UINT cchTarget) noexcept
{
FAIL_FAST_IF(!(pwchSource != (LPWSTR)pchTarget));
DBGCHARS(("ConvertToOem U->%d %.*ls\n", uiCodePage, cchSource > 10 ? 10 : cchSource, pwchSource));
// clang-format off
#pragma prefast(suppress: __WARNING_W2A_BEST_FIT, "WC_NO_BEST_FIT_CHARS doesn't work in many codepages. Retain old behavior.")
// clang-format on
Expand All @@ -80,6 +79,5 @@ int ConvertOutputToUnicode(_In_ UINT uiCodePage,
{
FAIL_FAST_IF(!(cchTarget > 0));
pwchTarget[0] = L'\0';
DBGCHARS(("ConvertOutputToUnicode %d->U %.*s\n", uiCodePage, cchSource > 10 ? 10 : cchSource, pchSource));
return MultiByteToWideChar(uiCodePage, MB_USEGLYPHCHARS, pchSource, cchSource, pwchTarget, cchTarget);
}
41 changes: 21 additions & 20 deletions src/host/tracing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,29 @@ Author(s):

#pragma once

#include <functional>

#include "../types/inc/Viewport.hpp"

#if DBG
#define DBGCHARS(_params_) \
{ \
Tracing::s_TraceChars _params_; \
}
#define DBGOUTPUT(_params_) \
{ \
Tracing::s_TraceOutput _params_; \
}
#else
#define DBGCHARS(_params_)
#define DBGOUTPUT(_params_)
#endif

#define TraceLoggingConsoleCoord(value, name) \
TraceLoggingStruct(2, name), \
TraceLoggingInt32(value.X, "X"), \
TraceLoggingInt32(value.Y, "Y")
#define TraceLoggingConsoleCoord(value, name) \
TraceLoggingPackedData(&value, sizeof(COORD)), \
TraceLoggingPackedStruct(2, name), \
TraceLoggingPackedMetadata(TlgInINT16, "X"), \
TraceLoggingPackedMetadata(TlgInINT16, "Y")

#define TraceLoggingConsoleSmallRect(value, name) \
TraceLoggingPackedData(&value, sizeof(SMALL_RECT)), \
TraceLoggingPackedStruct(4, name), \
TraceLoggingInt16(TlgInINT16, "Left"), \
TraceLoggingInt16(TlgInINT16, "Top"), \
TraceLoggingInt16(TlgInINT16, "Right"), \
TraceLoggingInt16(TlgInINT16, "Bottom")

// We intentionally don't differentiate between A and W versions of CHAR_INFO, because some particularly nasty
// applications smuggle data in the upper bytes of the UnicodeChar field while using the A APIs and then they
// expect to read the same values back at a later time, which is something we stopped supporting.
#define TraceLoggingConsoleCharInfo(value, name) \
TraceLoggingStruct(2, name), \
TraceLoggingInt16(value.Char.UnicodeChar, "Char"), \
TraceLoggingInt16(value.Attributes, "Attributes")

class Tracing
{
Expand Down
4 changes: 0 additions & 4 deletions src/propsheet/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,9 @@ void Undo(HWND hControlWindow);

#define DBGFONTS(_params_)
#define DBGFONTS2(_params_)
#define DBGCHARS(_params_)
#define DBGOUTPUT(_params_)
#else
#define DBGFONTS(_params_)
#define DBGFONTS2(_params_)
#define DBGCHARS(_params_)
#define DBGOUTPUT(_params_)
#endif
// clang-format on

Expand Down
Loading

0 comments on commit c0b2f55

Please sign in to comment.