WSL icon indicating copy to clipboard operation
WSL copied to clipboard

WSLA: Add initial wsladiag tool with basic --list command and placeholder ListSessions

Open beena352 opened this issue 2 months ago • 9 comments

This change adds the first version of the wsladiag diagnostic tool and hooks it up to the WSLA host service.

  • Adds a new wsladiag executable under src/windows/wsladiag and integrates it into the CMake build.
  • Implements a basic main.cpp that parses --list and --help arguments and prints a placeholder message for --list.
  • Updates WSLAUserSession::ListSessions to return a safe empty result instead of E_NOTIMPL, so it is ready to be called from wsladiag in a follow-up change.
  • Verified that the solution builds and that wsladiag.exe runs 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 wsladiag executable under src/windows/wsladiag.
  • Adds a simple main.cpp that:
  • Parses --list and --help command-line options.
  • For --list, currently prints a placeholder message. A follow-up change will connect this to the WSLA host service ListSessions COM 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_NOTIMPL stub implementation with a safe placeholder that:
  • Validates the output parameters.
  • Returns an empty WSLA_SESSION_INFORMATION list and a SessionsCount of 0.
  • This allows callers (such as wsladiag) to start wiring up the COM call without hitting E_NOTIMPL. A later change will populate the result from WSLAUserSessionImpl::m_sessions and 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.exe is produced under bin\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::ListSessions from E_NOTIMPL to an empty result does not break the service build.

beena352 avatar Nov 14 '25 20:11 beena352

@microsoft-github-policy-service agree company="Microsoft"

beena352 avatar Nov 14 '25 21:11 beena352

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.

beena352 avatar Nov 18 '25 07:11 beena352

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.

OneBlue avatar Nov 18 '25 19:11 OneBlue

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

OneBlue avatar Nov 18 '25 19:11 OneBlue

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.

beena352 avatar Nov 19 '25 18:11 beena352

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.

beena352 avatar Nov 20 '25 18:11 beena352

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 (""). This keeps the code cleaner and matches the formatting logic already defined in the shared formatter.

beena352 avatar Nov 21 '25 00:11 beena352

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.

beena352 avatar Nov 26 '25 23:11 beena352

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.

beena352 avatar Nov 30 '25 03:11 beena352