vscode-powershell icon indicating copy to clipboard operation
vscode-powershell copied to clipboard

debugging an external host should break at any statement

Open jjsmeets opened this issue 1 year ago • 3 comments

Prerequisites

  • [X] I have written a descriptive issue title.
  • [X] I have searched all issues to ensure it has not already been reported.

Summary

I have seen video's of vcode/powershell where when attaching to a host powershell process (running any script) using an attach configuration that script stops where it currently was executing.

This does not happen in the current powershell version (7.4.6). It also does not happen when doing the attach manually using enter-psHostProcess followed by debug-runspace. But it works when using debug-runspace -breakall.

I have seen that breakAll is new sinds powershell 7.2. I expect that in the powershell extension when using an attach configuration the old version "debug-runspace" is used and not the new version "debug-runspace -breakall".

Proposed Design

Can this be changed back to it was before powershell 7.2 (or configured in the launch configuration)?

jjsmeets avatar Oct 30 '24 10:10 jjsmeets

Thanks for your submission!

The external debugging, especially around breakpoints, is very finicky at the moment. I'm going to peg this as dependent on https://github.com/PowerShell/vscode-powershell/pull/4065 and once that breakpointing sync problem is solved we can look more into the remothing issue there.

JustinGrote avatar Oct 30 '24 17:10 JustinGrote

I have created a temporary solution . It involves 2 launch configurations. A powershell function called D03_FacilitateDebug and a procedure explaining how to use them. Because that all takes quit some lines I will add them as an attachment solution to debug.txt

jjsmeets avatar Oct 31 '24 19:10 jjsmeets

Forgot to meantion that D03_FacilitateDebug can not directly used inside the job. First you have to convert it to a string and the use that string to dynamicaly define the function (with the same or as done in the next example with a new name and then call that function. So the statements immediately befor the start-treadjob and the first statements inside the job are: he following statements at the start of the thread job:

[String]$f_FunctionNoHeader_Str=${function:D03_FacilitateDebug}.toString()

[ThreadJob.ThreadJob]$Job1 = start-threadjob -ScriptBlock {
    write-output "JOB: FIRST LINE"
    # bring the functions definition (as string) to this scope
    # define the function with a new name in this scope
    ${function:J03_FacilitateDebug}=$using:f_FunctionNoHeader_Str
    J03_FacilitateDebug -p_TypeOfScript "JOB"

jjsmeets avatar Oct 31 '24 20:10 jjsmeets