Flutter Debugging in visual studio code - flutter

When we use visual studio code for flutter programming, can we restrict debugging process to user files only? and forbid the debugger from opening and debugging external libraries during the debug session?
I used the debug setting at the bottom of the visual studio main window and set it to my code only, yet, the debugger keeps branching into external files when it reaches a return statement in the widget build method.
Sample statement that causes branching into external libraries during debugging
Sample external library that joins into the debugging process

If I understood correctly, you can click a button on the bottom bar to toggle between Debug my code and Debug my code + packages'.
This button is only visible when you are in debug mode.

Apparently the behavior I described in my question was related to deep Uncaught exceptions.
Enabling All Exceptions and Uncaught Exceptions in the debug window assisted in further exploring the issue.
My issue was related to popping an out-of-context widget which caused abnormal behavior while debugging.

Related

Need clarification on vs code debug

Can anyone explain these three debug symbols on VSCode I have found on the internet?
My vs code has the one with the play icon.
All demos online on debugging have the one in the middle. How do I get that?
Also, node js debugging is installed but I think it shows as disabled, with no option I can find to enable it.
To answer your question directly [TL;DR]: you already have it if you are using the latest version of vscode. It will take you to the same view as the one on the right
If you look at the codicon libray ref the middle one you pointed out is not present.
Visual Studio Code made changes in February 2020 ref that incorporates running and debugging to be something more harmonious:
User studies revealed that new users have difficulties finding how to run their programs in VS Code. One reason is that the existing "Debugging" functionality is not something that they relate to "Running" a program. For that reason, we are making "Run" more prominent in the UI.
The main menu Debug has become the Run menu.
The Run and Debug view has become the Run view and the corresponding Activity Bar icon now shows a large "Play" icon with a small "bug" decoration.
So in other words, there is no difference. The 'Run' and 'Debug' view is synonymous and the icon reflects those changes. As they noted, the Debug view is now called the 'Run' view, but it still offers debugging and breakpoints.
There are 2 possibilities you are running into however:
The tutorials and guides you are using are out-dated (showing an outdated version of vscode)
The tutorial or guide is using an extension that offers debugging capabilities. Extensions have some control over the icon you see
The extension is for single file debugging, according to the June 2020 ref notes, vscode recommends the following:
For debug extensions that want to improve the single file debug experience by adding a "Run" and/or "Debug" button to the editor, we recommend following these guidelines for a consistent look and feel:
Contribute Run and/or Debug commands in the package.json (see Mock Debug):
Use the command titles "Run File"/"Debug File" or "Run Python File"/"Debug Python File".
Use the $(play) icon for Run and $(debug-alt-small) for Debug.
Where their codicon library was updated in June to reflect the following:
As you can see, none of them are prefixed with verbiage like 'run', but they all represent the same functionality.
Additionally, you may see this icon as well:
This represents the panel (view) where the output of your debug will go.

What are the ways by which one can debug a Flutter app?

Error Example:
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following assertion was thrown building Builder(dirty):
type 'int' is not a subtype of type 'String'
I need to see where or which variable is causing this.
Do we have to use breakpoint(s) while debugging a Flutter app or is there something more to it?
I really truly appreciate your input. May I just say that the responses below to this question were perfect. However, there is no code to paste. I had so many bugs. It was just a 1 off question wondering at how one could see the runtime value of variables.
Your response is of huge benefit. Thank you all very much
By the way, the fix to this particular problem can be solved in many ways.
It happens when trying to do:
Text(myDoubleValue.toString());
The way you could fix this is by doing
var myTempValue = myList[counter]['doubleValue'];
(for what its worth) - but the question required more focus on using the debugger than actually solving this 1 issue.
If your question is about how to debug your code - then:
you can add breakpoints by clicking on the right from string numbers (red circles on screenshot)
after this you can run debug from menu or by clicking Shift+F9
Hope this is what you asked for
How to find where or which variable is causing this ? Two ways bellow:
Normally after crash, the first link in call stack take you to the code line which cause the crash.
If you enable All Exceptions in BREAKPOINTS of Debug Panel, you should see the line of crashing immediately when you debug.
Dev Tool
Or you can use Dev Tool as third comment mentioned by #SonofStackoverflow bellow.
DevTools is what your precisely looking for,
For debugging and profiling apps, DevTools might be the first tool you
reach for. DevTools runs in a browser and supports a variety of
features:
• Source-level debugger
• Widget inspector that displays a visual widget tree, and “widget
select” mode where you select a widget in the app and it drills down
to that widget in the tree.
• Memory profiler
• Timeline view that supports tracing, and importing and exporting trace
information Logging view
Excerpt taken from the official Flutter docs,
To know more about DevTools head over to the link given below,
https://flutter.dev/docs/testing/debugging

How to change/improve debugger UI in Visual Studio Code?

I am looking for ways to create my own window to show different threads and other information in a different way. I found following is written at https://code.visualstudio.com/docs/extensions/overview
"
Debug Adapter#
VS Code implements a generic debugger UI and relies on debugger extensions and so called "debug adapters" to connect the debug UI to a real debugger or runtime. A debug adapter is a dedicated process that communicates with VS Code through the VS Code Debug Protocol and can be implemented in any language.
"
Can someone guide me if it can be done by extension or by modifying the source code of VS code itself ?

eclipse - class find editor - source not find

I have a problem with eclipse debugging. I had a proper working code and few hours ago I add one more external library to do something new. When I run the program now it works properly, but when I want to debug it, it stopped on the first line of a new part of the code (the one using the newest external library). It shows the info:
"Class File Editor
Source not found
The source attachment does not contain the source for the file ModelBuilder.class"
When I try to step over I just receive the same information but connected with other files. After stepping over a multiple times I finally get back to my code and can debug the rest of the program normally.
Of course I can do it always but does anybody know the solution to that problem, not to click step over multiple times but debug normally?
It should not enter the external library code unless you step into it, or there's an exception in that code. If you find yourself stepping through code you don't have source to, use Step Return, which jumps to the end of whatever method you're in.
If it is caused by an exception in the library code and you want to ignore it, go to Window > Preferences > Java > Debug and uncheck "Suspend execution on uncaught exceptions".
If you know what exception is causing the execution to suspend, then you could also try this:
Go to the Debug perspective
Open the Breakpoints view
Click the J with the exclamation point by it (J!)
Search for the exception that triggers the debug suspend
Uncheck the two check boxes
Say OK

OutputDebugString() does not work on Windows 7x64

My program works great with windows xp. I am trying to add some more functionality and using OutputDebugString() to show some debug information. works flawlessly on XP. Now when i want to use the same program on windows 7x64. I dont see any output in DebugView.
F1! F1! F1!
Sorry for reviving an old question, but we spent a good couple of days searching the internet to answer this one and eventually ended up logging a connect call. I am posting here to help anyone else in the same situation. Our specific problem was getting the output from OutputDebugString, MFC TRACE etc in the debug output window when debugging an x64, mixed mode application.
According to Microsoft, apparently for debugging x64 mixed mode applications the debugger type of 'auto' (set in the Debugging->Debugger Type property page) defaults to managed rather than mixed. This will need to be explicitly set to 'Mixed' for both managed and native debug output to be seen when debugging a 64 bit build.
There are a number of reasons why this may or may not work. I accidentally disabled this -- here are all the things you need to check to get this working:
Is the debug output text getting redirected from the Output pane to the Immediate pane, thus you are not seeing it? To turn this off:
Debug
Options and Settings
[ ] Redirect all Output Windows text to the Immediate Window
Is the Output pane visible?
Debug
Windows
Output
In the Output pane do you have Program Output enabled?
Debug
Windows
Output
Right-Click anywhere inside the pane
[x] Program Output
Do you have the right Debugging Type selected?
In the Solution Explorer (View > Solution Explorer) pane
Right-click on your project
Properties
Debugging
Debugging Type: change from Auto to either Native or Mixed
Is the debugger tried to get attached before the program has started? To turn Attach off:
In the Solution Explorer (View > Solution Explorer) pane
Right-click on your project,
Properties
Debugging
Attach: change to No
Are you using OutputDebugStringW()? Try using OutputDebugStringA() instead.
Lastly, did you start the program in debugging mode? :-) Hey, you never know!
Debug
Start Debugging (F5)
I hadn't seen a comprehensive list before so the above are all the things I had to verify were set correctly.
3 small suggestions:
make sure you are actually capturing events (top menu -> capture -> capture win32 is marked)
if you program is running in low integrity (does it give a security warning when you are running it) you need to run debug view in low integrity as well. to do that you need to change the integrity level of dbgview.exe before running it.
if you are using visual studio and running with debugger (pressed F5) then the debug output is actually captured by visual studio (in the output window). try running your program with ctrl f5.