Mixed debugging (C#, C++) in VS Code via docker - docker

We've recently moved our development from Visual Studio to VS Code. Our code solution contains .NET Core C# which hands calculations off to C++. In Visual Studio, we were able to seamlessly debug between C# and C++.
We initially moved to running the multi-project solution in a VM and using the remote development features of VS Code. We use two Launch configurations:
{
"name": "(gdb) Attach",
"type": "cppdbg",
"request": "attach",
"program": "/usr/share/dotnet/dotnet",
"processId": "${command:pickProcess}",
"additionalSOLibSearchPath": "${workspaceFolder}/src/build/Debug/Cpp/",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
{
"name": "Run C#",
"type": "coreclr",
"request": "launch",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/src/AppProject/bin/Debug/netcoreapp2.2/AppProject.dll",
"args": [],
"cwd": "${workspaceFolder}/src/AppProject",
"stopAtEntry": false,
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"env": {
"ASPNETCORE_ENVIRONMENT": "Development",
"EnvironmentName": "Development",
"LD_LIBRARY_PATH": "${workspaceFolder}/src/build/Release/Cpp/;$LD_LIBRARY_PATH"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
}
}
First running "Run C#" then running "(gdb) Attach" and selecting the dotnet process to attach to. This worked, allowing us to step down from C# into C++.
We've now moved to a Docker set up, where the source is mounted into a container with the build tools built in (as described in the VS Code docs). This is roughly our devcontainer.json:
{
"image": [custom image in a private code repository],
"forwardPorts": [various ports to serve web interfaces],
"runArgs": [
"--cap-add=SYS_PTRACE",
"--security-opt",
"seccomp=unconfined"
],
"extensions": [
"ms-vscode.cpptools",
"ms-vscode.cmake-tools",
"hbenl.vscode-test-explorer",
"derivitec-ltd.cmake-test-adapter",
"ms-dotnettools.csharp",
"fernandoescolar.vscode-solution-explorer",
"derivitec-ltd.vscode-dotnet-adapter"
],
"mounts": [
"source=${localEnv:HOME}/.gitconfig,target=/root/.gitconfig,type=bind,consistency=cached",
"source=${localEnv:HOME}/.ssh,target=/root/.ssh,type=bind,consistency=cached"
]
}
In this set up, we've been able to successfully debug C# and C++ code separately, but the above flow of running the C# project and attaching GDB after it does not work as expected. The C# process exits, while the "(gdb) Attach" call starts multiple processes which run into various exceptions at launch. I've pasted the full output to Pastebin.
Much of the advice I've found is confused due to:
legacy methods such as calling docker directly (omnisharp/omnisharp-vscode issue on debugging in docker)
alternative setups where source code is packaged into a docker container rather than mounted (VS Code docs for debugging .NET Core in docker)
alternative setups where build tools live in a docker container but VS Code communicates with the docker container via SSH rather than using the dev container approach recommended in the docs (Microsoft blog post on developing C++ with VS Code and docker)
C++ seemingly having special requirements for debugging, especially where docker is concerned
The runArgs description in the devcontainer.json reference:
For example, "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ] allows ptrace based debuggers like C++ to work in the container.
VS Code docs suggesting that debugging should work exactly as it does natively when using remote development tools ("Debugging in a container" from VS Code docs)
How should I debug both C# and C++ running within a docker container using VS Code?

Related

Debug Dockerized Flask app in VSCode not breaking on breakpoints

I followed this tutorial to set up debug in my VSCode.
My launch.json file is below.
{
// 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": "Python: Remote Attach",
"type": "python",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}/server/project/views",
"remoteRoot": "/server/project/views"
}
]
}
]
}
My code does break on raised and user uncaught exceptions but it does not break on the breakpoints that I set. The code is reaching the breakpoints and I checked it using print statements, but my breakpoints are not working. VSCode debugger does seem to listen to my docker app (seen in the logs in screenshot) but not sure why it is not breaking at my breakpoints. However, it does give an error saying:
pydev debugger: unable to find translation for:
"/home/vvarma9/DTNetworkRepos/ip2m-metrr/server/project/utils/assessments.py"
in ["/home/vvarma9/DTNetworkRepos/ip2m-metrr/server/project/views/",
"/home/vvarma9/DTNetworkRepos/ip2m-metrr/server/project/views"]
(please revise your path mappings).
Kindly help!
Make sure your local and remote paths are correct. You can check your remote path by logging into the container's terminal. There you can find the absolute path of your "app".
I also cannot tell where you ${workspaceFolder} is actually is. Could be DTNetworkRepos or ip2m-metrr. You will need to make sure you clarify the path.
Also it would help if you posted up your folder stucture, Docker file for the server project and docker compose for all your container projects. Docker file will explain your path on the remote server. Dockerfile & Docker-compose file will ensure us that you have the right cmd or entrypoint for your environment. It may not line up with the tutorial that you set up.

Is there a way to build different projects (different electron-builder file) for electron

We have a white-labeled app built with electron+angular and we want to build 3 different let's say 'flavours' of the app. Except for the UI changes in Angular we have a different electron-builder file with configurations for each project. The problem is that after I build the first one the next one is twice its size (as a .exe) and when I build the third one it's even bigger. It does not matter which I build first, as this is always the case.
I am building these apps with the electron-builder build command, using the --config option to pass a file with configurations.
This is the electron-builder file that I am using (with PROJECT_NAME, PROJECT_APP_ID, and PROJECT_ID changing depending on the project).
"productName": "<PROJECT_NAME>",
"appId": "<PROJECT_APP_ID>",
"directories": {
"output": "release/<PROJECT_ID>"
},
"files": [
"**/*",
"!**/*.ts",
"!*.code-workspace",
"!LICENSE.md",
"!package.json",
"!package-lock.json",
"!src/",
"!e2e/",
"!hooks/",
"!angular.json",
"!_config.yml",
"!karma.conf.js",
"!tsconfig.json",
"!tslint.json"
],
"win": {
"icon": "dist/assets/icons/<PROJECT_ID>"
},
"mac": {
"icon": "dist/assets/icons/<PROJECT_ID>"
},
"linux": {
"icon": "dist/assets/icons/<PROJECT_ID>"
},
}
Am I missing something for electron-builder? I am thinking maybe it keeps a 'cache' or something in a temporary folder and uses that to build on.
I know the question is a bit over the place, but I don't have experience with electron-builder. Any help or suggestion is welcomed.
Some details:
I tried building it from both a windows machine and mac os.
I am using electron-builder v22.9.1
I have tried using different folders for the result, it still didn't work.
[UPDATE] In the script that i use to build these projects, if i delete the directory of the build and then continue with the others, it will work.

Application Insights Telemetry Missing in .Net Core 3 app Running in Docker Container

We have a small API hosted in AKS which was written using .Net core 2.2. It has been working fine and we have seen all our App Insights telemetry in the Azure portal, both in Live Metrics and Log Analytics as expected. We recently encountered a problem during a long running process which gave us an unhelpful error message, but it seems that upgrading to .Net core 3 or higher provides more information when it occurs, so we set about upgrading. We went straight for 3.1, upgraded all packages (including the AI package) to ensure they were all 3.1 compatible, and fixed whatever breaking changes had been introduced. When run in Visual Studio we see our telemetry in Live Metrics and the logs as expected, but the moment we build this into a docker container and run it form there we lose this telemetry. Exceptions are still logged, however.
We are configuring AI with the following in our startup.cs:
services.AddSingleton(typeof(ITelemetryChannel),
new InMemoryChannel() { MaxTelemetryBufferCapacity = 10000 });
services.AddApplicationInsightsTelemetry(new ApplicationInsightsServiceOptions
{
EnableAdaptiveSampling = false,
InstrumentationKey = Configuration.GetValue<string>("ApplicationInsights:InstrumentationKey")
});
I have tried making the buffer larger and smaller, I've downgraded to .Net core 3, I've tried downgrading the Microsoft.ApplicationInsights.AspNetCore package to 2.8.0 (minimum for core 3) since that was what we were using with 2.2 but all to no avail.
I have also looked at what comes out of the container and VS using Fiddler. You can see plenty of chatting to the QuickPulseService (Live Metrics) in both cases, but whereas using VS or the 2.2 version hosted in Docker I can see stuff like this:
"Documents": [
{
"Timestamp": "2020-02-13T11:28:17Z",
"SequenceNumber": 34,
"Content": {
"__type": "TraceTelemetryDocument:#Microsoft.ManagementServices.RealTimeDataProcessing.QuickPulseService",
"CloudRoleInstance": "XXXXXXXX",
"DocumentStreamIds": [
"all-types-default"
],
"DocumentType": "Trace",
"Id": "fc840f65-29a8-48dc-a425-e5b7aacd03a5",
"InternalNodeName": "XXXXXXXX",
"Message": "Finished processing 159 of 159 events in 3.29 seconds",
"OperationName": "POST Publish/Publish",
"Properties": [
{
"key": "totalEvents",
"value": "159"
},
{
"key": "ActionId",
"value": "a825bb45-a286-4f85-95f8-64cd88871f8d"
},
{
"key": "RequestPath",
"value": "/api/publish"
}
],
"SeverityLevel": "Information",
"Timestamp": {
"DateTime": "2020-02-13T11:28:15.309Z",
"OffsetMinutes": 0
},
"Version": "1.1"
},
"Instance": "XXXXXX",
"DocumentStreamIds": [
"all-types-default"
]
}]
Which is the messages I'm expecting to see in AI, when monitoring the core 3 version in docker the QuickPulseService calls contain no documents at all.
I should not that when running in VS or locally using Docker Desktop we have the logging level set to Debug, the same as we used to with .Net core 2.2.
In case it's relevant, here's the dockerfile as well
FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0
WORKDIR /app
COPY --from=build-env /app/out .
CMD ["dotnet", "MyApp.dll"]
I feel like I must have missed some small piece of crucial configuration but having read the .Net core 3 breaking changes list numerous times I cannot work out what that might be.
Has anyone else experienced this and if so, have you managed to solve the problem? Or do you have any ideas/pointers for me because I am stumped.
I recently ran into this problem when updating our .NET Core 2.2 Web API to 3.1. At the same time, I upgraded all of the supporting libraries, including Microsoft.ApplicationInsights.AspNetCore, upgrading it from 2.12.1 to 2.14.0. After I did that, I stopped getting SQL statements in Application Insights. When I downgraded Microsoft.ApplicationInsights.AspNetCore back to 2.12.1 (but keeping everything else the same), SQL statements appeared again in Application Insights.

Debugging webpack dev server using a vs code in a remote docker container

I'm currently creating a boiler plate for react with typescript, one of the things I'd like to do is debug from within vs code however I'm having issues configuring webpack to debug since it's running inside a docker container. Ideally I'd like to debug from my local Chrome but as I'm inside a remote container I can't get the VS code debugger to open Chrome
My launch.json configuration so far:
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost, with sourcemaps",
"url": "http://localhost",
"sourceMaps": true,
"webRoot": "${workspaceRoot}",
"trace": true,
"sourceMapPathOverrides": {
"webpack:///./*": "${webRoot}/*"
}
}
When I attempt to run it though it says "Error processing "launch": Can't find Chrome - install it or set the "runtimeExecutable" field in the launch config.

How to restart a dart server which file changes?

I'm running a web server with dart, it starts by:
dart server.dart
When I modified the project files, I hope this server can be restarted automatically. Is there any way to do it? Or is there any useful tool can help?
Not natively in Dart until bug 3310 is implemented. There may well be external tools that will restart the command line when a file changes (open to other answers).
Just ran into this problem developing a dart server. For vscode IDE, following this stackoverflow suggestion I installed the Save and Run Ext extension and modified it for a dart command line program:
{
"saveAndRunExt": {
"commands": [
{
// "match": "\\.(css$|js$|html$)",
"match": ".dart$",
"isShellCommand": false,
"cmd": "workbench.action.debug.restart",
"isAsync": false
},
{
"match": ".dart$",
"isShellCommand": false,
"cmd": "dart.rerunLastTestDebugSession"
}
]
}
}
This will restart the server in debug mode and rerun the last test debug session if any dart file is saved. Both server and test debug sessions work.
Works great for me, at least on initial use of this extension.

Resources