You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
libsosplugin cannot be loaded into lldb (macos arm64) #4259
I try to install dotnet-sos to get an ability to debug dotnet programs on mac, but after installing it according to this manual, lldb shows error on startup:
$ lldb
error: this file does not represent a loadable dylib
error: 'setsymbolserver' is not a valid command.
(lldb)
Futher context:
$ cat .lldbinit
#START - ADDED BY SOS INSTALLER
plugin load /Users/yuraaka/.dotnet/sos/libsosplugin.dylib
setsymbolserver -ms
#END - ADDED BY SOS INSTALLER
Also, I tried to build libsosplugin from source, but got the same result.
What do I do wrong?
Reproduction Steps
Install dotnet-sos
Run lldb
Get an error
Expected behavior
No error is appeared
Actual behavior
Error "this file does not represent a loadable dylib".
Regression?
No response
Known Workarounds
No response
Configuration
Apple M2 Max
macOS Ventura 13.5.2
$ lldb -v
lldb-1403.0.17.67
Apple Swift version 5.8.1 (swiftlang-5.8.0.124.5 clang-1403.0.22.11.100)
$ dotnet-sos --version
7.0.442301+6245a3eeff5a12218eb5b615788d776027133e91
I tracked down the Discord thread where we discussed it. Apparently it was broken in Xcode 14.3.1 and worked in Xcode 15 (which has different problems, so beware). A more detailed description was also cross posted to Apple forum.
Apologies - I should have updated the forum thread after our discussion with Apple. They very promptly solved the issue in their codebase. It's just now becoming available with Xcode 15 (although things seem to have some issues there right now that need some investigation cc @mikem8361 )
Apparently it was broken in Xcode 14.3.1 and worked in Xcode 15 (which has different problems, so beware). A more detailed description was also cross posted to Apple forum.
@filipnavara are any of the different problems issues we should investigate, and if so would you mind opening new issues to track it? It also sounds like we can close this particular bug because SOS loading is now fixed in XCode 15, so I will close this issue.
are any of the different problems issues we should investigate, and if so would you mind opening new issues to track it?
I am not sure. I will file separate issue if necessary. With some Xcode 15 beta I was getting the following error on lldb startup: Error: Fail to initialize coreclr 80070008.
Yes, I've repro'ed the Error: Fail to initialize coreclr 80070008 error on our M1. Initializing the managed hosting layer is failing for some reason which means managed commands like dumpheap and eeheap won't work. We will continue to investigate but Apple has made debugging this scenario difficult (can not attach to lldb to debug SOS).
"exception" : {"port":0,"signal":"SIGKILL","guardId":0,"codes":"0x0000000000000000, 0x0000000000000000","violations":["SET_EXCEPTION_BEHAVIOR"],"message":" SET_EXCEPTION_BEHAVIOR on mach port 0 (guarded with 0x0000000000000000)","subtype":"GUARD_TYPE_MACH_PORT","type":"EXC_GUARD","rawCodes":[0,0]},
with PAL_MachExceptionMode=7, it just fails to load the plugin:
$ PAL_MachExceptionMode=7 lldb helloworld/dist/helloworld
SOS_HOSTING: Fail to initialize hosting runtime '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/6.0.29/libcoreclr.dylib' 80004005
Unrecognized command'setsymbolserver' because managed hosting failed or was disabled. See sethostruntime commandfor details.
(lldb) target create "helloworld/dist/helloworld"
Current executable set to '/Users/adeel/projects/helloworld/dist/helloworld' (arm64).
both are arm64 binaries, so this is about something else?
(I chose /usr/local/bin/lldb since it is in PATH before /usr/bin)
Now open a new terminal and start using lldb with libsosplugin (clrstack -f etc. are working). There is no need to specify entitlements or setting PAL_MachExceptionMode. It's just that the Apple's lldb doesn't have any entitlement set, so plugin dylib with different signature fails to load. With adhoc, apparently it's not required to specify the entitlements.
Apparently working (when the program is stopped at the exception):
(lldb) dumpheap -stat
Statistics:
MT Count TotalSize Class Name
000102ed9f50 124 System.Reflection.Metadata.TypeNameParseOptions
000102958248124 System.Collections.Generic.StringEqualityComparer
00010295be88 124 System.OrdinalCaseSensitiveComparer
00010295b488 124 System.Collections.Generic.NonRandomizedStringEqualityComparer+OrdinalIgnoreCaseComparer
...
Total 1,307 objects, 133,745 bytes
@mikem8361 btw #52 is still relavant for lldb/Unix, e.g. if a class name has a unicode char dumpheap -stat renders ? (NörttiNirvana became N?rttiNirvana), while Console.WriteLine output in lldb REPL prints it correctly. So it's probably related to direct vs. indirect stdout (via lldb APIs). I had to switch to en-US to get , number grouping separator because the Finnish one has non-breaking space (char code 160) as a grouping separator, which was looking like:
Activity
filipnavara commentedon Sep 21, 2023
This is known regression in Xcode. I remember talking with @EgorBo about it so maybe he remembers the details?
filipnavara commentedon Sep 21, 2023
I tracked down the Discord thread where we discussed it. Apparently it was broken in Xcode 14.3.1 and worked in Xcode 15 (which has different problems, so beware). A more detailed description was also cross posted to Apple forum.
EgorBo commentedon Sep 21, 2023
cc @hoyosjs
hoyosjs commentedon Sep 22, 2023
Apologies - I should have updated the forum thread after our discussion with Apple. They very promptly solved the issue in their codebase. It's just now becoming available with Xcode 15 (although things seem to have some issues there right now that need some investigation cc @mikem8361 )
tommcdon commentedon Sep 25, 2023
@filipnavara are any of the different problems issues we should investigate, and if so would you mind opening new issues to track it? It also sounds like we can close this particular bug because SOS loading is now fixed in XCode 15, so I will close this issue.
filipnavara commentedon Sep 25, 2023
I am not sure. I will file separate issue if necessary. With some Xcode 15 beta I was getting the following error on
lldbstartup:Error: Fail to initialize coreclr 80070008.tommcdon commentedon Sep 25, 2023
If you are still seeing this error, we will re-activate this issue to track that particular problem
mikem8361 commentedon Sep 25, 2023
Yes, I've repro'ed the
Error: Fail to initialize coreclr 80070008error on our M1. Initializing the managed hosting layer is failing for some reason which means managed commands likedumpheapandeeheapwon't work. We will continue to investigate but Apple has made debugging this scenario difficult (can not attach to lldb to debug SOS).8 remaining items
am11 commentedon Sep 17, 2024
With 15.3, it goes straight to sigkill.
~/Library/Logs/DiagnosticReports/lldb-2024-09-17-073242.ipsshows:with PAL_MachExceptionMode=7, it just fails to load the plugin:
both are arm64 binaries, so this is about something else?
$ file ~/.dotnet/sos/libsosplugin.dylib /usr/local/share/dotnet/shared/Microsoft.NETCore.App/6.0.29/libcoreclr.dylib /Users/adeel/.dotnet/sos/libsosplugin.dylib: Mach-O 64-bit dynamically linked shared library arm64 /usr/local/share/dotnet/shared/Microsoft.NETCore.App/6.0.29/libcoreclr.dylib: Mach-O 64-bit dynamically linked shared library arm64tommcdon commentedon Sep 21, 2024
I believe folks have tried the following workaround with some success - #4551 (comment).
am11 commentedon Sep 21, 2024
Same issue on Sequoia 15.0 and Xcode / llvm / lldb 16.0. (released on Monday / 16th)
Better workaround with Apple's lldb (standard installation):
(I chose
/usr/local/bin/lldbsince it is in PATH before/usr/bin)Now open a new terminal and start using
lldbwith libsosplugin (clrstack -fetc. are working). There is no need to specify entitlements or settingPAL_MachExceptionMode. It's just that the Apple's lldb doesn't have any entitlement set, so plugin dylib with different signature fails to load. With adhoc, apparently it's not required to specify the entitlements.cc @lambdageek @janvorli
janvorli commentedon Sep 23, 2024
@am11, that's awesome, thank you so much for sharing this workaround!
mikem8361 commentedon Sep 23, 2024
Does the C# commands like
dumpheap -statwork? We have seen problems initializing the .NET hosting on arm64 MacOS.am11 commentedon Sep 23, 2024
Apparently working (when the program is stopped at the exception):
(lldb) dumpheap -stat Statistics: MT Count TotalSize Class Name 000102ed9f50 1 24 System.Reflection.Metadata.TypeNameParseOptions 000102958248 1 24 System.Collections.Generic.StringEqualityComparer 00010295be88 1 24 System.OrdinalCaseSensitiveComparer 00010295b488 1 24 System.Collections.Generic.NonRandomizedStringEqualityComparer+OrdinalIgnoreCaseComparer ... Total 1,307 objects, 133,745 bytes@mikem8361 btw #52 is still relavant for lldb/Unix, e.g. if a class name has a unicode char
dumpheap -statrenders?(NörttiNirvanabecameN?rttiNirvana), while Console.WriteLine output in lldb REPL prints it correctly. So it's probably related to direct vs. indirect stdout (via lldb APIs). I had to switch to en-US to get , number grouping separator because the Finnish one has non-breaking space (char code 160) as a grouping separator, which was looking like:(same goes for any non-ASCII char)
Update SOS FAQ with MacOS M1 lldb workaround
Update SOS FAQ with MacOS M1 lldb workaround (#4959)
tommcdon commentedon Oct 1, 2024
Limitation due to default signing and entitlements on macOS lldb. Workaround documented here: https://github.com/dotnet/diagnostics/blob/main/documentation/FAQ.md. Moving to Future and marking as
tracking-external-issue.Update SOS FAQ with MacOS M1 lldb workaround (dotnet#4959)