You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
baseUri returned by flutter run does not match actual base paths required by the debugger (flutter's has file://, VM not) #11040
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).
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!
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.
@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
@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:
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.
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.
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:
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.
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
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):
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.
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 -
Ok, I checked in Observatory and the URI is missing the file:/// prefix:
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!).
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
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
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.
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).
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.
@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:
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:
Someone should document the expected format of paths to/from the VM (including for Windows)
I am I happy to find all the places that don't follow that and raise bugs that they don't conform
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?
@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!).
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.
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.
Activity
devoncarew commentedon Jun 30, 2017
Are you using the
baseUrifield 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.
DanTup commentedon Jun 30, 2017
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.
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!
devoncarew commentedon Jun 30, 2017
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.
DanTup commentedon Jun 30, 2017
@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 =DDanTup commentedon Jul 2, 2017
@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:This resulted in never being hit (not even the first time). So I tried trimming the extra
file:///and ended up with this:Same thing; doesn't even get hit the first time anymore. Could you confirm exactly what I should end up with given inputs like:
(I'm also curious why I used to hit the first breakpoint without using
baseUri!)DanTup commentedon Jul 2, 2017
Ok, I figured maybe I needed to make the path relative from the workspace root, so I sent this:
Still never gets hit! So far, every attempt to use
baseUriseems 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.
devoncarew commentedon Jul 3, 2017
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.
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).
The
baseUrifield 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 islib\main.dart, so you'd want something likefile:///data/user/0/io.flutter.examples.stocks/cache/stocksez80O7/stocks/lib/main.dart.DanTup commentedon Jul 3, 2017
That's the format in my last comment but also didn't seem to work:
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?
devoncarew commentedon Jul 3, 2017
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
baseUriallows us to generate paths for scripts loaded from that filesystem.DanTup commentedon Jul 3, 2017
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.Aha, got it now; that makes sense!
DanTup commentedon Jul 4, 2017
@devoncarew I've double-checked everything and it's still not working.
Here's the baseUri I get back:
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):
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
flutterbranch. I've added some info to the contribution file (flutterversion here) including how to debug the debug adapters if you're interested/have time to have a poke.devoncarew commentedon Jul 4, 2017
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 -DanTup commentedon Jul 5, 2017
Ok, I checked in Observatory and the URI is missing the
file:///prefix:If I trim this off, it works. However, the
baseUriproperty returns by flutter includes it, so eitherflutter runis returning the wrongbaseUrior 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 runbut you can trust me they're the same! Flutter run hadfile:///at the start of thebaseUri!).[-]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)[/+][-]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)[/+]1 remaining item
DanTup commentedon Dec 21, 2017
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.
DanTup commentedon Feb 19, 2018
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).DanTup commentedon Feb 19, 2018
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:
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.
Hixie commentedon May 29, 2018
@DanTup Can you summarise what needs to change here?
DanTup commentedon May 30, 2018
@Hixie I believe that the need for
baseUrito map paths to the device-local paths may be going away, in which case maybe this could be dumped. However the issue is that thebaseUrithat comes back fromflutter run --machinelooks like this: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 thefile://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 thefile://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:
zoechi commentedon Dec 4, 2018
@DanTup Is this still an issue?
DanTup commentedon Dec 5, 2018
baseUriis 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
baseUriand update the docs - @devoncarew?DanTup commentedon Jan 28, 2019
@devoncarew The only references to baseUri in the spec is this:
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!).
pq commentedon Jan 29, 2019
@DanTup: I'm not sure if it's used actually but it does appear we collect it on
app.eventDebugPortevents.https://github.com/flutter/flutter-intellij/blob/1b199b40fcc79040625734f99d7ceb073bb97771/src/io/flutter/run/daemon/DaemonEvent.java#L197
@devoncarew : is this still valid?
DanTup commentedon Jan 29, 2019
Actually, I assumed we weren't sending it anymore, but I just tested and we do:
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.
github-actions commentedon Aug 31, 2021
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 -vand a minimal reproduction of the issue.