How to output "stopped" events in Visual Studio Code debugger - debugging

I am writing my own debugger in VS code for a custom language. Everything works fine, when I click "step over" my program is being debugged correctly, but I cannot see anything in the editor. I think the problem is the "stoppedOnStep" event, I followed the tutorial here: https://code.visualstudio.com/api/extension-guides/debugger-extension but there is no way to send line number or file name in the "stopped" events.
Here is the event in the code example: this.sendEvent(new StoppedEvent('step', MockDebugSession.THREAD_ID)); and as you can see, no info on file name of line number, so I have no idea how that part of the debugger works. How does the debugger client know on which line is the program stopped? Is there some secret getLine() method that reads the line number from the runtime?

Turns out the answer is in the stack trace. After the stopOnStep event (or any other event), the editor sends a stack trace request to the debugger, and the last entry is the current line of the execution.

Related

Hooking message 0x202 in machine code and inspecting the associated window procedure?

I'm trying to figure out what my debugger does when I hit the pause button, so I decided to hook the WM_LBUTTONUP message (by inserting my own code after PeekMessageW and hitting an int3 if the message is equal to 0x202) so that I can see what commands run after that and how it differs from other messages/no message.
Unfortunately there appears to be no significant change in the code path, as it appears to just run "the message loop" either way and I can't find out how to get to where "LRESULT CALLBACK WindowProcedure()" would normally be if I were looking at the code in C/C++. How do I get to that portion of the code in my debugger?

How can I see which line a program is using?

I want to see which line my program is using. For example, the program is on line 231, but I don't know that. Is there a way to do this?
While running in debug mode from Visual Studio you can:
Set a breakpoint. The debugger will kick in and pause execution on
that line.
Press the "Pause" button on the VS toolbar. Program
execution will immediately pause and the debugger will show you what
line its on.
Write code involving System.Diagnostics.Debugger (such as Debugger.Break();) where you beed the debugger to pause execution. This method has the added bonus of not relying on Visual Studio to be the debugger - if you're one of those weird-os. ;-)
Tools->Options->Text Editor->C# and the check line numbers.
Then set a breakpoint.
Only thing that comes to mind is for you to put a comment at the end of each line with the line number, then look at the comment as you step through. But that would only work in debug mode and only after hitting a breakpoint.
One major problem trying this in regular mode, running as normal, is that C# does not run. It compiles into byte code, and there is not a one-to-one correlation between C# lines and IL lines. So I'm afraid in that sense, this cannot be done.

Is there any way to see which line of code is being executed, without Breaking execution?

Long story short, I am debugging a big application which I didn't write. It is throwing an error when it runs on the server on which it is supposed to be run, so I am testing on my own machine with the debugger attached to see what happens.
It has thousands of lines of code, and has been running for a couple of hours now. I want to know which line of code is currently executing, so I can get a rough idea of how long is left, but I don't want to Break All as the code is...rickety.
Short of firing watchpoints all over the place in a spray and pray fashion, is there a non-invasive way to see which line of code is executing right now?
Thanks
Process Explorer can show the currently executing line and call stack in the process.
Right-click a process, click Properties, and then click the Threads tab.

Avoid starting debugging from the beginning

Is it possible to set a starting point for the debugger so that every debugging session
will start immediately from that point (instead of starting from the beginning of the code)?
Or to express it differently:
Isn't it possible to somehow store everything until the breakpoint so that next time the debugger could just instantly resume to that specific breakpoint (instead of starting from the beginning of the code and pausing at the breakpoint)?. Is there any debugger that can do this?
I am using Microsoft Visual Studio Express 2012.
Thank you.
Use a Debugger in visual studio.
In your code, click on the line number, you will see a dot on the line.
When you run the program, it will 'pause' at the line you specify, you can then walk through your program line by line from there
You can use a breakpoint at a line that you want to inspect.
You have a description how to do it here.
You could attach a debugger to a running process, but i'm afraid that it will be on a random place of execution. You could make a wait for a key or button press in your code and attach to your program before continuing.
No. It would have to run the code up to the point you want to get all the variables etc in the right state. If you just set a breakpoint where you're interested from and hit F5 it should get there quickly enough.
If it doesn't get there quickly enough, jot down the variables used and make some unit tests round the troublesome functions instead. That will skip the 10 minutes.

pausing execution javascript in code not in google chrome debugger

I am writing a Google Chrome extension. One of my content scripts has a little bug that I can't find and the Google Chrome debugger appears to be useless for this purpose. The code stops on an Uncaught typeError: Cannot set property 'value' of null. I can see this by opening the debugger and viewing the console after the code fails. But my content script does not appear in the list of scripts shown in the debugger at this point. There are a lot of scripts shown there, including a big block of scripts in light blue. But none named "profile.js" which is my content script.
I tried "location.reload(); but it simply returns "undefined." I'd love to step thru this code and find the problem but I can't figure out how to do it. I've set alerts to try to track the problem but once I click on the alert, the script continues with no opportunity to invoke the debugger. Based on the result of the alert experiment, it appears the code is failing at the very end. I presume the code is finished by the time the error is caught and the script is no longer available to the debugger.
I tried adding this line to the script: "debugger;" to try and force the debugger to open but there is no change whatever to the execution of the code. It fails as usual and as usual I can open the debugger, find the console message and the big list of scripts that does not include mine.
How can I pause execution of the code using a line in the code itself? I just want to stop execution of the code at the beginning, invoke the debugger, set up some breakpoints, resume execution and monitor some variables. That seems like a pretty simple and do-able request.
Any ideas?

Resources