terminal/src/host/tracing.hpp
Carlos Zamora 360c655acc
UIA: Fix GetVisibleRanges() and add Tracing (#4495)
## Summary of the Pull Request
Debugging our custom UIA providers has been a painful experience because outputting content to VS may result in UIA Clients getting impatient and giving up on extracting data.

Adding tracing allows us to debug these providers without getting in the way of reproducing a bug. This will help immensely with developing accessibility features on Windows Terminal and Console.

This pull request additionally contains payload from #4526:
* Make GetVisibleRanges() return one range (and add tracing for it).
`ScreenInfoUiaProvider::GetVisibleRanges()` used to return one range per line of visible text. The documentation for this function says that we should return one per contiguous span of text. Since all of the text in the TermControl will always be contiguous (at least by our standards), we should only ever be returning one range.

## PR Checklist
* [x] Closes #1914. Closes #4507.
* [x] CLA signed

## Detailed Description of the Pull Request / Additional comments
`UiaTracing` is a singleton class that is in charge of registration for trace logging. `TextRange` is used to trace `UiaTextRange`, whereas `TextProvider` is used to trace `ScreenInfoUiaProviderBase`.

`_getValue()` is overloaded to transform complex objects and enums into a string for logging.

`_getTextValue()` had to be added to be able to trace the text a UiaTextRange included. This makes following UiaTextRanges much simpler.

## Validation Steps Performed
Performed a few operations when under NVDA/Narrator and manually checked the results.
2020-02-20 23:50:43 +00:00

74 lines
2.5 KiB
C++

/*++
Copyright (c) Microsoft Corporation
Licensed under the MIT license.
Module Name:
- tracing.hpp
Abstract:
- This module is used for recording tracing/debugging information to the telemetry ETW channel
- The data is not automatically broadcast to telemetry backends as it does not set the TELEMETRY keyword.
- NOTE: Many functions in this file appear to be copy/pastes. This is because the TraceLog documentation warns
to not be "cute" in trying to reduce its macro usages with variables as it can cause unexpected behavior.
Author(s):
- Michael Niksa (miniksa) 25-Nov-2014
--*/
#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
class Tracing
{
public:
~Tracing();
static Tracing s_TraceApiCall(const NTSTATUS& result, PCSTR traceName);
static void s_TraceApi(const NTSTATUS status, const CONSOLE_GETLARGESTWINDOWSIZE_MSG* const a);
static void s_TraceApi(const NTSTATUS status, const CONSOLE_SCREENBUFFERINFO_MSG* const a, const bool fSet);
static void s_TraceApi(const NTSTATUS status, const CONSOLE_SETSCREENBUFFERSIZE_MSG* const a);
static void s_TraceApi(const NTSTATUS status, const CONSOLE_SETWINDOWINFO_MSG* const a);
static void s_TraceApi(_In_ const void* const buffer, const CONSOLE_WRITECONSOLE_MSG* const a);
static void s_TraceApi(const CONSOLE_SCREENBUFFERINFO_MSG* const a);
static void s_TraceApi(const CONSOLE_MODE_MSG* const a, const std::wstring& handleType);
static void s_TraceApi(const CONSOLE_SETTEXTATTRIBUTE_MSG* const a);
static void s_TraceApi(const CONSOLE_WRITECONSOLEOUTPUTSTRING_MSG* const a);
static void s_TraceWindowViewport(const Microsoft::Console::Types::Viewport& viewport);
static void s_TraceChars(_In_z_ const char* pszMessage, ...);
static void s_TraceOutput(_In_z_ const char* pszMessage, ...);
static void s_TraceWindowMessage(const MSG& msg);
static void s_TraceInputRecord(const INPUT_RECORD& inputRecord);
static void __stdcall TraceFailure(const wil::FailureInfo& failure) noexcept;
private:
static ULONG s_ulDebugFlag;
Tracing(std::function<void()> onExit);
std::function<void()> _onExit;
};