vscode icon indicating copy to clipboard operation
vscode copied to clipboard

Limit callstack walking for stop-all debug adapters

Open jacdavis opened this issue 10 years ago • 8 comments

From earlier conversation with Andre

We’ve run into a limitation with the threading support in vscode for the C++ and C# debugging efforts that the diagnostics team is working on. Specifically, the current callstack window will only walk a thread if a stopped event for that thread has been sent. This makes sense as it appears the design is currently optimized for the stop one thread model (where only the thread that hit a bp or experienced another stopping event actually stops).

However, both of these engines (C++ and C#) operate in the stop all mode where a single stopping event implies that all threads (or runtime in the case of C#) are stopped.

While we could work around this by sending a stopped event for all threads in the process, the end result is vscode will ask us to walk the callstack for all threads in the process at each stopping event. Callstack walking has been one of the major sources of performance issues in the visual studio debugger on these runtimes, and in that case, we typically only walk the stack of a single thread, so we feel this will wind up being an issue with the vscode integrated debuggers as well.

What we would like to propose would be to allow a debug adapter to enable stop all mode so that stopped events for the other threads is implied and limiting the callstack request coming from the ui to only the threads that actually have their callstacks open in the thread’s window or whose frames are requested by debugger service in the ui.

jacdavis avatar Mar 02 '16 22:03 jacdavis

@jacdavis instead of introducing a mode we could add some attribute to the stopped event that lets the UI know that all threads are stopped (or a missing threadId attribute in the stopped event could imply this).

Limiting "callstack walking" could be done with this approach:

  • Initially no thread is expanded on the first stop event (or only a single thread mentioned in the event is expanded).
  • Expanding a thread by the user will request the callstack for it.
  • Continuing will collapse all threads (but we would remember what threads were expanded).
  • On the next stop, we would expand the threads that were expanded before.
  • If user collapses a thread, no callstack will be requested on next stop.

CC @isidorn

weinand avatar Mar 02 '16 22:03 weinand

That proposal sounds great.

jacdavis avatar Mar 02 '16 23:03 jacdavis

@weinand, I was thinking about this last night and I think we probably want to use the flag model and keep the threadid since we still want the ui to open the documents and set the current frame to the thread that received the stopping event. Otherwise, the UI won't know where to take the user.

jacdavis avatar Mar 03 '16 17:03 jacdavis

@isidorn the threadId is already spec'ed as optional (but it is not spec'ed what happens if it is missing). So the DA can decide to not set it which will result in the UI using the strategy sketched above. If the DA decides to set the threadId, the UI will user the current behaviour.

weinand avatar Mar 03 '16 17:03 weinand

We talked with Chris and Erik a couple of days ago, and we have some resources to fix this. Ed Munoz is available, so hopefully he can contribute a fix in the next week or so, if you have some time to code review.

delmyers avatar Mar 10 '16 00:03 delmyers

Sounds good to me. However, for the next two weeks we are in endgame mode for build and are not adding new feature, we are mostly focussed on testing / fixing. I see this is assigned to backlog, so I assume this is post build - if yes, then I suggest we also do the PR post build.

isidorn avatar Mar 10 '16 07:03 isidorn

@isidorn, as agreed with @egamma, we'll have a PR ready by Monday.

@weinand, the workflow you proposed above makes sense except for the fact it seems to assume that in stop-all mode we don't care what thread sent the stop event. As @jacdavis pointed out, we would still want the debug adapter to send the threadId which caused the stop event so that the user can see in the UI which thread issued it (by opening that thread, just like it does now). In order to accomplish this, we could have the debug adapter send a flag in the stop event to signal the fact that all threads have stopped, as well as including the threadId.

Please let me know if you have concerns about this approach.

edumunoz avatar Mar 10 '16 18:03 edumunoz

@edumunoz Your approach is correct. I've added a boolean attribute allThreadsStoppedto the StoppedEvent and I've updated the node modules and VS Code.

/** If allThreadsStopped is true, a debug adapter can announce that all threads have stopped.
 *  The client should use this information to enable that all threads can be expanded to access their stacktraces.
 *  If the attribute is missing or false, only the thread with the given threadId can be expanded.
 **/
allThreadsStopped?: boolean;

weinand avatar Mar 11 '16 14:03 weinand