I was getting tired of hitting the F10 every step to debug the programs. Are there any program can automate the visual studio to run each debugging step in a consistent frequency? say, 3 seconds for each step?
Regards,
Sam
You can easily do that with a simple script in Autohotkey.
Download it from here: http://www.autohotkey.com/
Install Autohotkey.
Run it.
Find the green "H" icon in the task bar (bottom right).
Right click the icon and select Edit script.
And copy paste this script below.
^!y::
InputBox, input1, How many F10 strokes you want?, , , 250, 100
InputBox, input2, How many seconds between each F10 stroke?, , , 250, 100
if ErrorLevel <> 0
{
MsgBox, CANCEL was pressed.
}
else
{
loop, %input1%
{
Sleep, (input2 * 1000)
Send {F10}
}
MsgBox, "Your F10 script has Ended"
}
return
Then reload (again by right clicking the green "H" icon in task bar).
Press Control+Alt+y to try out the above script.
Sitting there repeatedly hitting F10 can be annoying, but you probably just need to make more use of the inbuilt debugging features.
set a breakpoint at a targetted location and hit F5 to run the program, it will stop when it hits the breakpoint
use F11 to step in to a function
use Shift-F11 to step out of a function
use the breakpoints window (Debug->Windows->Breakpoints) to get a complete list of all the bp's and you can easily enable/disable any of them (or set any of their other options)
use the Exceptions window (Debug->Exceptions) to select exceptions that you want to break on when they are first thrown
familiarize yourself with the options available to breakpoints (right-click on the bp itself to get these)
hit count: specify how many times code should go past the breakpoint before it stops
condition: super useful (i use it all the time), you can use almost any expression in there, including checking the value of inscope variables
when hit: you can run a macro when the breakpoint is hit
filter: to restrict which running thread can break on that breakpoint
Related
I know I can comment the code but would be even better if there is a shortcut to skip execution of code between two breakpoints.
VS has a feature 'set next statement' which moves the program counter to the to that location and continues execution from there (skipping anything in between). You can read more about it at: https://learn.microsoft.com/en-us/visualstudio/debugger/navigating-through-code-with-the-debugger?view=vs-2017#BKMK_Set_the_next_statement_to_execute. The easiest way to use it is to either use the context menu item "Set Next Statement" (right click on where you want to set it) or hold down the ctrl key which changes the green "Run to click" editor glyphs into yellow "Set next statement" glyphs and just click on where you want to set it.
Set next statement is a great tool but it's really dangerous as a debugging tool. You're using the debugger to execute code in a way which would never happen normally. The results of which could cause crashes or other failures easily. It's real easy to do things like skipping over the initialization of a variable that's later used and will now cause an exception/crash.
It can be used in JS, .NET and native.
I would like to add two breakpoints on the same line in IntelliJ: one always logs a message, and the other suspends the program if a certain condition is true.
Is this somehow possible to do in IntelliJ?
There's no way to have two breakpoints on the same line currently.
A workaround - log and check inside breakpoint condition:
here we log depth on every hit, but stop only if depth % 10 == 0
Yes, it's possible.
Right click on breakpoint and then click More, or by shortcut: Ctrl + Shift + F8 which opens Breakpoints dialog where you need to set up following options:
Condition
Evaluate and log
In PyCharm debugging mode, is there way to let it stop right after it hits an error but not exit and highlight the offending line? The analogous feature I have in mind is "dbstop if error" of Matlab.
Yes, there is. Under Run, if you hit View Breakpoints (Ctrl + Shift + F8 on Windows) there's a checkbox where you can create an exception breakpoint for any exception.
The given answer was confusing to me. To do this you do not need to go to preferences, what you need to go is to break points menu bar (which is not in preferences for some reason). So:
Go to break point by pressing Command + shift + fn + F8 (Ctrl + Shift + F8 on Windows) or go to the breakpoints you have at the bottom (see picture 1). This opens the break point menu (see picture 2).
Then click enabled (for me suspend was already on so I only needed to click enabled). That's it.
Pic 1:
Pic 2:
Note: the reason this feature is useful is because after running an execution it halts with exactly the program state it caused it to err. For me I have stochastic code due to machine learning and reproducing the error exactly is annoying. I'd rather just see what cased the error, inspect the program state, stack etc and just fix it. There is even a little window at the bottom right to run code so I can test it right there while I am fixing it. I can even do control+shift+E to test pieces of code from my actual code (as I right new code).
I am writing a program in VB6.
By mistake many times my code contains an endless loop, inside which there is a message box. For example:
while a>0
msgbox "a is positive"
wend
Then I press the play/run and I realize what has happened. Is there any way to stop the debugging/running of my program?
The only thing that works so far is Ctrl+Alt+Del and end task. But this way the whole visual basic closes and I lose my unsaved data. (please don't comment that I should save my program more often. I know it (now)).
Edit: I found on the internet that maybe esc or ctrl+c or ctrl+break could do the job. The first two do nothing and my laptop doesn't have a break key
Solution: I have the insert key in my laptop. on the key there is also written pause for use along with the Fn key. So I was able to break the application by pressing Ctrl+Fn+Insert (which maybe could be translated in Ctrl+Pause)
edit: link to photo of my keyboard:
ctrl + break will work. If you don't have those keys, use the on screen keyboard.
Start | Run | osk
Then press ctrl + break.
Is there any way to tell the debugger to just continue until the next file is accessed, and/or until the next (developer written) function is accessed, without setting debug points ahead of time? I'm kind of new to VS debugging so all I use right now are f5, f10, and f11.
There is currently no way to do what you are asking. The main ways of telling VS to go until something happens are the following
Hit F5 and VS will go until the next user breakpoint or ,depending on your settings and where it occurs, the next exception is raised
Right click and select "Run to cursor"
Shift-F11 breaks out of the current method
Run to cursor doesn't require an explicit break point but it does require that you know where you want to break next.
You can right-click and select "run to cursor" if you just want to run to a specific line ahead in the execution stream.
Another one is Shift-F11 which finishes the current method and breaks again when you get back to the caller.
Actually, there is a way to set conditional break points.
Click in the left margin on the line where you want to break, as usual. (or F9)
Right-click on the red dot. In the context menu, click on "Condition...."
In the dialog, set your condition, e.g., fileName == "foo"
Hit F5 and go until the conditional break is hit.
Looks like there's not a way to do what I wanted to do