What am I doing?
I have a native iOS app with an integrated Flutter add-to-app module. In order to debug the dart code, I launched the native app in an iOS Simulator, then I ran flutter attach to attach the Flutter debugger to the native app.
Below is my launch.json file.
"version": "0.2.0",
"configurations": [
{
"name": "chope_app_flutter",
"request": "launch",
"type": "dart"
},
{
"name": "chope_app_flutter (iOS attach)",
"request": "attach",
"type": "dart"
},
],
}
What is the problem?
Sometimes, when I start debugging flutter attach, some errors occur.
There are multiple observatory ports available.
Rerun this command with one of the following passed in as the appId:
flutter attach --app-id com.example.id
flutter attach --app-id com.example.id (2)
I know it's ok to run this in the terminal, but I want to debug flutter code in VSCode.
Can someone help to resolve this issue?
Thanks!
Related
I have been trying to debug C++ code via VScode on a remote docker container. While this is working for 2 of my other college's it isn't for me. We both use the same docker image. So I suspect it's something in my VScode, but what I do not know.
I get the following error when debugging the source code.
Unable to open 'malloc.c': Unable to read file 'vscode-remote://attached-container+7b22636f6e7461696e65724e616d65223a222f637070616e74227d/build/glibc-S9d2JN/glibc-2.27/malloc/malloc.c' (Error: Unable to resolve non-existing file 'vscode-remote://attached-container+7b22636f6e7461696e65724e616d65223a222f637070616e74227d/build/glibc-S9d2JN/glibc-2.27/malloc/malloc.c').
I can "fix" this by extracting glibc in /build/, but I would rather have it fix forever and not have the same issue with another docker container (possible). Glibc is installed in the Docker container at /usr/src/glibc. I found it by running find / -iname glibc.
To run the application from VScode on the remote docker container, I use this launch.json file:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch Program",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/src/application",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/build/src",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
Not sure if this information is necessary but it cant do harm.
host: Windows 10
docker container: ubuntu 18:04
visual studio code version: 1.55.0
Hopefully, this is enough information to resolve the issue I'm facing.
Once I had set launch.json and I ran gdb and debugged in my code successfully until something happened and all breakpoint became "gray" with the such message:
"Module containing this breakpoint has not yet loaded or the breakpoint address could not be obtained."
However, debugger attaches to running program and I even can make steps from main, but still breakpoint are not hit... This is C++ project that is built with cmake with gcc with -DCMAKE_BUILD_TYPE=DEBUG flag.
launch.json is this:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "./MyProject/project",
"args": [],
"stopAtEntry": false,
"cwd": "/home/AA/workspace",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"miDebuggerServerAddress": "/*Cannot write here, but it's fine*/",
"sourceFileMap": {/*Cannot write here, but it*/}
},
]
}
How do I fix this problem?
I was looking for an answer in other resources and the most solutions say that you should -g option if you compiler a project with gcc. It wasn't my case because I use cmake but I had one detail that I debugged code that was run in docker.
When you work with files in VS code from your user and docker runs project from another user, you should add the option "sourceFileMap": {} in launch.json:
"sourceFileMap": {
"/home/user/project/file.hpp" : "/home/YourNameBeyondDocker/project/file.hpp",
...
I added wrong path in this option. When I took it out, my debugger finally started hitting breakpoints!
I'm using vs code to create and build a flutter project.
But every time I press F5 to build, vs code always asks me to select the environment. It's very annoying.
How to set dart & flutter to default when I'm buliding flutter projects.
For VSCode you need a launch configuration
If you don't have the following file, create one:
.vscode/launch.json
With contents of:
{
"version": "0.2.0",
"configurations": [
{
"name": "Flutter",
"type": "dart",
"request": "launch",
"program": "${workspaceFolder}/main.dart"
}
]
}
Just make sure the program is pointing to your main dart file that has runApp in it
{
"configurations": [
{
"name": "Flutter",
"type": "dart",
"request": "launch",
"program": "lib/main.dart"
}
]
}
I have a React Native project open in Visual Studio code, and Im trying to run the project on a physical connected iOS device. I successfully ran the app on the device directly from Xcode, but from Visual Studio Code I'm having issues. I believe I need to add a configuration for the device into launch.json. I have tried different entries in there but non seem to work. What is the proper way to add a configuration for a connected iOS device?
If you need to target a specific device, this is how it´s done:
{
"name": "iOS Device",
"program": "${workspaceRoot}/.vscode/launchReactNative.js",
"type": "reactnative",
"request": "launch",
"platform": "ios",
"sourceMaps": true,
"target": "device",
"outDir": "${workspaceRoot}/.vscode/.react",
"runArguments": [
"--device",
"DEVICE NAME"
],
}
So you need to set "target": "device" to tell the debugger to run on a device, and then you set the device name through "runArguments".
Try with react-native run-ios --device "your device name"
Device name you can find in xcode
You can add this in package.json also
{
start:ios: "node node_modules/react-native/local-cli/cli.js run-ios --device \"your device name\""
}
You may need to install ios-deploy
npm install -g ios-deploy
For vscode launch.json you can add these configuration node node_modules/react-native/local-cli/cli.js run-ios --device \"your device name\" in launch.json too
launch.json
{
"type": "node",
"request": "launch",
"name": "Run app",
"program": "${workspaceRoot}/node_modules/react-native/local-cli/cli.js",
"cwd": "${workspaceRoot}",
"runtimeArgs": [
"run-ios",
"--device",
"\"your device name\""
],
}
This is what I eventually had and managed to get it to install and launch on the connected device. The value for key name does not seem to uniquely identify a connected device. Its just the name that shows in Device Debug drop down.
{
"name": "My iPad",
"program": "${workspaceRoot}/.vscode/launchReactNative.js",
"type": "reactnative",
"request": "launch",
"platform": "ios",
"target": "device",
"sourceMaps": true,
"outDir": "${workspaceRoot}/.vscode/.react"
},
VSCode Version: 1.12.2
OS Version: Windows 10
Electron Version: 1.7
Steps to Reproduce:
I did an NPM update for electron, and a few other modules, and the Debug Launch of Electron stopped working. However, I can still manually start Electron from the command prompt, and it seems that the same command is what VSCODE is doing.
I.e. this works:
> d:\wwwroot\librarian2017\dashboard/node_modules/.bin/electron.cmd --debug-brk=24964 --nolazy main.js
But I get the message (below) when I run launch.json, and the blue status bar at the bottom of the VSCODE window turns orange for a second and then goes back to blue. No indication of what crashed. But nothing pops up.
Debugging with legacy protocol because a runtime executable is set.
d:\wwwroot\librarian2017\dashboard/node_modules/.bin/electron.cmd --debug-brk=24964 --nolazy main.js
Launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "DashBoard",
"program": "${workspaceRoot}/main.js",
"stopOnEntry": false,
"args": [],
"cwd": "${workspaceRoot}",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd",
"env": {},
"sourceMaps": true
}
Probably a bug in VSCODE. I rolled electron back to 1.6.7 and it works again. I filed an issue on github.