Skip to content

Ensure debug adapter request/response sequence numbers tally#14336

Merged
joyceerhl merged 13 commits intomainfrom
dap-sequence-numbers
Oct 17, 2020
Merged

Ensure debug adapter request/response sequence numbers tally#14336
joyceerhl merged 13 commits intomainfrom
dap-sequence-numbers

Conversation

@joyceerhl
Copy link
Copy Markdown

While working on #14269, I found a bug in how we update topMostFrameId in debuggerVariables.ts. VSCode may send multiple stackTrace requests, but we should only update topMostFrameId when we get a response to a request where the startFrame was 0 (since that will retrieve all frames on the stack).

In #14269, this was causing variables to appear undefined since they were being evaluated with respect to the wrong frame. @rchiodo pointed out that we needed to fix this in debugLocationTracker.ts as well, so I created a base class to track the sequence numbers since that code is needed across both debuggerVariables.ts and debugLocationTracker.ts.

I didn't want to move more state being tracked as part of the stackTrace response in debugLocationTracker.ts into the base class, since there seems to be some custom logic there WRT whether we're waiting for a stack trace, but if that is safe and not messy to move into a shared class then I can make that change.

  • Pull request represents a single change (i.e. not fixing disparate/unrelated things in a single PR).
  • Title summarizes what is changing.
  • Has a news entry file (remember to thank yourself!).
  • Appropriate comments and documentation strings in the code.
  • Has sufficient logging.
  • Has telemetry for enhancements.
  • Unit tests & system/integration tests are added/updated.
  • Test plan is updated as appropriate.
  • package-lock.json has been regenerated by running npm install (if dependencies have changed).
  • The wiki is updated with any design decisions/details.


// When a python debugging session is active keep track of the current debug location
export class DebugLocationTracker implements DebugAdapterTracker {
export class DebugLocationTracker extends DebugStackTraceTracker implements DebugAdapterTracker {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need implements DebugAdapterTracker?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because DebugLocationTracker has other custom message handling besides what is handled in the base class, so it still needs to be able to intercept DAP messages via onDidSendMessage and onWillReceiveMessage.

message.request_seq === this.stackFrameRequestSequenceNumber
) {
// This should be the top frame. We need to use this to compute the value of a variable
this.topMostFrameId = message.body.stackFrames[0].id;
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels inconsistent because this state is only needed in debuggerVariables.ts, but here I've made it shared, and the equivalent state for debugLocationTracker.ts still lives in that class and not here.

Wanted people's thoughts on whether I should either

  1. move debugLocationTracker.ts's handling for a stackTrace response here, or
  2. move this function back into debuggerVariables

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vote for 1.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class's job is to track the list of stack frames. That shouldn't be done elsewhere. I'd say you could probably put almost all (if not all) of the code from the DebugLocationTracker here. Isn't the DebuggerVariable class really just a subclass of something that's tracking stack frames?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meaning you'd have this class hierarchy instead:

DebugVariables extends DebugLocationTracker
DebugLocationTracker

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the name / function of this class as I read it #1 makes more sense.

}

public onWillReceiveMessage(message: DebugProtocol.Request) {
if (message.type === 'request' && message.command === 'stackTrace' && message.arguments.startFrame === 0) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the specification this is not quite right I believe. Looks like startFrame === 0 or startFrame not being defined means to fetch everything. I think this might not handle the undefined case.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I missed that when looking at the spec. Thank you!

private sessionEndedEmitter: EventEmitter<DebugLocationTracker> = new EventEmitter<DebugLocationTracker>();

constructor(private _sessionId: string) {
constructor(private _sessionId: string | undefined) {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit of a cheat to get the class inheritance to work @rchiodo, because in debuggerVariables we may not have an active session at the time that the constructor is called. debuggerVariables doesn't need this to work anyway, this sessionId is used in the debugLocationTrackerFactory, but just to flag it here in case folks think this looks funny.

@codecov-io
Copy link
Copy Markdown

codecov-io commented Oct 15, 2020

Codecov Report

Merging #14336 into main will decrease coverage by 0.00%.
The diff coverage is 83.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #14336      +/-   ##
==========================================
- Coverage   59.40%   59.40%   -0.01%     
==========================================
  Files         716      716              
  Lines       39999    40000       +1     
  Branches     5793     5793              
==========================================
- Hits        23763    23762       -1     
- Misses      14975    14976       +1     
- Partials     1261     1262       +1     
Impacted Files Coverage Δ
src/client/datascience/debugLocationTracker.ts 76.92% <83.33%> (-1.21%) ⬇️
src/client/common/utils/platform.ts 68.00% <0.00%> (-4.00%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 76e6e28...06803f7. Read the comment docs.

@sonarqubecloud
Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

@joyceerhl joyceerhl merged commit aa1b0b2 into main Oct 17, 2020
@joyceerhl joyceerhl deleted the dap-sequence-numbers branch October 17, 2020 07:08
rchiodo pushed a commit that referenced this pull request Oct 19, 2020
* Ensure debug adapter request/response sequence numbers tally (#14336)

* Make data viewer openable from the variables window while debugging (#14406)
luabud pushed a commit to luabud/vscode-python that referenced this pull request Oct 26, 2020
DonJayamanne pushed a commit that referenced this pull request Oct 30, 2020
* Ensure debug adapter request/response sequence numbers tally (#14336)

* Port issue assigning fixes
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 59%. Comparing base (76e6e28) to head (06803f7).
⚠️ Report is 2829 commits behind head on main.

Files with missing lines Patch % Lines
src/client/datascience/debugLocationTracker.ts 83% 0 Missing and 4 partials ⚠️
Additional details and impacted files
@@          Coverage Diff           @@
##            main   #14336   +/-   ##
======================================
- Coverage     59%      59%   -1%     
======================================
  Files        716      716           
  Lines      39999    40000    +1     
  Branches    5793     5793           
======================================
- Hits       23763    23762    -1     
- Misses     14975    14976    +1     
- Partials    1261     1262    +1     
Files with missing lines Coverage Δ
src/client/datascience/debugLocationTracker.ts 76% <83%> (-2%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog No news entry required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants