I am learning scala in my free time. When I was programming in python with Pycharm, Pycharm provides a very handy tool called debug console which, if I set a breakpoint at line L, would store the value of the variables by the time of L, and I can freely explore some operations on those variables.
I know scala has a REPL tool and I am wondering if scala in Intellij IDEA has the similar debug console. I know I can use evaluate expression tool but it is a little difficult to use because
I can't see the previous calculated expression values and I have to retype every time to see the values.
I can't store the result of the expression on one variable and continue using that variable.
Thanks!
If you set a breakpoint on a line (click in left margin to get a red dot) and then Debug rather than Run (bug icon rather than play icon) then IntelliJ will stop at the first breakpoint and show a very comprehensive debugging window. You can evaluate an expression (calculator icon) and create a watch expression which is evaluated each time a breakpoint is hit (watch panel on the right).
Related
I am using emacs for programming, and recently also gdb.
The "locals" window does show local variables but not arguments to a function, which in a way also could be considered local variables. For example, if I have
void foo(char *bar)
{
int n;
....
}
then n is shown in the "locals" but not bar. Of course, I can print bar but it is not automatically updated while I step through the code and I have to print all the time.
Is there a way to add expressions that are shown in a window and constantly updated as I execute the code?
The display command will certainly fulfill your needs:
If you find that you want to print the value of an expression frequently (to see how it changes), you might want to add it to the
automatic display list so that GDB prints its value each time your
program stops.
By example, once that your are in foo body (under gdb), type:
display bar
The interactive command gud-watch will watch the expression at point and display its value in the speedbar. Prefix it with C-u to be able to enter an expression.
See the manual page Watch Expressions for more details.
At the moment there doesn't seem to be a way to display watched expressions in the locals window.
Question: Is there a preferred way to debug functions in matlab?
If I all calculations in a script, then every variable is in the workspace and I can easily query them to find out what's not working right. However, if I use a function, then only my outputs are visible and I can't see what's going wrong. I understand there are ways of getting around this, but thusfar they seem to be more trouble than just making one, long ugly, script. So how do YOU debug functions in matlab? Is there a preferred/efficient way of doing this?
I always make sure to enable "Stop If Error" in the Breakpoints menu and if I want to debug a specific function I set a breakpoint at the first line in that function (or at the point of interest). Note that "clear all", which is common in the beginning of scripts deletes all break points. Use "clear variables" instead.
See MATLAB settings - stop if errors for more info on how to make the Stop If Error persist when you restart Matlab.
I'm using IntelliJ idea Community edition (with Scala) and I'm trying to evaluate an expression. I hit Alt-F8 to open it in debug mode and then switch to 'Code Fragment Mode'. However, I'm allowed to only evaluate variables that already exist in memory, and am not allowed to declare new. When I do so, I get- 'Evaluation of variables is not supported'. Is there a plugin that I can use in debug mode to evaluate arbitrary code?
EDIT: So that it's clear, no worksheets are not what I'm looking for. I want to evaluate expressions using variables existing at runtime.
Have you considered using a Scala Worksheet, which is a kind of editor supported REPL. You can create one in your project, import code from your project, execute it and see the results instantly. It wont let you debug to a piece of code though, if that is your primary intention.
It's an old question, but for now there is a good answer:
https://www.jetbrains.com/help/idea/2016.1/evaluating-expressions.html
TL;DR: During debugging, click on a stack frame, and you'll be able to evaluate expressions in the context of that frame: Run|Evaluate Expression, and you can click "Code Fragment Mode" to enter multi-line stuff. IntelliJ autocomplete features would work properly too!
Using Scala plugin for Eclipse version 2.1 milestone 2, in Eclipse Indigo, if I set a breakpoint on a line that contains an anonymous function, e.g.
myList.map((x: String) => foo(bar(x)))
"the" breakpoint will be hit not only when map is called, but also when the anonymous function is called (it's actually multiple breakpoints, but frustratingly, they only show up as one breakpoint in the breakpoint tab in Eclipse). I think this is a regression, because I seem to remember you used to get multiple breakpoints showing up in this kind of case.
How can I stop Eclipse from treating the anonymous function as part of the same breakpoint?
Breakpoints are line-based, so just add newlines in such a way that it's still syntactically valid, but the lambdas you don't want to hit are now on separate lines. E.g.
myList.map(
(x: String) => foo(bar(x)))
(In my case, I still see an apparently spurious double-hit on the line, but that seems to be a different issue - it's not hitting the lambdas any more.)
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.