microsoft / microsoft/vscode-cpptools
Breakpoint is not hit while debugging C dylib called by C# dll
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 6.2k
- Forks
- 1.7k
- Avg merge
- 14h 46m
- Merged PRs (30d)
- 61
Description
Type: Debugger
Describe the bug
-
OS and Version: macOS BigSur 11.2 Apple M1
-
VS Code Version:
Version: 1.54.0-insider
Commit: 52838cf6799cc448e738677ec37e86cf62a5bd89
Date: 2021-02-05T05:15:00.813Z
Electron: 11.2.2
Chrome: 87.0.4280.141
Node.js: 12.18.3
V8: 8.7.220.31-electron.0
OS: Darwin x64 20.3.0 -
C/C++ Extension Version: C/C++ ms-vscode.cpptools v1.2.2-insiders2
-
A clear and concise description of what the bug is.
I'm debugging a C dylib, compiled with debug symbols, which is called by C# Application.
To debug the dylib I tried to attach VS Code debugger to the C# application. The C# applikation is running in Visual Studio Community:
Visual Studio Community 2019 for Mac
Version 8.8.7 (build 18)
Installation UUID: c23948f3-c8b4-4c93-bdf8-3ee445974d4b
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Mac 6.18.0.23 (d16-6 / 088c73638)
Package version: 612000113
Here the VS Code launch.json configuration:
{
"name": "Attach to C#",
"type": "cppdbg",
"request": "attach",
"program": "${workspaceFolder}/../artifacts/bin/SampleMaster/Debug/netcoreapp3.1/SampleMaster.dll",
"processId": "${command:pickProcess}",
"MIMode": "lldb",
"targetArchitecture": "arm64",
"additionalSOLibSearchPath": "${workspaceFolder}/../artifacts/bin/SampleMaster/Debug/netcoreapp3.1",
"setupCommands": [
{
"description": "Enable pretty-printing ",
"text": "-enable-pretty-printing",
"ignoreFailures": false,
}
],
"logging": {
"trace": true,
"traceResponse": true
},
}
Afterer attaching to the process, debugger doesn't stop at breakpoint. The C dylib is intergrated with [DllImport] attribute and invoked by C# application.
VS Code debug console output:
--> E (output): {"type":"event","event":"output","body":{"category":"telemetry","output":"VS/Diagnostics/Debugger/Attach","data":{"VS.Diagnostics.Debugger.ImplementationName":"Microsoft.MIDebugEngine","VS.Diagnostics.Debugger.EngineVersion":"16.5.11030.1","VS.Diagnostics.Debugger.HostVersion":"16.5.11030.1","VS.Diagnostics.Debugger.AdapterId":"cppdbg","VS.Diagnostics.Debugger.Attach.Duration":1122,"VS.Diagnostics.Debugger.MIMode":"lldb"}},"seq":2}
--> R (attach-2): {"type":"response","request_seq":2,"success":true,"command":"attach","body":{},"seq":4}
--> E (initialized): {"type":"event","event":"initialized","body":{},"seq":6}
--> E (process): {"type":"event","event":"process","body":{"startMethod":"attach","name":"/Users/norbertleitl/Projects/ifm/EtherCAT.NET/native/../artifacts/bin/SampleMaster/Debug/netcoreapp3.1/SampleMaster.dll","systemProcessId":4144},"seq":8}
--> E (thread): {"type":"event","event":"thread","body":{"reason":"started","threadId":1},"seq":10}
--> E (thread): {"type":"event","event":"thread","body":{"reason":"started","threadId":2},"seq":12}
--> E (thread): {"type":"event","event":"thread","body":{"reason":"started","threadId":3},"seq":14}
--> E (thread): {"type":"event","event":"thread","body":{"reason":"started","threadId":4},"seq":16}
--> E (thread): {"type":"event","event":"thread","body":{"reason":"started","threadId":5},"seq":18}
--> E (thread): {"type":"event","event":"thread","body":{"reason":"started","threadId":6},"seq":20}
--> E (thread): {"type":"event","event":"thread","body":{"reason":"started","threadId":7},"seq":22}
--> E (thread): {"type":"event","event":"thread","body":{"reason":"started","threadId":8},"seq":24}
--> E (thread): {"type":"event","event":"thread","body":{"reason":"started","threadId":9},"seq":26}
--> E (thread): {"type":"event","event":"thread","body":{"reason":"started","threadId":10},"seq":28}
--> E (thread): {"type":"event","event":"thread","body":{"reason":"started","threadId":11},"seq":30}
--> E (thread): {"type":"event","event":"thread","body":{"reason":"started","threadId":12},"seq":32}
--> E (thread): {"type":"event","event":"thread","body":{"reason":"started","threadId":13},"seq":34}
--> E (thread): {"type":"event","event":"thread","body":{"reason":"started","threadId":14},"seq":36}
--> E (thread): {"type":"event","event":"thread","body":{"reason":"started","threadId":15},"seq":38}
--> E (thread): {"type":"event","event":"thread","body":{"reason":"started","threadId":16},"seq":40}
--> E (thread): {"type":"event","event":"thread","body":{"reason":"started","threadId":17},"seq":42}
<-- C (setBreakpoints-3): {"command":"setBreakpoints","arguments":{"source":{"name":"soem_wrapper.c","path":"/Users/norbertleitl/Projects/ifm/EtherCAT.NET/native/SOEM_wrapper/soem_wrapper.c"},"lines":[972],"breakpoints":[{"line":972}],"sourceModified":false},"type":"request","seq":3}
--> R (setBreakpoints-3): {"type":"response","request_seq":3,"success":true,"command":"setBreakpoints","body":{"breakpoints":[{"id":1,"verified":true,"line":972}]},"seq":45}
--> E (breakpoint): {"type":"event","event":"breakpoint","body":{"reason":"changed","breakpoint":{"id":1,"verified":true,"line":972}},"seq":47}
<-- C (threads-4): {"command":"threads","type":"request","seq":4}
--> R (threads-4): {"type":"response","request_seq":4,"success":true,"command":"threads","body":{"threads":[{"id":1,"name":"Thread #1"},{"id":2,"name":"Thread #2"},{"id":3,"name":"Thread #3"},{"id":4,"name":"Thread #4"},{"id":5,"name":"Thread #5"},{"id":6,"name":"Thread #6"},{"id":7,"name":"Thread #7"},{"id":8,"name":"Thread #8"},{"id":9,"name":"Thread #9"},{"id":10,"name":"Thread #10"},{"id":11,"name":"Thread #11"},{"id":12,"name":"Thread #12"},{"id":13,"name":"Thread #13"},{"id":14,"name":"Thread #14"},{"id":15,"name":"Thread #15"},{"id":16,"name":"Thread #16"},{"id":17,"name":"Thread #17"}]},"seq":50}
<-- C (setFunctionBreakpoints-5): {"command":"setFunctionBreakpoints","arguments":{"breakpoints":[]},"type":"request","seq":5}
--> R (setFunctionBreakpoints-5): {"type":"response","request_seq":5,"success":true,"command":"setFunctionBreakpoints","body":{"breakpoints":[]},"seq":53}
<-- C (configurationDone-6): {"command":"configurationDone","type":"request","seq":6}
--> R (configurationDone-6): {"type":"response","request_seq":6,"success":true,"command":"configurationDone","body":{},"seq":56}
--> E (output): {"type":"event","event":"output","body":{"category":"stdout","output":"=thread-selected,id=\"1\"\n=library-unloaded,id=\"/Users/norbertleitl/Projects/ifm/EtherCAT.NET/artifacts/bin/SampleMaster/Debug/netcoreapp3.1/SampleMaster.dll\",target-name=\"/Users/norbertleitl/Projects/ifm/EtherCAT.NET/artifacts/bin/SampleMaster/Debug/netcoreapp3.1/SampleMaster.dll\",host-name=\"/Users/norbertleitl/Projects/ifm/EtherCAT.NET/artifacts/bin/SampleMaster/Debug/netcoreapp3.1/SampleMaster.dll\"\n"},"seq":58}
=thread-selected,id="1"
=library-unloaded,id="/Users/norbertleitl/Projects/ifm/EtherCAT.NET/artifacts/bin/SampleMaster/Debug/netcoreapp3.1/SampleMaster.dll",target-name="/Users/norbertleitl/Projects/ifm/EtherCAT.NET/artifacts/bin/SampleMaster/Debug/netcoreapp3.1/SampleMaster.dll",host-name="/Users/norbertleitl/Projects/ifm/EtherCAT.NET/artifacts/bin/SampleMaster/Debug/netcoreapp3.1/SampleMaster.dll"
<-- C (threads-7): {"command":"threads","type":"request","seq":7}
--> R (threads-7): {"type":"response","request_seq":7,"success":true,"command":"threads","body":{"threads":[{"id":1,"name":"Thread #1"},{"id":2,"name":"Thread #2"},{"id":3,"name":"Thread #3"},{"id":4,"name":"Thread #4"},{"id":5,"name":"Thread #5"},{"id":6,"name":"Thread #6"},{"id":7,"name":"Thread #7"},{"id":8,"name":"Thread #8"},{"id":9,"name":"Thread #9"},{"id":10,"name":"Thread #10"},{"id":11,"name":"Thread #11"},{"id":12,"name":"Thread #12"},{"id":13,"name":"Thread #13"},{"id":14,"name":"Thread #14"},{"id":15,"name":"Thread #15"},{"id":16,"name":"Thread #16"},{"id":17,"name":"Thread #17"}]},"seq":61}
It seems the C# applikation lib is immediately unloaded after breakpoint setting (library-unloaded,id="/ ......)
I can not see any breakpoint error in the log.
Trying to activate (click) on the breakpoint again generates following log:
<-- C (setBreakpoints-8): {"command":"setBreakpoints","arguments":{"source":{"name":"soem_wrapper.c","path":"/Users/norbertleitl/Projects/ifm/EtherCAT.NET/native/SOEM_wrapper/soem_wrapper.c"},"lines":[],"breakpoints":[],"sourceModified":false},"type":"request","seq":8}
--> R (setBreakpoints-8): {"type":"response","request_seq":8,"success":true,"command":"setBreakpoints","body":{"breakpoints":[]},"seq":58}
<-- C (setBreakpoints-9): {"command":"setBreakpoints","arguments":{"source":{"name":"soem_wrapper.c","path":"/Users/norbertleitl/Projects/ifm/EtherCAT.NET/native/SOEM_wrapper/soem_wrapper.c"},"lines":[972],"breakpoints":[{"line":972}],"sourceModified":false},"type":"request","seq":9}
--> R (setBreakpoints-9): {"type":"response","request_seq":9,"success":true,"command":"setBreakpoints","body":{"breakpoints":[{"id":2,"verified":true,"line":972}]},"seq":61}
--> E (breakpoint): {"type":"event","event":"breakpoint","body":{"reason":"changed","breakpoint":{"id":2,"verified":false,"message":"Attempting to bind the breakpoint....","line":972}},"seq":63}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the launch.json attach configuration, soem_wrapper.c at line 972, and the debug console trace showing the library-unloaded event. Reproduce the C dylib called through DllImport on macOS with LLDB, then determine why the breakpoint becomes unbound; done means the breakpoint is hit during the native call.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, csharp, vscode
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100