Pause Flutter app in debugger and wait for tap in IntelliJ - debugging

I'm trying to debug a Flutter app in the Android emulator by pausing it, tapping on a button and expecting the debugger to take me to the buttons onPressed event handler, where I want to step through the code.
When I tap the button, nothing happens and the debugger doesn't change from paused to running. However, if I resume the app after tapping the button, the onPressed event handler is immediately invoked, so obviously the tap is being picked up by the emulator while the app was paused.
How can I debug my app in this manner, instead of manually finding the correct .dart file and the correct button and inserting a breakpoint?

Unfortunately you cannot do exactly that. Pausing the app prevents the event loop from executing and your button handler is not called. Making it pause in any of your code requires a new feature in which IntelliJ can differentiate between your code and framework code, and stop at any invocation of your code (even then, it should ignore your build() functions). The closest thing to that I could find in IntelliJ is Java method breakpoints, which would not work with Dart.
However, here is one thing you can do: You can set up a breakpoint in the caller of onPressed, which would pause your app on any button press. Here's where you can place that breakpoint:
// This is Line 504 of flutter/lib/src/material/ink_well.dart
// Ctrl+click on button to go into the framework code
// and find this file in project explorer
void _handleTap(BuildContext context) {
_currentSplash?.confirm();
_currentSplash = null;
updateHighlight(false);
if (widget.onTap != null) {
if (widget.enableFeedback)
Feedback.forTap(context);
widget.onTap(); // <---PLACE BREAKPOINT HERE
}
}
Once you hit this breakpoint, click step into (F7) a couple of times and you should get to your onPressed.

Related

how can i debug the opening of my application from a file on OSX?

I linked my application to a file extension, so when i double click those files it opens my application. However i experience crash when doing so, and i am looking for a way to breakpoint that and see what's going wrong. I'm using Xcode, it's an OSX app.
Any idea?
lldb doesn't have a "launch with open AppleEvent" feature, so you can't do this directly.
But you can use lldb's "attach wait" feature to catch the app early in startup. You can do this in Xcode by turning on "Wait for the executable to be launched" in the Info tab of the Run scheme of your App target. Then click the Run button, and go to Finder to launch your app by double-clicking on one of its files.
If your system is not heavily loaded, lldb will generally stop the app pretty early in its startup, usually before it gets to handling the open event. Xcode will auto-continue the app, so it should just proceed right to the crash.
If for some reason lldb doesn't attach early enough, edit the main function of your application, and at the very top put in:
int go_on = 0;
while(!go_on) {
sleep(1);
}
That way your app will stall in launching before it handles the open event, giving
lldb time to attach. Once it has attached, Pause the app in the debugger, select the thread and frame containing this main function, go to the lldb Console and do:
(lldb) expr go_on = 1
and then continue. Now your app should finish starting up, handle the open event and crash into the debugger.
As a complement of Jim's answer: If your application is responding to the kAEOpenDocuments event through
- (void)handleAppleEvent:(NSAppleEventDescriptor *)event
withReplyEvent:(NSAppleEventDescriptor *)replyEvent
you can debug your application using Xcode as usual, and set a breakpoint on the line where you start to process that event (or at the beginning if it crashing before reaching that point). Once set up, go to Finder and open the file.
Take into account that when double-clicking it will launch the default app, so if your debug build is not the default one you have to choose "Open With > Other...".

NativeScript app.start does not fire page events

I'm seeing a strange behavior with my simple NativeScript / Typescript app. In the app.ts i launch the application like so:
app.start({ moduleName: "pages/home/home-page" });
but debug break points in home-page.ts in the loaded and navigatingTo event handlers don't stop execution. however when in the app i click on the Home page link the events are fired and the break points are stopped. So it looks like the app.start call does not fire page lifecycle events at all.
Seems like a strange behavior. Any ides?
It appears that the application is being executed too fast and the debugger doesn't have time to attach. To fix this problem in the launch.json (debugger configuration in VSC) set
"stopOnEntry": true
This will stop the application on the first line and allow time for the debugger to attach.

Xcode 4.3 leaving debug after breakpoint

I am aware of shourtcuts from: Xcode 4 shortcuts but when i'm try to step out after breakpoint and i hit F8 there step into some thread. I don't want to do that. After i saw the infos i want i want to return to my app on the simulator or device and don't want to app stops anywhere. There is a way to completly step out of debug after breakpoint?
Stepping out takes you out of the function you're currently in and moves you to the function that called the function you were in. Stepping out does not resume program execution. Click the Continue button to resume program execution. The Continue button is to the left of the step buttons in Xcode's Debug area.

ResolveHostNameAsync breaks tombstoning?

I noticed an issue where calling DeviceNetworkInformation.ResolveHostNameAsync prevents the app from resuming from a tombstoned state. If you force tombstoning upon deactivation when debugging (via the project settings, debug tab), pressing the Windows button and then the Back button to return to the app causes the phone/emulator to display "Resuming..." and never actually return from the tombstoned state.
To test this, I created a new WP7.1 app and added a button with the following action:
private void Button_Click(object sender, RoutedEventArgs e)
{
DeviceNetworkInformation.ResolveHostNameAsync(new DnsEndPoint("google.com", 0), HostNameResolutionCallback, null);
}
For testing, my callback method doesn't actually do anything:
private static void HostNameResolutionCallback(NameResolutionResult result)
{
}
If you tap the button, exit, and then return to the app, it will display "Resuming..." until you press the Windows button again.
I am using the WP7.1 Beta 2 Refresh SDK.
Any ideas?
I suspect that you're starting the app with the debugger attached.
When you force tombstoning the process is being ended and so when you resume the emulator is waiting for you to restart the debugger so you can continue debugging the app.
This behaviour is by design. It is to allow you to continue debugging after tombstoning.
If you force tombstoning while debugging and the app appears to be stuck in the resuming state just hit F5 (Debug > Start Debugging) in Visual Studio to resume the app and the debug session.

WP7 App Events in Emulator

I'm seeing some unexpected things happening in the emulator.
When debugging and starting the app for the first time, the Application_Launching fires just fine. When clicking the start button, the Application_Deactivated event fires fine. When click the back button, the Application_Activated event fires fine.
If I click the start button then go to my apps and launch my app, no events are fired. I would assume either the Application_Launching or Application_Activated would fire when the app is launched every time, just a different event depending on how the app got there.
Is this an issue with the emulator or do I have the wrong assumptions here?
Well, the events get fired right. What you missed is that debugger get dettached when you are launching "new instance" of your app. ;)

Resources