Skip to content

Debugger breaks at incorrect location for breakpoint in new Flutter project's _MyHomePageState.build method #1553

@DanTup

Description

@DanTup

This was raised at Dart-Code/Dart-Code#3898, but I think it's a DWDS issue. I can reproduce it on latest Flutter master.

  • Create a new project with flutter create
  • Add a new breakpoint to the build method in _MyHomePageState
  • Debug on Chrome device and wait for the breakpoint to be hit
  • The debugger pauses in package:flutter/src/widgets/binding.dart
{
	"type": "Event",
	"kind": "PauseBreakpoint",
	"timestamp": 1648811630946,
	"isolate": {
		"type": "@Isolate",
		"id": "1",
		"number": "1",
		"name": "main()",
		"isSystemIsolate": false
	},
	"pauseBreakpoints": [
		{
			"type": "Breakpoint",
			"id": "bp/3#72",
			"breakpointNumber": 609,
			"enabled": true,
			"resolved": true,
			"location": {
				"type": "SourceLocation",
				"script": {
					"type": "@Script",
					"id": "3",
					"uri": "package:dartcode_flutter_3898/main.dart"
				},
				"tokenPos": 1368
			}
		}
	],
	"topFrame": {
		"type": "Frame",
		"index": 602,
		"code": {
			"type": "@Code",
			"id": "610",
			"name": "scheduleAttachRootWidget",
			"kind": "Dart"
		},
		"location": {
			"type": "SourceLocation",
			"script": {
				"type": "@Script",
				"id": "68",
				"uri": "package:flutter/src/widgets/binding.dart"
			},
			"tokenPos": 73501
		},
		"kind": "AsyncCausal"
	}
}

In VS Code we detect this is not user-code and walk up the stack to the first user-code frame, which is:

{
	"type": "Frame",
	"index": 605,
	"code": {
		"type": "@Code",
		"id": "612",
		"name": "main$",
		"kind": "Dart"
	},
	"location": {
		"type": "SourceLocation",
		"script": {
			"type": "@Script",
			"id": "3",
			"uri": "package:dartcode_flutter_3898/main.dart"
		},
		"tokenPos": 1394
	},
	"kind": "AsyncCausal"
},

The tokenPos is 1394 and the relevant part of tokenPosTable is:

	[
		4,
		1393,
		24,
		1394,
		3
	],

This says line 4, character 3, which is the runApp call, so the breakpoint is here:

Screenshot 2022-04-01 at 12 23 15

But the user ends up here:

Screenshot 2022-04-01 at 12 23 58

The actual reported top frame of the stack is here:

Screenshot 2022-04-01 at 12 24 23

Relevant logs:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions