WSLA: Add initial wsladiag tool with basic --list command and placeholder ListSessions
This change adds the first version of the wsladiag diagnostic tool and hooks it up to the WSLA host service.
- Adds a new
wsladiagexecutable undersrc/windows/wsladiagand integrates it into the CMake build. - Implements a basic
main.cppthat parses--listand--helparguments and prints a placeholder message for--list. - Updates
WSLAUserSession::ListSessionsto return a safe empty result instead ofE_NOTIMPL, so it is ready to be called fromwsladiagin a follow-up change. - Verified that the solution builds and that
wsladiag.exeruns and accepts--list/--help.
Detailed Description of the Pull Request / Additional comments
This PR is the first step toward a WSLA-specific diagnostic tool (wsladiag) that can be used by developers to inspect and debug WSLA sessions.
Tool side (wsladiag):
- Introduces a new
wsladiagexecutable undersrc/windows/wsladiag. - Adds a simple
main.cppthat: - Parses
--listand--helpcommand-line options. - For
--list, currently prints a placeholder message. A follow-up change will connect this to the WSLA host serviceListSessionsCOM API. - Integrates the new executable into the existing CMake build so it is produced as part of the Windows build.
Host service side (WSLAUserSession::ListSessions):
- Replaces the
E_NOTIMPLstub implementation with a safe placeholder that: - Validates the output parameters.
- Returns an empty
WSLA_SESSION_INFORMATIONlist and aSessionsCountof0. - This allows callers (such as
wsladiag) to start wiring up the COM call without hittingE_NOTIMPL. A later change will populate the result fromWSLAUserSessionImpl::m_sessionsand return real session information.
This PR is intended as a starting point / draft to confirm the overall direction (shape of the tool, build integration, and host API surface) before adding the actual session enumeration and debug-shell functionality.
Validation Steps Performed
- Built the solution in Debug configuration:
-
cmake --build . --config Debug
-
- Confirmed that
wsladiag.exeis produced underbin\x64\Debug. - Ran the tool manually:
-
wsladiag.exe --help→ shows usage text. -
wsladiag.exe --list→ prints the placeholder message without errors.
-
- Verified that updating
WSLAUserSession::ListSessionsfromE_NOTIMPLto an empty result does not break the service build.
@microsoft-github-policy-service agree company="Microsoft"
Latest update: • Added wsladiag main.cpp with full initialization (CRT/WIL/telemetry/COM/WSA) • Added argument parsing (--help / --list) • Added placeholder for future ListSessions COM call • Added wsladiag.exe to CMake BINARIES and msipackage dependencies • Added <File Id="wsladiag.exe" ...> to package.wix.in
Note: msipackage does not build locally due to missing clang/MSBuild tooling, but wsladiag.exe builds and runs normally. Please confirm the MSI wiring (BINARIES + File entry) looks correct.
FYI, to format the code to our clang-format rules, you can run powershell .\FormatSource.ps1 -ModifiedOnly $false.
You can also enable clang-format in VS for that to be done automatically.
Note: msipackage does not build locally due to missing clang/MSBuild tooling, but wsladiag.exe builds and runs normally. Please confirm the MSI wiring (BINARIES + File entry) looks correct.
The msipackage should build locally, so I'd be curious to see which error you're hitting, since there isn't a tooling requirement to build it (we use WIX, which is installed via nuget when you build)
The wiring does look correct though
Update
Pushed the initial implementation of the --list command in wsladiag.
This version:
Creates and initializes IWSLAUserSession
Calls ListSessions and prints session ID, creator PID, and display name
Handles UTF-8 → UTF-16 conversion for DisplayName
Cleans up all CoTaskMem-allocated fields and the session array
Uses the existing WSLA COM impersonation helpers
Adds basic usage/help output for the new flag
I'm still fixing an unrelated local environment issue where CMake can’t find the compiler, but the feature code itself is complete and ready for review.
Update: Renamed the telemetry provider to WslaTelemetryProvider and updated all places where it is used. Updated the session listing code to use WIL RAII (unique_cotaskmem_array_ptr) instead of raw pointers. Added a safe cleanup step for the inner DisplayName strings returned by the service. Added a small UTF-8 to wide string conversion helper to correctly handle DisplayName values. Improved error messages so they show both the HRESULT and a readable string when available.
I removed the explicit UTF-8 wide string conversion and now rely on the repo’s std::formatter<char*, wchar_t> helper. DisplayName is passed directly to std::format, with a small fallback for the null case ("
Update
Implemented WSLA session creation and enumeration (CreateSession and ListSessions) in the service.
Fixed session tracking by storing ComPtr<WSLASession> instead of raw pointers to ensure correct lifetime management.
Added basic session information population (SessionId + DisplayName).
Rebuilt the service, deployed the updated MSI, and verified the full flow: wsl --wsla creates a session and wsladiag --list correctly lists it.
Update: Addressed all review feedback: added std::atomic for session IDs, added try/CATCH_LOG() to ListSessions, switched DisplayName to a fixed-size buffer in the session struct, updated the wsladiag output code to use the new buffer, and applied the CMake/style nits.