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 LICENSE NUMBERS, ACTIVATION 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.
This topic is 4 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
Jehoschua
Posts: 64
Last visit: Fri Mar 01, 2024 3:24 am

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

Post 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
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

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

Post 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.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
Jehoschua
Posts: 64
Last visit: Fri Mar 01, 2024 3:24 am

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

Post 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
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

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

Post 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.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

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

Post 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 2726 times
Please let us know if this works for you.
David
SAPIEN Technologies, Inc.
This topic is 4 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.