I have encountered a weird situation recently: when I am running my programs, sometimes the execution pauses when it reaches some warning statements (yet, sometimes it doesn't stop in identical situations, and just outputs the warning statement). I cant force the program not to stop. when I click on the small triangle below the "run" or "Breakpoints" in the editor "stop on warning" is sometimes checked, If I remove its tick, it becomes checked again after a while and the program stops on some warnings!
Has anybody encountered similar issue? is there a way to force the program not stop (maybe using some code)
Programmatically, you can use dbstop and dbclear to set and clear break conditions.
In your case, use dbclear if warning.
And see https://www.mathworks.com/help/matlab/ref/dbclear.html
Related
I am working on a project using Eclipse CDT and am encountering what seems to be an infinite loop.
When debugging an application from within Eclipse, I can easily retrieve and examine the call stack when the process terminates abnormally (segfault being the most common one) or when I hit a breakpoint.
If I run into an infinite loop without knowing which statements are looping, a stack trace would give me a rough idea of the functions to look at. How can I tell Eclipse to get me a stack trace of whatever the process is doing right now (in the absence of a breakpoint or segfault)?
My hack for that so far is
killall -SIGSEGV $process_name
(replacing $process_name with the name of the process you are trying to debug). This will cause the process to behave as if it had segfaulted, i.e. stopping it and giving you the call stack of whatever the process was executing at the time.
Is there a cleaner way of achieving the same?
A slightly cleaner way is:
killall -SIGCONT $process_name
This sends a CONT (continue) signal to the process. The primary purpose of this signal is to continue a process after it has been sent a STOP signal. When sent to a process that isn’t stopped, it does nothing.
However, if the process is being debugged in Eclipse (which in turn relies on gdb for debugging), this will stop execution and cause a stack trace to displayed.
Unlike with -SIGSEGV (or other signals that tell the process to dump its core or terminate), you can then hit the Resume button and continue to run your process. The UX is close to what would happen after hitting a breakpoint, except Eclipse will report a different reason for suspending execution.
Note that if you are doing anything that messes with signal processing by your process, this might not work as expected.
No idea if there’s anything that can be triggered from the Eclipse UI, though.
What is the difference between "step out (shift+F11)" and "continue (F)" in MATLAB debugger? When I debug a MATLAB function, both are triggering the cursor to come out of the loop. What is the exact difference between these two?
Continue (dbcont) will cause the program to resume execution and will only stop once it encounters another breakpoint.
Step-Out (dbstep out) will cause the currently executing function to continue and will automatically pause in the calling function regardless of whether you have a breakpoint there or not. Notice that this is referring to stepping out of a function and not a loop.
In your case, I'm assuming you only have a single function (or script) and therefore if you have no manual breakpoints after calling dbcont or dbstep out, they are going to have the same result since they will both just run the rest of the script to completion.
Question: Is there a preferred way to debug functions in matlab?
If I all calculations in a script, then every variable is in the workspace and I can easily query them to find out what's not working right. However, if I use a function, then only my outputs are visible and I can't see what's going wrong. I understand there are ways of getting around this, but thusfar they seem to be more trouble than just making one, long ugly, script. So how do YOU debug functions in matlab? Is there a preferred/efficient way of doing this?
I always make sure to enable "Stop If Error" in the Breakpoints menu and if I want to debug a specific function I set a breakpoint at the first line in that function (or at the point of interest). Note that "clear all", which is common in the beginning of scripts deletes all break points. Use "clear variables" instead.
See MATLAB settings - stop if errors for more info on how to make the Stop If Error persist when you restart Matlab.
I've tried to figure the problem myself, and will probably continue, but due to poor error reporting it's just too time consuming. So, perhaps, if anyone had encountered this problem before, please share.
What happens: after flymake-jshint encounters an error, no matter what the error is, it could be a missing semicolon for example. It will get stuck in an infinite loop. I can C-g the loop, but this is very annoying, and will happen multiple times on the same line, making it absolutely impossible to write anything.
When I then look into the *Messages* buffer, it reveals something like:
missing ; after statement [NNNN times]
i.e Flymake was requested to perform the check many times. The timer interval is set to 2 seconds, but it clearly overdoes, because it will do hundreds of checks in two seconds. Trying to increase the flymake-log-level reveals no additional information.
I have customized these variables:
(flymake-no-changes-timeout 2)
(flymake-start-syntax-check-on-newline nil)
but no more additional customizations.
EDIT:
This seems to be related to auto-complete mode. Disabling this minor mode "solved" the problem, but now I'm getting hundreds of "Invalid face reference: nil [NNNN times]" kinds of messages. sigh
I think, I finally found the problem. It was the highlight-current-line minor mode. Whenever Flymake would detect an error and needed to paint the error location it tried to read the overlay, but got confused by the overlay created by the highlight. I haven't yet gotten to trying to fix it, but simple disabling of the highlight made it at least possible to work.
I have used Eclipse and VS. When I insert a breakpoint and debug the program, it will stop before the breakpoint.
But what if I want to debug the effect of the last sentence of the program? Inserting a meaningless sentence(say print 'pause' in Python) is OK but seems awkward. Is there any alternatives?
In Visual Studio you can put break point on closing bracket in main (or any) method of Program (or any) class (default naming, may vary), then debugger stops just before closing application.
Is there any reason not to use a breakpoint on the last statement, like you said, then manually proceed one step? Depending on the debugger, this can also be automated. In GDB, one can use commands N, where N is the breakpoint number, to set a list of (debugger) commands to be executed immediately after a breakpoint is hit.