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

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST SUBSCRIPTION NUMBERS, LICENSE KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
Jehoschua
Posts: 54
Joined: Fri Jan 29, 2016 6:23 am

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

Post by Jehoschua » Mon May 27, 2019 3:38 am

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

User avatar
Alexander Riedel
Posts: 6999
Joined: Tue May 29, 2007 4:43 pm

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

Post by Alexander Riedel » Mon May 27, 2019 10:22 am

How exactly are these script dot sourced? Are you using a full path, a relative path, a constructed path from variables?
Please specify.
Alexander Riedel
SAPIEN Technologies, Inc.

User avatar
Jehoschua
Posts: 54
Joined: Fri Jan 29, 2016 6:23 am

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

Post by Jehoschua » Mon May 27, 2019 12:12 pm

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

User avatar
Alexander Riedel
Posts: 6999
Joined: Tue May 29, 2007 4:43 pm

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

Post by Alexander Riedel » Mon May 27, 2019 12:41 pm

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.
Alexander Riedel
SAPIEN Technologies, Inc.

User avatar
davidc
Posts: 5913
Joined: Thu Aug 18, 2011 4:56 am

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

Post by davidc » Tue May 28, 2019 8:11 am

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 1188 times
Please let us know if this works for you.
David
SAPIEN Technologies, Inc.