Skip to content

libsosplugin cannot be loaded into lldb (macos arm64) #4259

Open

Description

@yuraaka

Description

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

  1. Install dotnet-sos
  2. Run lldb
  3. 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

Other information

No response

Activity

  1. filipnavara commented on Sep 21, 2023

    @filipnavara
    Member

    This is known regression in Xcode. I remember talking with @EgorBo about it so maybe he remembers the details?

  2. filipnavara commented on Sep 21, 2023

    @filipnavara
    Member

    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.

  3. EgorBo commented on Sep 21, 2023

    @EgorBo
    Member
  4. hoyosjs commented on Sep 22, 2023

    @hoyosjs
    Member

    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 )

  5. transferred this issue fromdotnet/runtimeon Sep 25, 2023
  6. added this to the 8.0.0 milestone on Sep 25, 2023
  7. tommcdon commented on Sep 25, 2023

    @tommcdon
    Member

    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.

  8. filipnavara commented on Sep 25, 2023

    @filipnavara
    Member

    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.

  9. tommcdon commented on Sep 25, 2023

    @tommcdon
    Member

    With some Xcode 15 beta I was getting the following error on lldb startup: Error: Fail to initialize coreclr 80070008.

    If you are still seeing this error, we will re-activate this issue to track that particular problem

  10. mikem8361 commented on Sep 25, 2023

    @mikem8361
    Contributor

    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).

  11. 8 remaining items

  12. modified the milestones: 8.0.0, 9.0.0 on Aug 28, 2024
  13. am11 commented on Sep 17, 2024

    @am11
    Member

    With 15.3, it goes straight to sigkill.

    $ xcodebuild -version   
    Xcode 15.3
    Build version 15E204a
    
    $ lldb helloworld/dist/helloworld 
    zsh: killed     lldb helloworld/dist/helloworld

    ~/Library/Logs/DiagnosticReports/lldb-2024-09-17-073242.ips shows:

    "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 command for 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?

    $ 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 arm64
  14. tommcdon commented on Sep 21, 2024

    @tommcdon
    Member

    I believe folks have tried the following workaround with some success - #4551 (comment).

  15. am11 commented on Sep 21, 2024

    @am11
    Member

    Same issue on Sequoia 15.0 and Xcode / llvm / lldb 16.0. (released on Monday / 16th)

    Better workaround with Apple's lldb (standard installation):

    $ sudo cp /Applications/Xcode.app/Contents/Developer/usr/bin/lldb /usr/local/bin
    $ sudo install_name_tool -add_rpath /Applications/Xcode.app/Contents/SharedFrameworks /usr/local/bin/lldb
    $ sudo codesign --force --sign - /usr/local/bin/lldb

    (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.

    cc @lambdageek @janvorli

  16. janvorli commented on Sep 23, 2024

    @janvorli
    Member

    @am11, that's awesome, thank you so much for sharing this workaround!

  17. mikem8361 commented on Sep 23, 2024

    @mikem8361
    Contributor

    Does the C# commands like dumpheap -stat work? We have seen problems initializing the .NET hosting on arm64 MacOS.

  18. am11 commented on Sep 23, 2024

    @am11
    Member

    Does the C# commands like dumpheap -stat work?

    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 -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:

    0001040a92e0     5     8?392 System.Object[]
    000105193d58    39    12?424 System.Int32[]
    000105196e50   805    71?272 System.String
    Total 1?320 objects, 140?633 bytes
    

    (same goes for any non-ASCII char)

  19. modified the milestones: 9.0.0, Future on Oct 1, 2024
  20. tommcdon commented on Oct 1, 2024

    @tommcdon
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions