terminal/src/terminal/parser/tracing.cpp
Michael Niksa 6f667f48ae
Make the terminal parser/adapter and related classes use modern… (#3956)
## Summary of the Pull Request
Refactors parsing/adapting libraries and consumers to use safer and/or more consistent mechanisms for passing information.

## PR Checklist
* [x] I work here
* [x] Tests still pass
* [x] Am a core contributor.

## Detailed Description of the Pull Request / Additional comments
This is in support of hopefully turning audit mode on to more projects. If I turned it on, it would immediately complain about certain classes of issues like pointer and size, pointer math, etc. The changes in this refactoring will eliminate those off the top.

Additionally, this has caught a bunch of comments all over the VT classes that weren't updated to match the parameters lists.

Additionally, this has caught a handful of member variables on classes that were completely unused (and now gone).

Additionally, I'm killing almost all hungarian and shortening variable names. I'm only really leaving 'p' for pointers.

Additionally, this is vaguely in support of a future where we can have "infinite scrollback" in that I'm moving things to size_t across the board. I know it's a bit of a memory cost, but all the casting and moving between types is error prone and unfun to save a couple bytes.

## Validation Steps Performed
- [x] build it
- [x] run all the tests
- [x] everyone looked real hard at it
2019-12-19 14:12:53 -08:00

128 lines
4.3 KiB
C++

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "precomp.h"
#include "tracing.hpp"
using namespace Microsoft::Console::VirtualTerminal;
ParserTracing::ParserTracing()
{
ClearSequenceTrace();
}
ParserTracing::~ParserTracing()
{
}
void ParserTracing::TraceStateChange(const std::wstring_view name) const
{
TraceLoggingWrite(g_hConsoleVirtTermParserEventTraceProvider,
"StateMachine_EnterState",
TraceLoggingCountedWideString(name.data(), gsl::narrow_cast<ULONG>(name.size())),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE));
}
void ParserTracing::TraceOnAction(const std::wstring_view name) const
{
TraceLoggingWrite(g_hConsoleVirtTermParserEventTraceProvider,
"StateMachine_Action",
TraceLoggingCountedWideString(name.data(), gsl::narrow_cast<ULONG>(name.size())),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE));
}
void ParserTracing::TraceOnExecute(const wchar_t wch) const
{
INT16 sch = (INT16)wch;
TraceLoggingWrite(g_hConsoleVirtTermParserEventTraceProvider,
"StateMachine_Execute",
TraceLoggingWChar(wch),
TraceLoggingHexInt16(sch),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE));
}
void ParserTracing::TraceOnExecuteFromEscape(const wchar_t wch) const
{
INT16 sch = (INT16)wch;
TraceLoggingWrite(g_hConsoleVirtTermParserEventTraceProvider,
"StateMachine_ExecuteFromEscape",
TraceLoggingWChar(wch),
TraceLoggingHexInt16(sch),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE));
}
void ParserTracing::TraceOnEvent(const std::wstring_view name) const
{
TraceLoggingWrite(g_hConsoleVirtTermParserEventTraceProvider,
"StateMachine_Event",
TraceLoggingCountedWideString(name.data(), gsl::narrow_cast<ULONG>(name.size())),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE));
}
void ParserTracing::TraceCharInput(const wchar_t wch)
{
AddSequenceTrace(wch);
INT16 sch = (INT16)wch;
TraceLoggingWrite(g_hConsoleVirtTermParserEventTraceProvider,
"StateMachine_NewChar",
TraceLoggingWChar(wch),
TraceLoggingHexInt16(sch),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE));
}
void ParserTracing::AddSequenceTrace(const wchar_t wch)
{
_sequenceTrace.push_back(wch);
}
void ParserTracing::DispatchSequenceTrace(const bool fSuccess)
{
if (fSuccess)
{
TraceLoggingWrite(g_hConsoleVirtTermParserEventTraceProvider,
"StateMachine_Sequence_OK",
TraceLoggingWideString(_sequenceTrace.c_str()),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE));
}
else
{
TraceLoggingWrite(g_hConsoleVirtTermParserEventTraceProvider,
"StateMachine_Sequence_FAIL",
TraceLoggingWideString(_sequenceTrace.c_str()),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE));
}
ClearSequenceTrace();
}
void ParserTracing::ClearSequenceTrace()
{
_sequenceTrace.clear();
}
// NOTE: I'm expecting this to not be null terminated
void ParserTracing::DispatchPrintRunTrace(const std::wstring_view string) const
{
if (string.size() == 1)
{
wchar_t wch = string.front();
INT16 sch = (INT16)wch;
TraceLoggingWrite(g_hConsoleVirtTermParserEventTraceProvider,
"StateMachine_PrintRun",
TraceLoggingWChar(wch),
TraceLoggingHexInt16(sch),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE));
}
else
{
const auto length = gsl::narrow_cast<ULONG>(string.size());
TraceLoggingWrite(g_hConsoleVirtTermParserEventTraceProvider,
"StateMachine_PrintRun",
TraceLoggingCountedWideString(string.data(), length),
TraceLoggingValue(length),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE));
}
}