Skip to content
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

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

Open
the-ress opened this issue Oct 24, 2018 · 15 comments
Open

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

the-ress opened this issue Oct 24, 2018 · 15 comments
Labels
Hacktoberfest Potential candidate to participate in Hacktoberfest Up-for-Grabs Up-for-grabs issues are not high priorities, and may be opportunities for external contributors WG-Interactive-Debugging debugging PowerShell script

Comments

@the-ress
Copy link

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 the-ress changed the title Set-PSDebug -Trace 1 doesn't prints only first line of a multiline command Set-PSDebug -Trace 1 prints only first line of a multiline command Oct 24, 2018
@SteveL-MSFT SteveL-MSFT added the WG-Interactive-Debugging debugging PowerShell script label Oct 24, 2018
@iSazonov
Copy link
Collaborator

@the-ress Can you repo without PSReadline loaded?

@SteveL-MSFT
Copy link
Member

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

@SteveL-MSFT
Copy link
Member

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

@SteveL-MSFT SteveL-MSFT added Up-for-Grabs Up-for-grabs issues are not high priorities, and may be opportunities for external contributors Hacktoberfest Potential candidate to participate in Hacktoberfest labels Oct 26, 2018
@dwalleck
Copy link

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?

@SteveL-MSFT
Copy link
Member

@dwalleck yes, seems correct. Consider it yours!

@lzybkr
Copy link
Member

lzybkr commented Oct 26, 2018

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

@SteveL-MSFT
Copy link
Member

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.

@iSazonov
Copy link
Collaborator

iSazonov commented Nov 2, 2018

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

@the-ress
Copy link
Author

the-ress commented Nov 2, 2018

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.

@SteveL-MSFT
Copy link
Member

@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

@vexx32
Copy link
Collaborator

vexx32 commented Nov 2, 2018

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.

@ElvenSpellmaker
Copy link

This is still an issue to this day...

PowerShell 7.1.0

@lnking81
Copy link

lnking81 commented Nov 15, 2022

This is still an issue to this day...

PowerShell 7.1.0

And to this day @7.3.0

@taehokangithub
Copy link

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

@microsoft-github-policy-service microsoft-github-policy-service bot added the Resolution-No Activity Issue has had no activity for 6 months or more label Jan 1, 2024
@jeremy-visionaid
Copy link

Still an issue in 7.4.0

@microsoft-github-policy-service microsoft-github-policy-service bot removed the Resolution-No Activity Issue has had no activity for 6 months or more label Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Hacktoberfest Potential candidate to participate in Hacktoberfest Up-for-Grabs Up-for-grabs issues are not high priorities, and may be opportunities for external contributors WG-Interactive-Debugging debugging PowerShell script
Projects
None yet
Development

No branches or pull requests

10 participants