Been trying to stop the cmd window from vanishing right after I execute a program.
it vanishes without showing me the result.
The only method that worked for me was to type system("pause") but I realized its wrong.
what can I do?
b.t.w I'm coding CPP right now (was coding c before).
If you want to stop you program you can use getch() before the end of main func. Getch() reads one character after which the program moves on. I don’t know how correct this method is because I do not use windows myself, but it’s very common.
Related
I'm having a problem with debugging Fortran code within emacs using gdb.
Gdb starts up fine and the program loads OK and stops on the first breakpoint, which I set at the beginning main. Then when I type n to go to the next line, the program proceeds to run all the way through (as if I typed c), instead of going to the next line. To get around this, I set another breakpoint further down. After hitting c, (at the first breakpoint in main) the code skips to and stops at the latter breakpoint (which is what I want).
However, at this point, I can no longer enter gdb commands, as the source code has moved to the top window, and the output to the bottom window (whereas normally all the gdb input commands and program output occur in the top window, and the source code being traversed through on the bottom). So now at this point, when I enter gdb commands, it becomes part of the source code and I cannot navigate through it with n and c and such - instead the code has a bunch of n's an c's in it!
I'm running Fedora 18, and GNU Emacs 24.3.1. Also, to run gdb in emacs, it insists I use the switch -i=mi. After I hit M-x gdb, the line at the bottom pops up as: Run gdb (like this): gdb -i=mi .... I tried playing around with the switches, such as -annotate=3 to no avail.
If I understand correctly, you only have two windows open within emacs, and what has happened is that the output and source code buffers have replaced the gdb command buffer.
You can switch back to the gdb command buffer with C-x b *gud-programname* RET, where programname is the name of the program you are debugging. You might find it helpful to create a new window and switch to the gdb command buffer in that.
This happens because the gdb mode isn't clever enough to keep the command window on top. You can use M-x gdb-many-windows which improves on this a bit.
These two questions may also be helpful.
I am debugging a piece of code on visual studio and I forgot to note down the values I have kept a watch on. Can I go to previous line without rerunning the entire code?
There are similar questions asked on SO but in my case i haven't run through any error or exception. The code is running normally.
After pausing on a break point, right click on the line you want to "go back" to. From the menu that pops up, select "set next statement".
This will adjust the instruction pointer to continue from the specified line of code, but it will not roll back any variables or memory addresses to the values they were at before that line of code was originally executed.
It sounds like what you want to do is rewind / replay your code rather than just move to a specific line. You can move to a specific line, you can just right click and choose set next statement. Unfortunately, this won't rewind the state of the program to some past point (beyond setting the stack and doing a bit of unwinding).
To rewind/replay you need to be a bit trickier. Some options are: -
VMWare replay which will allow you to record and then go back to a certain point in time.
Intellitrace. I haven't tried it, but it allows you to replay to a point.
Which is a bit heavyweight and wont help you right now.
You can use the mouse to drag the yellow arrow pointing to the "next statement to be executed." This actually changes which statement will be executed next. It's not guaranteed to work, but as long as the code is not too complex, it could.
This is my first time on this amazing forum. I am also very new to vba (3 weeks).
I have 2 macros: CallerMac, WorkerMac. These are in separate modules within the "Modules" node of my VBAProject.
In its code, CallerMac imports a .bas file (which has the WorkerMac code) and executes it through a " Application.Run"
When the user is handed this code, they will run "CallerMac" (whose code wont change much) while the code imports the "WorkerMac" (likely to change often)
How can I, for debugging purposes, "F8"/Step into the copied code (WorkerMac) during execution?
Please let me know how I can rephrase my question if it doesn't say much to you or if I should have searched for it differently (I did a lot of searching before posting this code)
Many thanks.
You can place a breakpoint at the beginning of "WorkerMac" as you step through "CallerMac", and then use F8 to continue running "WorkerMac" in step mode.
You can add breakpoints by right clicking on a line that is an executable statement and going to Toggle->Breakpoint, or by clicking on the bar on the left next to the code. It should show a red circle in the bar and highlight the line in red.
I know about basic features of visual studio debugging. F10, F11, Shift+F11, Ctrl+F10.
If I am inside a for loop is there a way of stopping right after the loop is completed?
Right now the way I am doing it is to manually go to the location after the loop and press Ctrl+F10. Is there a better way of doing this?
There is no dedicated "Step Out of Loop" command in Visual Studio. "Step Out" (Shift+F11) works only for functions. There are only two options that I can think of:
Like Brian suggests, there is Run to Cursor, which has been there at least since VC++ 6. This is what you're already getting with the Ctrl+F10 keyboard shortcut. I use this literally all the time while debugging; it's an extremely useful tool. I don't really understand why you think this is a lousy way of doing it, or why you think there should be a "better" way.
You could set a simple breakpoint on the line of code immediately following the loop. This is relatively simple if you use the keyboard shortcut F9. But you still have to navigate to the appropriate line of code, so you might as well use Run to Cursor.
If you're working in a C-derived language, your loops probably conclude with a }. So you could use the Ctrl+] keyboard shortcut to move to the matching brace in the source file if your caret is at the loop's opening brace. That might make navigation easier. It certainly can help avoid moving your hands over to the mouse, killing precious seconds.
* Note that keyboard combinations are subject to change, depending on how you have configured your Visual Studio environment.
I just found out that if you hover with your cursor at beginning of the desired line, VS automatically blends in a little play symbol. When you click on it, debugger jumps to this point.
Perhaps you would like to use a breakpoint, which can be used to trigger the debugger once your program has reached a specific line. You can set one by clicking on the left side of the code line, where errors and arrows usually show up during debugging. Hope this helps!
Simple way is to put a break statement in the for loop and add a condition. This will allow you to test the loop while debugging.
Is there a way in which I can debug my compiled Matlab components, using native Matlab debugger, like Visual Studio "Attach to process" option, or something like that?
I mean EXE stand-alone files, DLLs, COM in-process servers or .NET components.
You can't debug them in the sense of being able to step through the MATLAB code line by line, as you can with MATLAB's own debugger prior to compilation. One of the steps that the MATLAB deployment products take is to encrypt the MATLAB code (so you can preserve your IP when distributing the deployed component). The ability to step through the code in a debugger after deployment would defeat the purpose of that.
I experimented with using something like :
try
catch ME
waitbar(0,ME.message)
end
This was quite an effective and generic solution.
you may want to break down the code into multiple parts and debug each to save compiling time.
good luck,
dan
You can follow the instructions to debug:
Debugging:
Using the Debugging Tool will let you stop your program in mid-execution to examine the contents of variables and other things which can help you find mistakes in your program. M-file programs are stopped at "breakpoints". To create a breakpoint, simply press F12 and a red dot will appear next to the line where your cursor is. You can also click on the dash next to the line number on the left side of the M-file window to achieve the same result.
Then press F5 or Debug->Run from the menu to run the program. It will stop at the breakpoint with a green arrow next to it. You can then examine the contents of variables in the workspace, step, continue or stop your program using the Debug menu. To examine contents of a variable, simply type its name into the workspace, but be warned: you can only look at the values of variables in the file you stop in, so this means that you'll probably need multiple breakpoints to find the source of your problem. There are several different ways you can move through the program from a breakpoint. One way is to go through the whole program, line by line, entering every function that is called. This is effective if you don't know where the problem is. There's also a way to simply step through the function you're currently stopped in, one line at a time, and instead of going through the child functions line by line MATLAB will simply give you the results of those functions.
Finally, note that you cannot set a breakpoint until you save the M-file. If you change something, you must save before the breakpoint "notices" your changes. This situation is depicted in MATLAB by changing the dots from red to gray. Sometimes, you'll save but the dots will still be gray; this occurs when you have more than one breakpoint in multiple files. To get around this (which is really annoying), you have to keep going to "exit debug mode" until it turns gray. Once you're completely out of debug mode, your file will save and you'll be ready to start another round of debugging. Using comments to help you debug code. you want to test the effects of leaving out certain lines of code (to see, for example, if the program still returns Inf if you take them out), you can comment out the code. To do this, highlight it and then go to:
Text -> Comment
Or press CTRL+R. This will simply put a '%' in front of every line; if the line is already commented out it will put another '%' there so when you uncomment them the pattern of comment lines will not change. Commented lines will be ignored by the compiler, so the effect will be that the program is run without them.
To uncomment a line go to
Text -> Uncomment
Or press CTRL+T.
Another use of commenting is to test the difference between two different possible sets of code to do something (for example, you may want to test the effect of using ODE113 as opposed to ODE45 to solve a differential equation, so you'd have one line calling each). You can test the difference by commenting one out and running the program, then uncommenting that one and commenting the other one out, and calling the program again.
How to escape infinite loops?
MATLAB can't directly tell you you have an infinite loop, it does attempt to give you some hints. The first comes when you terminate the program. Terminate it by pressing CTRL+C and MATLAB will give you a message telling you exactly what line you stopped on. If your program is running a long time, it is likely the line you stopped in is in the middle of an infinite loop. sometimes MATLAB won't even let you return to the main window to press CTRL-C. In this case you probably have to kill the whole MATLAB process. After this, add a "pause (0.001)" or a similarly small value in the loop you suspect to be the infinite one. Whenever MATLAB passes this instruction you will be able to interact with MATLAB for a (very) short time, e.g. go to the main window and press CTRL-C with MATLAB being able to respond to your command.