I want to have a single line of code with an if
and the result on the same line. Example
if(_count > 0) return;
If I add a breakpoint on the line, it is set on the if(_count > 0)
:
but what I want is to have the breakpoint on the return;
like so:
Is this doable?
NOTE: The closest question I could find on SO was this (which is not the same thing).
To set breakpoints, type "break [filename]:[linenumber]". For example, if you wanted to set a breakpoint at line 55 of main. cpp, you would type "break main.
Conditional breakpoints allow you to break inside a code block when a defined expression evaluates to true. Conditional breakpoints highlight as orange instead of blue. Add a conditional breakpoint by right clicking a line number, selecting Add Conditional Breakpoint , and entering an expression.
Set breakpoints in source code To set a breakpoint in source code: Click in the far left margin next to a line of code. You can also select the line and press F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert breakpoint. The breakpoint appears as a red dot in the left margin.
It's easy to set a breakpoint in Python code to i.e. inspect the contents of variables at a given line. Add import pdb; pdb. set_trace() at the corresponding line in the Python code and execute it. The execution will stop at the breakpoint.
Just click on a part of the line and press F9. This will set breakpoint in the middle of the line.
EDIT
mareko posted a 3rd option that seems to work just fine and is much easier than messing around with all this line-and-character stuff. I'm going to leave this answer for completeness, but mareko's is much more practical in general.
Yes, but unfortunately, there is no drag-and-drop or anything like that. You have 2 options:
OPTION 1
Move your return to a new line:
obviously, you can leave it like that, but if you want to keep the return
on the same line as the if
, you can simply delete the new line and the whitespace between the if
and the return
-- the breakpoint should "stick" to the return
as you move it around.
This is probably the easier way to do it unless you are currently debugging code that does not have edit-and-continue for whatever reason. In that case, you'll need option 2...
OPTION 2
Alternately, you can place the cursor just before the r in 'return' and then look in your status bar to see which character ("Ch") you are on. In my case, I'm on 20
now right click on the breakpoint and choose "Location..."
In the dialog box that pops up, set Character:
to whatever the status bar was (20 in our example).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With