While tracing a function in bash, I can return non-zero value (say,1) from by DEBUG trap handler to skip the execution of the next line.
Also, I can return the value 2 to execute a return statement to return out of the function without executing the rest of the function body
However, I would like to be able to step out of the current function, not by `return'ing, but by executing the remainder of the function body in just a single shot (instead of executing it line-by-line till the end of its body).
Is this possible?
Tedious sure, but it seems this can be done with the existing callstack information provided by Bash.
Here's how.
Keep executing your DEBUG trap handler till you reach the next callstack frame, F2, sitting right under the current one, F1, and stop on a line number that is greater than or equal to the BASH_LINENO saved in F2. The '... or equal to' check is required to address recursive calls.
Related
While learning asyncio I was trying this code:
import asyncio
from asyncio.coroutines import coroutine
#coroutine
def coro():
counter: int = 0
while True:
print("Executed" + str(counter))
counter += 1
yield
loop = asyncio.get_event_loop()
loop.run_until_complete(coro())
loop.run_forever()
print("Finished!")
I was expecting the coroutine to be executed only once because it contains a yield and should have returned control to the caller. The output I was expecting was:
Executed 0
Finished!
I was expecting this behaviour because I thought the loop was going to run the coroutine forever once every "frame" returning to the caller after each execution (something like a background thread but in a cooperative way). But instead, it runs the coroutine forever without returning?. Output is the following:
Executed 0
Executed 1
Executed 2
Executed 3
...
Could anyone explain why this happens instead of my expectations?
Cheers.
You have a couple of problems. When you call run_until_complete, it waits for coro to finish before moving on to your run_forever call. As you've defined it, coro never finishes. It contains an infinite loop that does nothing to break out of the loop. You need a break or a return somewhere inside the loop if you want to move on to the next step in your application.
Once you've done that, though, your next call is to run_forever, which, just as its name suggests, will run forever. And in this case it won't have anything to do because you've scheduled nothing else with the event loop.
I was expecting the coroutine to be executed only once because it contains a yield and should have returned control to the caller.
Looking past the fact that your coroutine has no yield, awaiting (or yielding from depending on which syntax you choose to use) does not return control to the caller of run_until_complete or run_forever. It returns control to the event loop so that it can check for anything else that has been awaited and is ready to resume.
I have an instance of a word document running (opened through a New Word.Application). I have populated the document and sent it to print, however, if i then use the Msword.application.quit method as the next statement it cancels the print job
I have put in a do while MsWord.BackgroundPrintingStatus = 1 loop in but this then goes into an infinite loop.
stepping into the code and giving the print job time to run before continuing to the quit command works fine and the MsWord.BackgroundPrintingStatus does return to 0.
Why would a do while loop go into an infinite loop while waiting for the status to change?
OK found a way to do it. put the quit in a do while printingstatus = 0
I'm just discovering the new (to my system) ABAP Debugger Script.
Say this is my program:
* Assume i have the class LCL_SMTH with public methods INCREMENT and REFRESH
DATA: lo_smth TYPE REF TO lcl_smth.
CREATE OBJECT LO_SMTH.
lo_smth->increment( ).
WRITE 'Nothing hapenned'.
Could i get my script to call the REFRESH method after it exits INCREMENT?
I set the script to execute on calling of the INCREMENT method, and it does so. Next I know I have to STEP OUT (F7) -> which I also do - i just don't know how to invoke the REFRESH method.
Debugger script can do exactly what you could do manually. So you can't ... unless you could manually. Since you can jump manually in the debugger, debugger script can as well. So if there is a suitable call to REFRESH somewhere in the code, then you can jump there and back as well.
I just found that such MathLink functions as LinkWrite and LinkRead have something like its own internal CheckAbort that absorbs any aborts, and does not propagate them further.
This can be easily shown with LinkRead:
link = LinkLaunch[First[$CommandLine] <> " -mathlink"];
LinkRead[link];
LinkWrite[link, Unevaluated[Pause[10]]];
{LinkRead[link], Print["!!"]}
After evaluating the above code press Alt+. and you will get the following output:
During evaluation of In[6]:= !!
Out[9]= {ReturnPacket[$Aborted], Null}
As you see the abort was absorbed by LinkRead.
My problem is that it breaks my own flow control of evaluation based on CheckAbort.
Is there a way to intercept aborts absorbed by such functions as LinkRead and LinkWrite?
The way MathLink works, LinkRead blocks if there is nothing to read on the link. If you try to abort at this time, an abort message is passed via MathLink message channel to the other end of the link. If the program on the other end behaves nicely, it will drop whatever it was doing and send a return value (in many cases $Aborted). If you want to propagate the abort to your end of the link, so that you can catch it with CheckAbort, you will need to check the return value and generate another abort, for example:
If[LinkRead[link] == $Aborted, Abort[]]
This works if you know that the other end of the link returns $Aborted in case it is aborted.
I want to debug the whole flow of a (Java) program. I see there are several options for stepping through my program. What is the difference between step into and step over?
Consider the following code with your current instruction pointer (the line that will be executed next, indicated by ->) at the f(x) line in g(), having been called by the g(2) line in main():
public class testprog {
static void f (int x) {
System.out.println ("num is " + (x+0)); // <- STEP INTO
}
static void g (int x) {
-> f(x); //
f(1); // <----------------------------------- STEP OVER
}
public static void main (String args[]) {
g(2);
g(3); // <----------------------------------- STEP OUT OF
}
}
If you were to step into at that point, you will move to the println() line in f(), stepping into the function call.
If you were to step over at that point, you will move to the f(1) line in g(), stepping over the function call.
Another useful feature of debuggers is the step out of or step return. In that case, a step return will basically run you through the current function until you go back up one level. In other words, it will step through f(x) and f(1), then back out to the calling function to end up at g(3) in main().
When debugging lines of code, here are the usual scenarios:
Step Into
A method is about to be invoked, and you want to debug into the code of that method, so the next step is to go into that method and continue debugging step-by-step.
Step Over
A method is about to be invoked, but you're not interested in debugging this particular invocation, so you want the debugger to execute that method completely as one entire step.
Step Return
You're done debugging this method step-by-step, and you just want the debugger to run the entire method until it returns as one entire step.
Resume
You want the debugger to resume "normal" execution instead of step-by-step
Line Breakpoint
You don't care how it got there, but if execution reaches a particular line of code, you want the debugger to temporarily pause execution there so you can decide what to do.
Eclipse has other advanced debugging features, but these are the basic fundamentals.
See also
Free video tutorial: Eclipse and Java: Using the Debugger
IBM/DeveloperWorks/Debugging with the Eclipse Platform
IBM/DeveloperWorks/Learn the essentials of debugging
step into will dig into method calls
step over will just execute the line and go to the next one
Method of Communicating with a Debugger
(Or, how I explain my road trip to my grandmother)
Step Into: "When the next statement to execute reaches a method call, dont execute the method as a whole, but rather, execute the first line of that method and stop"
Step Over: "When the next statement to execute reaches a method call, execute the method as a whole and stop"
Step Out: "Finish off executing the callee's code and stop when execution returns to the caller"
Continue: "Execute up until the next breakpoint"
Here is a great example to practically demonstrate the concepts above:
You can't go through the details of the method by using the step over.
If you want to skip the current line, you can use step over, then you only need to press the F6 for only once to move to the next line.
And if you think there's someting wrong within the method, use F5 to examine the details.
Step Into The next expression on the currently-selected line to be executed is invoked, and execution suspends at the next executable line in the method that is invoked.
Step Over The currently-selected line is executed and suspends on the next executable line.