Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix Set-PSDebug -Trace to display all lines of multiline commands#26537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
yotsuda wants to merge1 commit intoPowerShell:master
base:master
Choose a base branch
Loading
fromyotsuda:fix-issue-8113-trace-multiline

Conversation

@yotsuda
Copy link
Contributor

PR Summary

FixSet-PSDebug -Trace to display all lines of multiline commands.

PR Context

Fixes#8113

When usingSet-PSDebug -Trace 1 or-Trace 2, multiline commands (e.g., using backtick line continuation) only showed the first line in debug output. This made it difficult to trace and debug scripts with multiline commands.

Before this fix:

Set-PSDebug-Trace1Write-Output"foo`bar"

Output:

DEBUG:    3+  >>>> Write-Output "foo `foobar

After this fix:

Output:

DEBUG:    3+  >>>> Write-Output "foo `DEBUG:    4+  >>>> bar"foobar

PR Checklist

Description

Root Cause

TheTraceLine method in the debugger was callingPositionUtilities.BriefMessage(extent.StartScriptPosition), which only considers the start position of an extent. For multiline commands, this meant only the first line was displayed.

Solution

  1. Added a new overloadPositionUtilities.BriefMessage(IScriptExtent extent) that handles multiline extents by:

    • Detecting if an extent spans multiple lines
    • For single-line extents, delegating to the existing method
    • For multiline extents, formatting each line with appropriate line numbers and markers
  2. ChangedTraceLine to call the new extent-based overload and write each line separately so each gets theDEBUG: prefix.

Files Changed

  • src/System.Management.Automation/engine/debugger/debugger.cs - ChangedTraceLine to use extent-basedBriefMessage and write each line separately
  • src/System.Management.Automation/engine/parser/Position.cs - Added newBriefMessage(IScriptExtent) overload
  • test/powershell/Modules/Microsoft.PowerShell.Core/Set-PSDebug.Tests.ps1 - Added tests for multiline command tracing with-Trace 1 and-Trace 2

Testing

Test Coverage

Added test cases that:

  1. Create a script with a multiline command using backtick line continuation
  2. Run it in a separate process to capture trace output
  3. Verify both the first line (Write-Output) and continuation line (bar") appear in debug output withDEBUG: prefix

Tests cover both-Trace 1 and-Trace 2 options.

Automated Tests

All tests pass:

Context Tracing can be used  [+] Should be able to go through the tracing options  [+] Should be able to set strict  [+] Should skip magic extents created by pwsh  [+] Should trace all lines of a multiline command  [+] Should trace all lines of a multiline command with -Trace 2Tests Passed: 5, Failed: 0

@microsoft-github-policy-servicemicrosoft-github-policy-servicebot added the Review - NeededThe PR is being reviewed labelDec 4, 2025
@iSazonoviSazonov added the CL-GeneralIndicates that a PR should be marked as a general cmdlet change in the Change Log labelDec 5, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@daxian-dbwdaxian-dbwAwaiting requested review from daxian-dbwdaxian-dbw is a code owner

@SeeminglyScienceSeeminglyScienceAwaiting requested review from SeeminglyScienceSeeminglyScience is a code owner

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

CL-GeneralIndicates that a PR should be marked as a general cmdlet change in the Change LogReview - NeededThe PR is being reviewed

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Set-PSDebug -Trace 1 prints only first line of a multiline command

2 participants

@yotsuda@iSazonov

[8]ページ先頭

©2009-2025 Movatter.jp