I am using CLion to debug C programs, however I keep finding myself in the situation of needing to set all lines as breakpoints. Currently the only way I can set all lines as breakpoints is by manually marking each line as a breakpoint, one line at a time. I looked for alternative ways to set lines as breakpoints and the only thing i found was that I could use keyboard shortcuts to toggle breakpoints and I could view all breakpoints. I also tried highlighting all lines in the file and then toggling breakpoints, but it would only toggle breakpoints for a single line - the line selected right before highlighting all lines in the file.
Is there or is there not currently any way to set all lines as breakpoints in one go in CLion?
Also, I considered asking this on superuser.com, however there were ~200x more questions (13 vs 3275) about CLion on StackOverflow so I asked it here instead.
Setting all lines as breakpoints would be the same as stepping through a program. So set a breakpoint at the beginning of main and step through.
Related
I have a question about how does the breakpoint work in text editor. That is when you add a breakpoint, and add/delete new lines above, the breakpoint will follow the line.
What is the algorithm to do this things? And for VSC, where is these code to do so, or can I use this function in my plugin to track some lines?
Similar questions: One, Two. But this is not what I am looking for.
Similar questions, but said options are diabled: Three, Four, Five.
Situation: I want to identify the line where the value of the variable ApplianceState changes to the value normal. ApplianceState is an enum type and can have one of 4 different values. The project I am working on is quite huge and looking for it line-by-line could take days.
Question: Is there a way I can set a watch so that visual studio breaks at the line where the value of ApplianceState changes to normal?
I know I can set a conditional breakpoint, but that would mean I have to set a break point on certain line, and I don't want to do that.
Also, I have enabled native code debugging and the menu item New Data Breakpoint, in menu Debug -> New Breakpoint, is disabled (greyed out). So, I can't select it.
Does anyone know if there is a way or plugin that allows you to create a trailing breakpoint while debugging. For example I want to set a breakpoint on some class and then as I step to the next line and my breakpoint gets updated to that line. Then step to the next line and my breakpoint gets updated to that line, etc... This would be really useful when diving deep into a class hierarchy and being able to start debugging again at the same point where I stopped.
Just toggle the breakpoint whenever you want it, since you're stepping through the code anyway.
I don't see a lot of value in this, but the F9 (for toggling breakpoint) and F10 (for stepping to the next line) keys are right next to one another.
To debug, just:
Set the breakpoint on the first line of code you want to hit.
When the breakpoint hits for the first time, use F9 to remove the breakpoint (if desired).
Press F10/F11 to step to (or into) the next line.
I don't see much value when you keep moving the breakpoint, unless you keep breakpoints there along the hierarchy.
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.
Whenever i set a breakpoint in Xcode, using the gutter, my cursor jumps to a random line of code, typically, 10-20 lines above the breakpoint. Why is it doing this? It is very annoying...
Thanks.
This typically happens when you turn on various optimizations in your debug build. Debug builds should have no optimization. I have a list of possible causes here. They reduce to making sure:
"Strip Debug Symbols During Copy" is unchecked.
"Generate Debug Symbols" is checked.
"Optimization Level" is set to "None [-O0]".
"Use Separate Strip" is unchecked.
"Additional Strip Flags" has nothing set (I don’t think this matters if strip isn't run).
"Unroll Loops" is unchecked
None of the individual files have optimization-related (like -funroll_loops) flags attached.
More detail is provided in my post.
AFAIK it's jumping cause of compiler optimizations (cursor position follows relative code instruction) in binary. Try building your project without optimizations and try debugging again.
Since i'm not a guru at this yet. I may be wrong.
I tried the debugger configuration mentioned above and still get the jumping effect. What I have found works is opening up all my collapsed code (methods, code blocks, and comment blocks) and the problem of the jumping cursor on setting breakpoints goes away. The shortcut to open collapsed code is ctrl + cmd + down arrow. Unfortunately, the comment blocks you have to do one at a time. I think this is a pain and almost would rather just deal with the jumping of the breakpoints than opening up my collapsed code.