Skip to content

baseUri returned by flutter run does not match actual base paths required by the debugger (flutter's has file://, VM not) #11040

Closed

Description

@DanTup

This could be related to #10934 but I don't think so, so raising a new issue.

I'm sending a hot reload with pause=true then when I get PausePostRequest I'm deleting and re-sending breakpoints (I also then send a resume, which fails, but I'm discarding the error for now - that's what #10934 is about).

However, my breakpoints never appear to be hit after this has happened. I'm aware that #10934 means there's a race, however I'm doing this:

  • Hitting breakpoint in Stocks example app theme getter (main.dart:66)
  • Sending resume (twice, since this getter is called twice)
  • Changing the colour of one of the themes
  • Sending a hot reload - the colour correctly updates
  • Switching theme using the app's slide-out drawer

When switching theme, the theme updates on the screen but the debugger never breaks.

It's harder to repro this in a script like I did for the other cases so I'm hoping this is enough info to go on; but if you really can't repro/understand this then I can try and find time to do this.

Here's the log - I've included a trimmed version without all the stuff I think is not relevant but also the full log (best viewed without wrapping).

observatory.trimmed.txt
observatory.txt

Activity

  1. devoncarew commented on Jun 30, 2017

    @devoncarew
    Contributor

    Are you using the baseUri field returned from the app.debugPort event (https://github.com/flutter/flutter/wiki/The-flutter-daemon-mode#appdebugport)? After the first reload, the sources are being loaded exclusively from the vm's devfs. Before that, they could be running from the initial snapshot - breakpoint paths with work before may not work after.

    You can connect w/ the observatory before and after a reload, and see if the script paths are different. Here's our logic for setting a breakpoint in IntelliJ - https://github.com/flutter/flutter-intellij/blob/10f4723dd11736640aa8896068c819917c9e09a0/src/io/flutter/run/PositionMapper.java#L173 - we do have to send in several VM breakpoints per user one.

  2. DanTup commented on Jun 30, 2017

    @DanTup
    ContributorAuthor

    Are you using the baseUri field returned from the app.debugPort event

    I'm not. It wasn't clear exactly how to use this (though I see from your code it's literally just stuck on the front) and at the time the breakpoints seemed to be working (before I hit this issue!) so I figured it wasn't needed. I'll try adding that in to see if it helps.

    we do have to send in several VM breakpoints per user one.

    Interesting - we have this in Dart Code but I always thought it was a nasty hack; it's good to see IntelliJ having to do the same!

    I'll try and give these changes a go this weekend and post back with the results. Thanks!

  3. devoncarew commented on Jun 30, 2017

    @devoncarew
    Contributor

    The chrome debug protocol allows you to set a breakpoint using a regex (or just a glob pattern?). If we had the same functionality in the dart vm, we could remove a bunch of the duplicate breakpoints.

  4. DanTup commented on Jun 30, 2017

    @DanTup
    ContributorAuthor

    @devoncarew IMO that should really be done inside the debugger/VM not from outside. We should just be able to send filesystem paths (even if we have to put them in a specific format) and the debugger should deal with normalising the paths it has (eg. package paths). After all, the VM loaded the files off disk (even for a package: import, so it knows where everything is). This would also mean consistent behaviour across IDEs without implementors having to copy each others hacks =D

  5. DanTup commented on Jul 2, 2017

    @DanTup
    ContributorAuthor

    @devoncarew I cannot figure out how I'm supposed to use baseUri. I tried cramming it on to the start of what I was previously sending, which ended up as:

    "scriptUri":"file:///data/user/0/io.flutter.examples.stocks/cache/stocksez80O7/stocks/file:///m:/Coding/Applications/flutter/examples/stocks/lib/main.dart"

    This resulted in never being hit (not even the first time). So I tried trimming the extra file:/// and ended up with this:

    "scriptUri":"file:///data/user/0/io.flutter.examples.stocks/cache/stocksez80O7/stocks/m:/Coding/Applications/flutter/examples/stocks/lib/main.dart"

    Same thing; doesn't even get hit the first time anymore. Could you confirm exactly what I should end up with given inputs like:

    baseUri = file:///data/user/0/io.flutter.examples.stocks/cache/stocksez80O7/stocks/
    filename from IDE: m:\Coding\Applications\flutter\examples\stocks\lib\main.dart
    

    (I'm also curious why I used to hit the first breakpoint without using baseUri!)

  6. DanTup commented on Jul 2, 2017

    @DanTup
    ContributorAuthor

    Ok, I figured maybe I needed to make the path relative from the workspace root, so I sent this:

    "scriptUri":"file:///data/user/0/io.flutter.examples.stocks/cache/stocksanN6XK/stocks/lib/main.dart"

    Still never gets hit! So far, every attempt to use baseUri seems like a step backwards; breakpoints don't work at all, never mind after a hot reload.

    I really think there needs to be some documentation on how these should be formatted. It was already a bit wonky that we need to "send lots of breakpoints in the hope one is correct" and it kinda feels like I'm just trying to "hack it till it works" rather than understand it. I think it'd be much more reliable to understand exactly how this should work.

  7. devoncarew commented on Jul 3, 2017

    @devoncarew
    Contributor

    I really think there needs to be some documentation on how these should be formatted.

    I agree here - I think having a third-party implementor go through these steps really illuminates the need for better docs in a few tooling areas.

    it kinda feels like I'm just trying to "hack it till it works"

    Breakpoints in flutter apps are tricky, and getting them working successfully requires work on both the VM side and the IDE. In order to simplify the current state of the art, I think we want the ability to specify breakpoints via globs (I opened the request here: dart-lang/sdk#30061).

    baseUri = file:///data/user/0/io.flutter.examples.stocks/cache/stocksez80O7/stocks/
    filename from IDE: m:\Coding\Applications\flutter\examples\stocks\lib\main.dart

    The baseUri field is the prefix for the path the VM thinks the project is running in. We use it since for flutter apps the source is often not running on the host machine, so the IDE won't be able to know the path head of time. You want to do $baseUri$relativePath. For the above, the relative path is lib\main.dart, so you'd want something like file:///data/user/0/io.flutter.examples.stocks/cache/stocksez80O7/stocks/lib/main.dart.

  8. DanTup commented on Jul 3, 2017

    @DanTup
    ContributorAuthor

    For the above, the relative path is lib\main.dart, so you'd want something like file:///data/user/0/io.flutter.examples.stocks/cache/stocksez80O7/stocks/lib/main.dart.

    That's the format in my last comment but also didn't seem to work:

    "scriptUri":"file:///data/user/0/io.flutter.examples.stocks/cache/stocksanN6XK/stocks/lib/main.dart"

    I'll try again and get some logs. though I'm still confused why the breakpoints worked initially with the real fs path from the host?

  9. devoncarew commented on Jul 3, 2017

    @devoncarew
    Contributor

    It looked like your comments included the full local path? They have the m: in them. Just to be clear, you only want to append the relative path from the project root.

    For the first run, we ship the app over to the device as a snapshot; that snapshot is generated on the host, and will include the local paths for the scripts. After a reload, the app is loaded (and reloaded) from a filesystem hosted in the VM (the devfs) - the baseUri allows us to generate paths for scripts loaded from that filesystem.

  10. DanTup commented on Jul 3, 2017

    @DanTup
    ContributorAuthor

    It looked like your comments included the full local path? They have the m: in them.

    The first comments did, but the last one before your comment I'd realised that was an error tried what you suggested ("scriptUri":"file:///data/user/0/io.flutter.examples.stocks/cache/stocksanN6XK/stocks/lib/main.dart"). Still didn't work; though I'll give it another try tomorrow evening.

    For the first run, we ship the app over to the device as a snapshot; that snapshot is generated on the host, and will include the local paths for the scripts

    Aha, got it now; that makes sense!

  11. DanTup commented on Jul 4, 2017

    @DanTup
    ContributorAuthor

    @devoncarew I've double-checked everything and it's still not working.

    Here's the baseUri I get back:

    {"event":"app.debugPort","params":{"appId":"0d1454f5-da2e-4652-baf6-cf6f37f2160d","port":8099,"wsUri":"ws://127.0.0.1:8099/ws","baseUri":"file:///data/user/0/io.flutter.examples.stocks/cache/stocksx9P1aa/stocks/"}}

    Here's me deleting and re-sending the breakpoints after the hot reload (the last one is the one we believe should hit, I've snipped the responses out to keep it short, but they were all success):

    {"id":"468","method":"removeBreakpoint","params":{"isolateId":"isolates/986982991","breakpointId":"breakpoints/1"}}
    {"id":"469","method":"removeBreakpoint","params":{"isolateId":"isolates/986982991","breakpointId":"breakpoints/2"}}
    {"id":"470","method":"removeBreakpoint","params":{"isolateId":"isolates/986982991","breakpointId":"breakpoints/3"}}
    
    {"id":"471","method":"addBreakpointWithScriptUri","params":{"isolateId":"isolates/986982991","scriptUri":"file:///m:/Coding/Applications/flutter/examples/stocks/lib/main.dart","line":60}}
    {"id":"472","method":"addBreakpointWithScriptUri","params":{"isolateId":"isolates/986982991","scriptUri":"package:stocks/main.dart","line":60}}
    {"id":"473","method":"addBreakpointWithScriptUri","params":{"isolateId":"isolates/986982991","scriptUri":"file:///data/user/0/io.flutter.examples.stocks/cache/stocksx9P1aa/stocks/lib/main.dart","line":60}}

    After that, I switch the theme in the app in the emulator, but it never breaks.

    I've pushed the exact code with all changes (including resending the breakpoints and adding the additional mapped uri) to the flutter branch. I've added some info to the contribution file (flutter version here) including how to debug the debug adapters if you're interested/have time to have a poke.

  12. devoncarew commented on Jul 4, 2017

    @devoncarew
    Contributor

    Hmm, I don't see an issue w/ how you're using baseUri, or the breakpoint uris you're sending. You might try opening the observatory against the running instance. There's a way in the UI to see the uris for the loaded scripts. You can see the uri for lib/main.dart, before the reload, and after the reload, and compare that to what you'd expect to generated based on the returned baseUri. That may given you an indication of where the issue is and why the breakpoints aren't being hit -

  13. DanTup commented on Jul 5, 2017

    @DanTup
    ContributorAuthor

    Ok, I checked in Observatory and the URI is missing the file:/// prefix:

    Observatory URI

    If I trim this off, it works. However, the baseUri property returns by flutter includes it, so either flutter run is returning the wrong baseUri or something is wrong with the path in the VM.

    I'm going to just trim this off for now so I can fix the next issue (mapping the path back so the IDE can break in the correct place) however I think this has to be considered a bug. It would really help if someone can add exactly what the breakpoints are expected to be to the docs, it feels erally fragile to just "send as many formats as I can come up with" to try and hit them :(

    Edit: My screenshot was misleading since it showed what I was sending as the breakpoint, not what came back in flutter run but you can trust me they're the same! Flutter run had file:/// at the start of the baseUri!).

  14. changed the title [-]After hot reload and re-sending breakpoints, breakpoints are not hit[/-] [+]baseUri returned by flutter run does not match actual base paths required by the debugger (flutter's has file://, VM not)[/+] on Jul 5, 2017
  15. changed the title [-]baseUri returned by flutter run does not match actual base paths required by the debugger (flutter's has file://, VM not)[/-] [+]baseUri returned by `flutter run` does not match actual base paths required by the debugger (flutter's has file://, VM not)[/+] on Jul 5, 2017
  16. 1 remaining item

  17. DanTup commented on Dec 21, 2017

    @DanTup
    ContributorAuthor

    Ok, can't explain what's caused this, but seems like if I just never send file:/// prefixed breakpoints, they all work (both initially, after hot reload and on both Mac and PC). This avoid the issue with getting repeated IDs back (the fix was less easy than I thought, because we store them grouped by uri and the uris are different).

    So, I think I can solve my issue; however the original point of this issue remains - documenting the expected formats for this stuff would remove a lot of guesswork/assumptions.

  18. DanTup commented on Feb 19, 2018

    @DanTup
    ContributorAuthor

    Another bug came up relating to breakpoint paths going to the VM: Dart-Code/Dart-Code#586

    It seems like this was probably broken by Dart-Code/Dart-Code@848ff2c but since I did that work on Windows, I'm a bit confused how it's failed!

    It would definitely help if we could document exactly the format we should send breakpoint paths in; we used to send just file-prefixed but that caused issues on Mac OS, so then we started sending slash-prefixed as well, but then I found issues where the VM would consider both of those paths the same and therefore reject the second one. We then changed to just sending slash-prefixed (which seemed to work?) but now this doesn't seem to work on Windows!

    I'm gonna try going back to the sending everything twice (and if the VM rejects the second one, handle that better) but it's rather complicated to test all this (the permutations of Windows/Max/Linux plus Dart vs Flutter plus local paths versus on-device paths) so if we could document it it'd be much easier to ensure we're doing the right thing (and if the VM breaks, we know and can fix it there, rather than shotguning it from the editor).

  19. DanTup commented on Feb 19, 2018

    @DanTup
    ContributorAuthor

    You know what happens when you assume? ... 😞

    The new bug turned out to be something even better - Windows drive letters! I tried this and it resolved the issue:

    if (isWin) {
    	// Flip the casing of the drive letter since it's often different and the VM doesn't
    	// consider then the same.
    	uris.slice().forEach((uri) => {
    		if (uri.startsWith("/") && uri.substring(1, 2) === uri.substring(1, 2).toLowerCase())
    			uris.push("/" + uri.substring(1, 2).toUpperCase() + uri.substring(2));
    		if (uri.startsWith("/") && uri.substring(1, 2) === uri.substring(1, 2).toUpperCase())
    			uris.push("/" + uri.substring(1, 2).toLowerCase() + uri.substring(2));
    	});
    }
    

    So, the Windows path casing issues seem to go further than the analyzer. I'm gonna do some investigating into why these paths are different (both are coming from VS Code in this case) in Dart-Code/Dart-Code#586 but I think long-term these should be handled better by the server/VM.

  20. Hixie commented on May 29, 2018

    @Hixie
    Contributor

    @DanTup Can you summarise what needs to change here?

  21. DanTup commented on May 30, 2018

    @DanTup
    ContributorAuthor

    @Hixie I believe that the need for baseUri to map paths to the device-local paths may be going away, in which case maybe this could be dumped. However the issue is that the baseUri that comes back from flutter run --machine looks like this:

    "baseUri":"file:///Users/dantup/Library/Developer/CoreSimulator/Devices/153B2451-E7EC-4C9F-828F-DB57FACBE47D/data/Containers/Data/Application/E45306D2-4408-4968-8BB6-36FD88757366/tmp/flutter_gallerydhLNgS/flutter_gallery/"
    

    Note that it's prefixed with file://. However in my testing, I found that when I sent a path to the VM for a breakpoint it wouldn't always work unless I removed the file:// prefix (by always, I mean between Flutter Run, Flutter Test and Dart - some of those worked with and without, and some did not; though it's been a while). So right now, my debug adapters strip the file:// prefix before sending paths as breakpoints, which feels a bit wonky.

    I think this is kinda related to this request to better document expected formats for paths. I think the lack of docs has resulted in Flutter Run/Test/Dart behaving slightly differently and because there's no docs it's less clear when the difference in behaviour is a bug, and usually ends up being worked around in the editor (for example, there's also #16352).

    I'm not sure I summarised this well; but maybe a plan would be:

    1. Someone should document the expected format of paths to/from the VM (including for Windows)
    2. I am I happy to find all the places that don't follow that and raise bugs that they don't conform
  22. added
    a: debugging
    on Jun 26, 2018
  23. zoechi commented on Dec 4, 2018

    @zoechi
    Contributor

    @DanTup Is this still an issue?

  24. DanTup commented on Dec 5, 2018

    @DanTup
    ContributorAuthor

    baseUri is no longer required because the mapping of paths is all done internally now. I removed the mappings from VS Code in Dart-Code/Dart-Code@7d25178 so this is not an issue for me.

    I wonder whether we should deprecate baseUri and update the docs - @devoncarew?

  25. added
    tool
    on Dec 5, 2018
  26. DanTup commented on Jan 28, 2019

    @DanTup
    ContributorAuthor

    @devoncarew The only references to baseUri in the spec is this:

    An optional field, baseUri, is populated if a path prefix is required for setting breakpoints on the target device.

    Since it's already marked as optional, shall I just remove that line from the doc and close this?

    (I can also remove the references in the code if we want - I guess there's a small risk, but since it was marked as optional anyway, it should be fine? @pq I presume you don't rely on this? I'm not even sure it's currently populated!).

  27. pq commented on Jan 29, 2019

    @pq
    Contributor
  28. DanTup commented on Jan 29, 2019

    @DanTup
    ContributorAuthor

    Actually, I assumed we weren't sending it anymore, but I just tested and we do:

    {
    	"event": "app.debugPort",
    	"params": {
    		"appId": "7e021aba-e58f-4852-b6f8-2ce805f50ed1",
    		"port": 51169,
    		"wsUri": "ws://127.0.0.1:51169/ws",
    		"baseUri": "file:///Users/dantup/Library/Developer/CoreSimulator/Devices/1DD6786B-37D4-4355-AA15-B818A87A18B4/data/Containers/Data/Application/3BC1155B-4C4F-4D30-8555-A1620963B87B/tmp/flutter_galleryqXPNN8/flutter_gallery/"
    	}

    VS Code stopped using it mid-last year though (v2.15.0):

    Dart-Code/Dart-Code@7d25178

    Looking deeper, we started always prefixing breakpoints with file:/// too:

    Dart-Code/Dart-Code@d385876

    So this is resolved - we can send breakpoints in the format that we get baseUri in and it all works (Dart Code has integration tests exercising that code, so I'm confident this is the case on all platforms). I still suspect baseUri could just be deleted from everywhere, but this issue is sorted.

  29. github-actions commented on Aug 31, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  30. locked as resolved and limited conversation to collaborators on Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: debuggingtool

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions