Page 1 of 1

Bug: Debugging nested ('dotsourced') Scripts: Please fix the ignored breakpoints

Posted: Mon May 27, 2019 3:38 am
by Jehoschua
Product: PowerShell Studio 2019 (64 Bit)
Build: v5.6.163
OS: Windows 10 Enterprise (64 Bit)
Build: v10.0.17134.0


Hello

If a PowerShell Script 'dotsources' another Script, we can use "Step into" to debug functions in the 'dotsourced' Script :-)

While debugging the 'dotsourced' Script,
  • we can use "Step into" and "Step over" commands :-)
  • but if we set breakpoints and use "Go (F5)", then the breakpoints usually are ignored :-(
This is strange:
if we use "Step into" and "Step over" to get near to a breakpoint, then f5 sometimes works and stops at the breakpoint.

Thanks a lot, kind regards,
Thomas

Re: Bug: Debugging nested ('dotsourced') Scripts: Please fix the ignored breakpoints

Posted: Mon May 27, 2019 10:22 am
by Alexander Riedel
How exactly are these script dot sourced? Are you using a full path, a relative path, a constructed path from variables?
Please specify.

Re: Bug: Debugging nested ('dotsourced') Scripts: Please fix the ignored breakpoints

Posted: Mon May 27, 2019 12:12 pm
by Jehoschua
Good evening

We assign the Script-Filename with it's full, absolute path to a variable and then 'dotsource' it:

Code: Select all

$AddScript = 'c:\scripts\powershell\lib\tools.ps1'
. $AddScript
Thanks a lot, kind regards,
Thomas

Re: Bug: Debugging nested ('dotsourced') Scripts: Please fix the ignored breakpoints

Posted: Mon May 27, 2019 12:41 pm
by Alexander Riedel
We have a holiday here, so the team is not in. As such there is some guesswork here on my path, just to be clear.
Assuming you actually have the dot sourced files open to set the breakpoints, I would assume that PowerShell Studio only sets breakpoints for files it considers 'associated' with your main script. (That part I need to verify with the team)
Since you are not dot sourcing a path but a variable, PowerShell Studio probably ignores it.
It has no idea what value (or values) $AddScript will have once a script is executed. Breakpoints are set before the script is executed.
So even IF it would by static analysis recognize that you dot source a variable, Set-PSBreakPoint -script $AddScript -line 799
has no meaning whatsoever, since $AddScript is empty at that time.
What you want would require the script to be executed once before it gets debugged to pre-set the variables.

Try just dot sourcing the script directly.

Re: Bug: Debugging nested ('dotsourced') Scripts: Please fix the ignored breakpoints

Posted: Tue May 28, 2019 8:11 am
by davidc
Please try using the Debug with Multiple files command and check the dependent files.
Debug with Multiple Files.png
Debug with Multiple Files.png (31.78 KiB) Viewed 1441 times
Please let us know if this works for you.