-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
|
||
| ui.WriteDebugLine(msg, ref pref); | ||
| // Write each line separately so each gets the DEBUG: prefix | ||
| string[] lines = msg.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we split at "\r" here as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for catching this! Updated to include "\r" for consistency with the existing pattern used elsewhere in the same file (line 5316).
string[] lines = msg.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);Commit: feecda0
|
|
||
| ui.WriteDebugLine(msg, ref pref); | ||
| // Write each line separately so each gets the DEBUG: prefix | ||
| string[] lines = msg.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can BriefMessage() return string[]?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion! I've updated BriefMessage(IScriptExtent) to return string[] directly instead of building a single concatenated string.
Commit: 71d46a1
PR Summary
Fix
Set-PSDebug -Traceto display all lines of multiline commands.PR Context
Fixes #8113
When using
Set-PSDebug -Trace 1or-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:
Output:
After this fix:
Output:
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerDescription
Root Cause
The
TraceLinemethod 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
Added a new overload
PositionUtilities.BriefMessage(IScriptExtent extent)that handles multiline extents by:Changed
TraceLineto 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- ChangedTraceLineto use extent-basedBriefMessageand write each line separatelysrc/System.Management.Automation/engine/parser/Position.cs- Added newBriefMessage(IScriptExtent)overloadtest/powershell/Modules/Microsoft.PowerShell.Core/Set-PSDebug.Tests.ps1- Added tests for multiline command tracing with-Trace 1and-Trace 2Testing
Test Coverage
Added test cases that:
Write-Output) and continuation line (bar") appear in debug output withDEBUG:prefixTests cover both
-Trace 1and-Trace 2options.Automated Tests
All tests pass: