Skip to content

Add an opt-in for capturing sanitizer logs from the language server#14573

Open
sean-mcmanus wants to merge 3 commits into
mainfrom
seanmcm/sanitizerLaunch
Open

Add an opt-in for capturing sanitizer logs from the language server#14573
sean-mcmanus wants to merge 3 commits into
mainfrom
seanmcm/sanitizerLaunch

Conversation

@sean-mcmanus

@sean-mcmanus sean-mcmanus commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Fix by Copilot with Claude Opus 4.8 in VS Code.

Problem

When running a sanitizer build of the language server (a -tsan/-asan/-ubsan
CMake preset), the sanitizer prints its reports to stderr. Because the
extension talks to the language server over stdio, those reports are easily
lost, and a crash log only shows the sanitizer shutting down, not the actual
report. There was no convenient, checked-in way to capture them, so developers
resorted to attaching a debugger (which can hang the process at shutdown) or
hand-editing the spawn code.

Change

Add an opt-in, gated on the CPPTOOLS_SANITIZER_LOG_DIR environment variable:

  • client.ts: new getSanitizerServerEnv() helper. When CPPTOOLS_SANITIZER_LOG_DIR
    is set, it routes each sanitizer's log_path into that directory and returns the
    merged env for the spawned language server; the cpptools-srv/-srv2 children
    inherit it, so every process writes its own "/." file
    (tsan/asan/ubsan). Any TSAN_OPTIONS/ASAN_OPTIONS/UBSAN_OPTIONS the developer
    already set are preserved. The helper best-effort creates the directory
    (the sanitizer runtime does not create a missing one; without it reports
    silently fall back to stderr). It is wired into both the run and debug
    ServerOptions.
  • When the variable is unset (normal development, CI, released builds), the
    helper returns undefined, leaving the child environment inherited unchanged --
    a true no-op, safe to leave checked in.
  • .vscode/launch.json: new "Run Extension (capture sanitizer logs)"
    configuration (based on "Run Extension") that sets
    CPPTOOLS_SANITIZER_LOG_DIR=${userHome}/cpptools-sanitizer-logs, so a developer
    can just pick it from the Run and Debug dropdown.
  • readme.developer.md: new "Capturing sanitizer diagnostics from the language
    server" section (with a Table of Contents entry) documenting the variable, the
    launch configuration, and how to read the resulting files.

Usage

Build a sanitizer preset of the language server, pick "Run Extension (capture
sanitizer logs)" from the Run and Debug dropdown (or set
CPPTOOLS_SANITIZER_LOG_DIR yourself), reproduce, then read
~/cpptools-sanitizer-logs/tsan. (or asan.* / ubsan.*). No debugger is
required, which also avoids the shutdown-time hang that can occur when a
debugger is attached to a sanitizer process as it exits.

Notes

  • This is in the vscode-cpptools (extension) repo; the native sanitizer/crash
    handler changes are a separate PR in the VS repo.
  • No behavior change unless the environment variable is set.

Testing

Ran a TSan build of the language server with the new launch configuration;
reports were written to ~/cpptools-sanitizer-logs/tsan.. With the variable
unset, the spawned environment is unchanged and there is no behavior difference.

This comment was marked as resolved.

@sean-mcmanus sean-mcmanus marked this pull request as ready for review July 9, 2026 22:39
@sean-mcmanus sean-mcmanus requested a review from a team as a code owner July 9, 2026 22:39
@sean-mcmanus sean-mcmanus requested a review from Copilot July 9, 2026 22:39

This comment was marked as resolved.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Pull Request

Development

Successfully merging this pull request may close these issues.

2 participants