PowerShell icon indicating copy to clipboard operation
PowerShell copied to clipboard

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

Open the-ress opened this issue 7 years ago • 21 comments

Steps to reproduce

Set-PSDebug -Trace 1

Write-Output "foo `
bar"

Expected behavior

Something like:

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

foo
bar

Actual behavior

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

foo
bar

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.2.0-preview.1
PSEdition                      Core
GitCommitId                    6.2.0-preview.1
OS                             Microsoft Windows 10.0.17134
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

the-ress avatar Oct 24 '18 11:10 the-ress

@the-ress Can you repo without PSReadline loaded?

iSazonov avatar Oct 25 '18 05:10 iSazonov

It repros without PSReadLine. Seems like it should be outputting the logical line and not the physical line

SteveL-MSFT avatar Oct 25 '18 19:10 SteveL-MSFT

The problem is here. Basically it only traces the line at the start of the extent.

SteveL-MSFT avatar Oct 26 '18 02:10 SteveL-MSFT

I'd be interested in picking this issue up if it's still available. Based on @SteveL-MSFT 's previous comment, it looks like the BriefMessage method of PositionUtilities needs to be multi-line aware. Does that sound about right?

dwalleck avatar Oct 26 '18 06:10 dwalleck

@dwalleck yes, seems correct. Consider it yours!

SteveL-MSFT avatar Oct 26 '18 15:10 SteveL-MSFT

It will take some smarts to provide a better experience. Most statements have multiple lines, e.g. an if statement. If you make a change, compare the output to the following and decide if it's an improvement or not.

PS> dir $env:TEMP | ForEach-Object {
>>     if ((Get-Random -Maximum 15) -lt 1) {
>>         "Lucky file is $_"
>>         break
>>     }
>> }
DEBUG:    1+  >>>> dir $env:TEMP | ForEach-Object {
DEBUG:     ! CALL function '<ScriptBlock>'
DEBUG:    1+ dir $env:TEMP | ForEach-Object  >>>> {
DEBUG:     ! CALL function '<ScriptBlock>'
DEBUG:    2+     if ( >>>> (Get-Random -Maximum 15) -lt 1) {
DEBUG:    6+  >>>> }
DEBUG:    1+ dir $env:TEMP | ForEach-Object  >>>> {
DEBUG:     ! CALL function '<ScriptBlock>'
DEBUG:    2+     if ( >>>> (Get-Random -Maximum 15) -lt 1) {
DEBUG:    6+  >>>> }
DEBUG:    1+ dir $env:TEMP | ForEach-Object  >>>> {
DEBUG:     ! CALL function '<ScriptBlock>'
DEBUG:    2+     if ( >>>> (Get-Random -Maximum 15) -lt 1) {
DEBUG:    6+  >>>> }
DEBUG:    1+ dir $env:TEMP | ForEach-Object  >>>> {
DEBUG:     ! CALL function '<ScriptBlock>'
DEBUG:    2+     if ( >>>> (Get-Random -Maximum 15) -lt 1) {
DEBUG:    6+  >>>> }
DEBUG:    1+ dir $env:TEMP | ForEach-Object  >>>> {
DEBUG:     ! CALL function '<ScriptBlock>'
DEBUG:    2+     if ( >>>> (Get-Random -Maximum 15) -lt 1) {
DEBUG:    6+  >>>> }
DEBUG:    1+ dir $env:TEMP | ForEach-Object  >>>> {
DEBUG:     ! CALL function '<ScriptBlock>'
DEBUG:    2+     if ( >>>> (Get-Random -Maximum 15) -lt 1) {
DEBUG:    6+  >>>> }
DEBUG:    1+ dir $env:TEMP | ForEach-Object  >>>> {
DEBUG:     ! CALL function '<ScriptBlock>'
DEBUG:    2+     if ( >>>> (Get-Random -Maximum 15) -lt 1) {
DEBUG:    6+  >>>> }
DEBUG:    1+ dir $env:TEMP | ForEach-Object  >>>> {
DEBUG:     ! CALL function '<ScriptBlock>'
DEBUG:    2+     if ( >>>> (Get-Random -Maximum 15) -lt 1) {
DEBUG:    6+  >>>> }
DEBUG:    1+ dir $env:TEMP | ForEach-Object  >>>> {
DEBUG:     ! CALL function '<ScriptBlock>'
DEBUG:    2+     if ( >>>> (Get-Random -Maximum 15) -lt 1) {
DEBUG:    3+          >>>> "Lucky file is $_"
Lucky file is wct721E.tmp
DEBUG:    4+          >>>> break

lzybkr avatar Oct 26 '18 18:10 lzybkr

Based on @lzybkr's feedback on the PR, it seems that we should conclude on what we think is the optimal expected output for multiline. I would also suggest that it should be enabled via a parameter on Set-PSDebug rather than changing existing default behavior as some people may prefer the existing single line.

SteveL-MSFT avatar Nov 01 '18 16:11 SteveL-MSFT

I should point that the original repo sample is about multiline with backtick.

iSazonov avatar Nov 02 '18 05:11 iSazonov

The actual code I was debugging looked like this: (Note the extra backtick on line 3.)

msbuild /m /restore MyApp.sln `
    /p:Configuration="$Configuration" `
    /p:Platform="$Platform" `
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }

Seeing only the first line of the command wasn't really helpful.

the-ress avatar Nov 02 '18 06:11 the-ress

@iSazonov thanks for pointing that out! We should focus on when a single logical line is multiple physical lines and not the general multi line case

SteveL-MSFT avatar Nov 02 '18 14:11 SteveL-MSFT

We should be able to simply check if the line referenced ends with a backtick, and if it does, grab the next line as well, loop until we find a line that doesn't end in a backtick.

vexx32 avatar Nov 02 '18 14:11 vexx32

This is still an issue to this day...

PowerShell 7.1.0

ElvenSpellmaker avatar Jan 21 '21 16:01 ElvenSpellmaker

This is still an issue to this day...

PowerShell 7.1.0

And to this day @7.3.0

lnking81 avatar Nov 15 '22 01:11 lnking81

Any news? How I can see the multi line commands? @7.3.4

taehokangithub avatar Jul 05 '23 11:07 taehokangithub

Still an issue in 7.4.0

jeremy-visionaid avatar Jan 02 '24 03:01 jeremy-visionaid

Still an issue

ElvenSpellmaker avatar Jun 30 '24 17:06 ElvenSpellmaker