Why is the Node debugger "break on first line" a thing? - node.js

I thought the reason the new VS Code debugger stopped on the 'use strict'; in my file was because of some weird deprecatory behaviour in new versions of Node, or else because my code had some weird error in it.
Then I realised that "break on first line" is a thing, and one that people want. Why on earth is this a thing? I know that my script has a first line, thank you very much. I'd have bigger problems if it didn't. So why does the debugger need to do this?

In launch.json there is a property stopOnEntry which is set to true by default. If you don't want to Node Debugger to "break on first line" set this property to false.

Now a toggle for this exists:
--inspect vs --inspect-brk

The reason "break on first line" is a feature, is so that you can run your application, and have it stop on the first line before continuing.
This allows you to attach a debugger before Node has executed some of the code. This enables you to debug the very first lines of code, set more breakpoints, or step over the lines of code whenever you are ready.
This is actually a pretty common feature in a debugger, especially if you don't necessarily have a way to set breakpoints before you run the code.

Related

MS. VBA Debugging "Run to Cursor" not working

Hello all,
this has me quite baffled as I dont even know how to even search for a solution to this.
Basically the problem is that when I'm debugging, after I stop the code in a breakpoint, the debugger can only go line by line and seems to not be able to "Run" (with F5, just continuing executing the code) or "Run to Cursor" to execute the code until the position the cursor is.
This makes of course very difficult the debugging, especially in cases where you just want to skip over a for-loop with 300000 iterations and not go through it one by one...
I have somehow found a workaround, although not really: I can set a breakpoint at some point down the code and select "Step Out" (Ctrl+Shift+F8) and the program will execute until the next breakpoint. This is far from ideal as I need to be setting and removing the breakpoints instead of just placing the cursor where I wanted the program to go and click Ctrl+F8. This operation is something I probably do hundreds of times while I am debugging and now I just go so much slower.
I wondered if any of you encountered this problem and know how to fix it or change this behaviour?
I should mention that the issue came when I changed my computer for a new one. I'm using Microsoft Visual Basic for Applications 7.1 within MS Excel in Microsoft Office 365

How to step back a line of code with Android Studio debugger

I am new to the debugger. When I step over a line of code, I was wondering how to step back. Now I'm realizing that the code can't be executed backwards? Do I have to restart the activity in debug if I want to step back to old lines?
Also, if you don't mind, what is the force-step-into command?
Don't think that is possible. Android works like all other debuggers, which are more or less waterfalls over the code. You can't really step backwards, but thats where breakpoints come in. Place a break point before the line you wanted to step backward on and rerun your app, it'll keep going until it hits that line.
To explain Force-Step-Into I'm going to explain Step-Into/Over first. Step-Over sees the line you want, and steps over it, stopping at the line in the same file after the function call was made. Step Into on the other hand steps into the function call and stops on the first line of that function call, could be in a new file or a new location. In Android, there are a lot of functions that are considered "Black Boxes" where you don't really care what they do since they most probably don't affect the code (Like the Log.d function). Force Step Into allows you to step into those if you'd want to.
Source: https://www.quora.com/How-would-you-explain-in-one-line-about-Step-over-Step-into-Force-Step-into-and-Step-out-of-Android-studio
Notice that you can set conditional breakpoint, i.e. breakpoint will stop execution only if x == 57 (so you don't have to skip manually all 56 breaks). Very useful. Just set breakpoint, click with right button on it and set your condition.
May be Frames can help to check method() calling stack in debugger window
YES, you can!
According to the Android Dev Summit in 2019, now you can step back while debugging with Android Studio!
Check out the live demonstration.
All you need to do is to press the Drop Frame button in your debug view, and then Resume Program. Then you will automatically get back to the last break-point.
Note: the device should run at least Android 10.
I don't think that is possible, like #OmegaNalphA mention, but you can have a look on the stack trace and see the order your code is executed.
StackTraceElement trace = new Exception().getStackTrace();
Log.d("myapp", trace.toString());

How do you actually do any debugging with node-inspector?

I read about node-inspector as a suggestion for debugging node code.
However I have found no clear instructions on how to use it, and the documentation is awful.
I installed node-inspector and then did
node-inspector --web-port=5858 &
I get a message saying
Visit http://127.0.0.1:5858/?ws=127.0.0.1:5858&port=5858 to start debugging.
which I do.
Now I get a blank console page.
But the docs stop here. What do I do next to actually debug my app?
Click the 'source' tab to see all the files used by your nodejs project. When the debugger starts it stops code execution at the first line automatically without setting any breakpoint, this lets you set more breakpoints if necessary. After setting breakpoints, click on 'Run' or 'Resume execution' button to proceed.
For the first usage you can follow next instruction:
Create new project with only index.js
var a = 0;
setTimeout(function() {
debugger;
console.log(a++);
}, 1000);
Open your preferred shell in project dir and execute node-debug index

strongloop: can not set breakpoint in certain model.js files

I start the debugger with "slc debug" and Chrome starts up. I want to set a breakpoint on line 100 of report.js
I can't do it. Won't let me.
Any ideas why?
In other file such as events.js I can click on the linenumber and the blue breakpoint shows up.
Is the Strongloop node inspector any different from the standard one?
I got this problem too. Try this (sound weird), but its work for me :
type "slc debug"
the chrome will open up, with one new tab
explore to your "report.js" file, set break point at your line (Note : the break point will not show)
open up new tab at same chrome
type in the debug path (same like the one at step 2, or you can see it at your debugger). ex : http://localhost:8080/debug?port=5858
At the new debug tab, the break point will show up.
Hope it help, just sharing what i been through.
thanks.

step without breakpoints in android studio?

I want to get a better idea how a program I have operates, and rather than print the code out and try to see which method calls which method, it'd be easier to just run a debugger that steps through every line.
But manually putting a breakpoint on every line seems a bit laborious.
Is there any option to step through every line of the program as it runs(without manually putting in all the breakpoints)?
So that I could then see, ah MainActivity launches and runs onCreate and I could see it running through the code of onCreate how it then goes to a fragment class's onCreateView method.. and so on.. I want to see who is calling who as it happens and step through.
You don't need to add breakpoints on each line. Just add a breakpoint to the entry point of your application and then simply use the step-in and step-out buttons of the debugger to execute the code line by line.
In order to prevent the debugger from stepping through the code that wasn't written by you, go to File > Settings > Debugger > Stepping and then on the right, click the plus icon with the question mark that says Add Pattern to add the following patterns:
android.*
dalvik.*
com.android.*

Resources