43

I'm trying to profile a Swift application in Instruments and am having difficulty because debug symbols for libswiftCore.dylib and libswiftFoundation.dylib libraries are not being displayed. The mouseover text suggests using File -> Symbols to manually select the dSYM files but I have no idea where they are stored, or even if they exist. Symbols from code that I've written are appearing fine.

I set up a test project and profiled it in instruments to demonstrate:

Symbols from libSwiftCore.dylib are not available

How can I identify the functions shown from libswiftCore.dylib?

Noah Wilder
  • 1,656
  • 20
  • 38
rankAmateur
  • 2,067
  • 2
  • 18
  • 22
  • 1
    No I didn't, all I thought of was that I could do a workaround and write my own (one-line) functions that each just called a Swift function. That way I could check which of my functions were being called and then I'd know which Swift method was which. It's not a great solution though. – rankAmateur Mar 03 '15 at 08:57

4 Answers4

1

If you have installed Xcode in the default location, the swift dylib files can be found in:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/

(Please note, these are not dSYM files) Under this directory you will find a subdirectory for the different build targets, for example, macosx for OS X, iphoneos for iOS devices and iphonesimulator for the simulator etc. (browse to the lib folder to view what's there)

Loading the correct file from one of these folders should hopefully work.

If all else fails you may need to build your own copy of the swift libraries with debug symbols form the source code which can be found at https://github.com/apple/swift

Alok C
  • 2,787
  • 3
  • 25
  • 44
discorevilo
  • 148
  • 1
  • 6
1

This answer is copied from https://github.com/Flash3001/iOSCharts.Xamarin/issues/17

by: Flash3001

but hope this will help you:

The file is located in: /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS

Before:

<Target Name="_CalculateCodesignAppBundleInputs" Condition="'$(_RequireCodeSigning)' == 'true'">
        <ItemGroup>
            <_CodesignAppBundleInput Include="$(_NativeExecutable)" />
            <_CodesignAppBundleInput Include="$(_AppBundlePath)Info.plist" />
            <_CodesignAppBundleInput Include="$(_AppBundlePath)embedded.mobileprovision" />
            <_CodesignAppBundleInput Include="$(DeviceSpecificIntermediateOutputPath)Entitlements.xcent" />
            <_CodesignAppBundleInput Include="@(_BundleResourceWithLogicalName)" />
            <_CodesignAppBundleInput Include="@(_NativeLibrary)" />
            <_CodesignAppBundleInput Include="@(_Frameworks)" />
            <_CodesignAppBundleInput Include="@(_ResolvedAppExtensionReferences -> '$(_AppBundlePath)PlugIns\%(FileName)%(Extension)\_CodeSignature\CodeResources')" Condition="'$(IsAppExtension)' == 'false'" />

            <!-- Include WatchOS1 App references -->
            <_CodesignAppBundleInput Include="@(_ResolvedWatchAppReferences -> '$(_AppBundlePath)%(FileName)%(Extension)\_CodeSignature\CodeResources')" Condition="'$(IsAppExtension)' == 'true'" />

            <!-- Include WatchOS2 App references -->
            <_CodesignAppBundleInput Include="@(_ResolvedWatchAppReferences -> '$(_AppBundlePath)Watch\%(FileName)%(Extension)\_CodeSignature\CodeResources')" Condition="'$(OutputType)' == 'Exe'" />
        </ItemGroup>
    </Target>

    <Target Name="_CodesignAppBundle" Condition="'$(_RequireCodeSigning)' == 'true'" DependsOnTargets="$(_CodesignAppBundleDependsOn)"
        Inputs="@(_CodesignAppBundleInput)"
        Outputs="$(DeviceSpecificIntermediateOutputPath)codesign\$(_AppBundleName)$(AppBundleExtension)">

After:

<Target Name="_CalculateCodesignAppBundleInputs" Condition="'$(_RequireCodeSigning)' == 'true'">
        <ItemGroup>
            <_CodesignAppBundleInputs Include="$(_AppBundlePath)**\*.*" Exclude="$(_AppBundlePath)_CodeSignature\CodeResources" />
        </ItemGroup>
    </Target>

    <Target Name="_CodesignAppBundle" Condition="'$(_RequireCodeSigning)' == 'true'" DependsOnTargets="$(_CodesignAppBundleDependsOn)"
        Inputs="@(_CodesignAppBundleInputs)" Outputs="$(_AppBundlePath)_CodeSignature\CodeResources">

Warning: Do not copy the entire file, as it will break other things. Warning 2: You should not normally modify this file, as it is Xamarin's and can stop the build process from working if you do the wrong thing. Warning 3: It will be replaced when you update Xamarin.

hood
  • 65
  • 1
  • 9
0

You can find the dSym files in your archives under xcode-> Window -> Organizer -> Archives choose the proper version of your build -> Show in finder -> Show Package Contents => you'll find a "dSYMs" folder there.

You could load them into the Instruments application.

Edward Ashak
  • 2,411
  • 2
  • 23
  • 38
  • 2
    This is not what is asked. He is not looking for symbols of his app, he wants the system symbols. – Léo Natan Jul 17 '15 at 15:50
  • Leo is right. Both rankAmateur and me are looking for symbols of deep deep internals of iOS libraries. I have all the app symbols since they are generated automatically, the same symbols for Core and other libraries. I guess I'm missing symbols for C libraries used inside iOS libraries. – Lukasz Czerwinski Jul 17 '15 at 20:28
  • @LukaszCzerwinski The problem is, the Swift libraries are not internal C libraries, which actually have symbols from the SDK. Since the Swift libraries are embedded with the final bundle, perhaps Xcode is stripping them. Can you disable stripping and see if that helps? – Léo Natan Jul 18 '15 at 02:19
  • @LeoNatan Thanks for your reply. Did you mean "Strip Debug Symbols During Copy"? It had already been set to No in my project. – Lukasz Czerwinski Jul 20 '15 at 19:44
0

As I am assuming you want the meanings of commands

Compilation command looks something like:

swift -frontend -gnone -O -Xfrontend -disable-red-zone -Xcc -mno-red-zone -Xcc -mno-mmx -Xcc -mno-sse -Xcc -mno-sse2 -parse-as-library -import-objc-header -whole-module-optimization -module-name MyModule -emit-object -o -gnone disables debug information which probably isn't very useful until you have some sort of debugger support

-O is for optimisation, the other options being -Onone which turns it off but produces a larger amount of code and -Ounchecked which is -O but without extra checks after certain operations. -O produces good code but does tend to inline everything into one big function which can make it hard to workout what went wrong when an exception handler simply gives the instruction pointer as the source of an error.

-Xfrontend -disable-red-zone ensures that code generated from the swiftc doesn't generate red zone code.

-Xcc -mno-red-zone tells the clang compiler not to use the red zone on any files it compiles. clang is used if there is any code in the header file you use which will probably be the case as will be shown.

-Xcc -mno-mmx -Xcc -mno-sse -Xcc -mno-sse2 uses clang options to tell swiftc not to use MMX/SSE/SSE2

-parse-as-library means that the code is not a script.

-import-objc-header allows a .h header file to be imported that allows access to C function and type definitions.

-module-name is required although is only used in fully qualifying the method and function names. However actual module files are not created with this option.

Libraries

Now that a .o ELF file has been produced it needs to be linked to a final executable. Swift requires that its stdlib is linked in as this provides some basic functions that are needed by Swift at runtime.

The library name is libswiftCore.a and should be in lib/swift_static/linux under the install directory.

libswiftCore.a relies on libc, libcpp and a few other system libraries however they wont be available so the missing functions need to be emulated. The full list of symbols that need to be implemented can be found here :- https://github.com/spevans/swift-project1/blob/master/doc/symbols.txt

hood
  • 65
  • 1
  • 9