debug the last sentence of a program - eclipse

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.

Related

forcing matlab not to pause on warnings

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

step out and continue in MATLAB debugging

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.

Step to cursor/line eclipse debugger

Is there a possibility to step to any following line while debugging in eclipse?
It will help debug situations when I have a breakpoint at method beginning, I check something there, and below there is a for loop that i want to step through fast to see all changes it made at once.
Currently in the above scenario I put a breakpoint below the for-loop, hit F8, remove the breakpoint after execution stops which is pretty cumbersome.
Is there a better method of doing above?
Put break point at start of function.
Check XYZ. Come up to for loop.
Put your cursor after for loop.
Press CTRL + R.
HURRAY!!!!! I skiped for loop in debug.

How to inspect a variable in XCODE?

Is there any command using which we can inspect a object in command line while app is running in DEBUG mode. I do not want to put description message in the code.
Try these resources. one two
(gdb) p varName
Yes sure. If you are debuging, breakpoints are automatically set to on. Just set a breakpoint to the line in which the variable is. The program stops as soon it reaches the line with the breakpoint. Just hold the cursor over the variable and all important data is displayed. I do it also that way all the time. ;-)

How can I set the current line of execution in the eclipse java debugger?

I want to force the current execution line to a specific line in the same function, possibly skipping intermediate lines. All my old school debuggers had this feature, but I can't find it in eclipse. Is there a way to do it without changing code?
The first two answers seem to miss the topic, unless it is me not understanding the question.
My understanding, a feature I searched myself, is that you want to skip a number of lines (when stepping in code) and set the program counter (to take assembly vocabulary) to the given line. It might be interesting to skip some costly object creation, see some error situations, etc. I used to do that in Visual Studio (C or C++ code).
I haven't found that in Eclipse, nor in NetBean. It might be a limitation of JVM, or an enforcement of some policy...
The Run to line command execute, of course, all lines between the current execution position and the designated one.
I too have long sought this feature, and "Run to line" is not the same thing.
This may well be a limitation of the JVM. Java does not implement goto, though it does have jump statements, like break and continue. Those are at the block level however. If this is a JVM limitation, my guess is that it is more likely due to the security architecture. Tight control of the program counter is debilitating for interlopers, like viruses -- and sadly debuggers.
I think that is not possible in Java. The only feature that allows you to "step back" is using "drop to frame", which takes you back to the first instruction of the current frame. At least I haven't seen any debugger with this specific functionality, but I haven't been able to find on the net why is it so...
I know the debugger in Visual C allows to change to pointer. I will keep on searching, maybe at least we will know why is like this, but it seems to be some kind of design limitation.
Feature request saying it is not possible
In https://bugs.eclipse.org/bugs/show_bug.cgi?id=287795 (credits to Amitd) Darin Wright says it is a limitation of the underlying Java debugger:
Currently, this is not possible with the Java debugger as the native debug interface does not provide the ability to move/set the program counter arbitrarily.
C / C++
CDT supports it however (tested on Neon, Ubuntu 14.04). Right click on the line you want to go to, and select either:
"Move to line": jump to line and break there
"Resume at line": jump to line and continue execution from there
This also serves as further evidence that there is an underlying Java limitation, as Java tends to be more feature rich in Eclipse, and those menu entries are not present in Java next to "Run to line" (which does not skip execution of lines).
This test program prints 0 if you jump the line i = 1:
#include <stdio.h>
int main(void) {
int i;
i = 0; /* Break here. */
i = 1;
printf("%d\n", i); /* Jump to here. */
}
"Run to line" appears to need the program to be running and in a paused state to use. The other option is to set a breakpoint for that line when running in debug-mode.
Double-click far-left vertical bar in the source pane on the same line to add a breakpoint; or,
Select the line and go to Run > Toggle Breakpoint.
At least, this is in Eclipse 3.3.2.