Xcode - 使用 dyld 环境变量进行调试

文章目录


一、使用 DYLD_PRINT_STATISTICS 获取启动时间

arguments里面加入环境变量 DYLD_PRINT_STATISTICS = 1.

具体设置方法可见文章:ios app获取main函数之前的启动时间
https://www.jianshu.com/p/0e91993b2f4a

这里写图片描述

这里写图片描述

那么是否还有其他方法可以使用呢?
下面列表展示了 dyld 相关变量


二、DYLD_PRINT 变量列表

可以通过 manual page 来访问
或者在终端中输入 man dyld

DYLD_FRAMEWORK_PATH
       DYLD_FALLBACK_FRAMEWORK_PATH
       DYLD_VERSIONED_FRAMEWORK_PATH
       DYLD_LIBRARY_PATH
       DYLD_FALLBACK_LIBRARY_PATH
       DYLD_VERSIONED_LIBRARY_PATH
       DYLD_PRINT_TO_FILE
       DYLD_SHARED_REGION
       DYLD_INSERT_LIBRARIES
       DYLD_FORCE_FLAT_NAMESPACE
       DYLD_IMAGE_SUFFIX
       DYLD_PRINT_OPTS
       DYLD_PRINT_ENV
       DYLD_PRINT_LIBRARIES
       DYLD_BIND_AT_LAUNCH
       DYLD_DISABLE_DOFS
       DYLD_PRINT_APIS
       DYLD_PRINT_BINDINGS
       DYLD_PRINT_INITIALIZERS
       DYLD_PRINT_REBASINGS
       DYLD_PRINT_SEGMENTS
       DYLD_PRINT_STATISTICS
       DYLD_PRINT_DOFS
       DYLD_PRINT_RPATHS
       DYLD_SHARED_CACHE_DIR
       DYLD_SHARED_CACHE_DONT_VALIDATE

这里列举一下常用的以及描述

Environment variable Description
DYLD_PRINT_LIBRARIES Logs when images are loaded. 镜像文件加载后打印
DYLD_PRINT_LIBRARIES_POST_LAUNCH Logs when images are loaded as a result of a dlopen call. Includes a dynamic libraries’ dependent libraries.
DYLD_PRINT_STATISTICS Logs statistical information on an application’s launch process, such as how many images were loaded, when the application finishes launching.
DYLD_PRINT_INITIALIZERS Logs when the dynamic loader calls initializer and finalizer functions.
DYLD_PRINT_SEGMENTS Logs when the dynamic loader maps a segment of a dynamic library to the current process’s address space.
DYLD_PRINT_BINDINGS Logs when the dynamic loader binds an undefined external symbol with its definition. 动态库绑定未定义的外部符号文件。

三、调试示例


1、DYLD_PRINT_LIBRARIES

打印内容如下(不全),这里只截取前面几个文件。

dyld: loaded: /Users/administrator/Library/Developer/CoreSimulator/Devices/7E3D7605-368C-4DA1-BE76-1100849590C3/data/Containers/Bundle/Application/C503DC1E-4CE2-4A7E-A283-6406F6A43595/SocketDemo.app/SocketDemo
dyld: loaded: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libBacktraceRecording.dylib
dyld: loaded: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libMainThreadChecker.dylib
dyld: loaded: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib
dyld: loaded: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/Foundation.framework/Foundation
dyld: loaded: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libobjc.A.dylib
dyld: loaded: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libSystem.dylib
dyld: loaded: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
dyld: loaded: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/UIKit.framework/UIKit

可以发现,大都是 dylib 或者可执行文件。


2、DYLD_PRINT_LIBRARIES_POST_LAUNCH

dyld: loaded: /Users/administrator/Library/Developer/CoreSimulator/Devices/7E3D7605-368C-4DA1-BE76-1100849590C3/data/Containers/Bundle/Application/6C837C0F-CEDE-4215-B2B4-E67BADAB30BE/SocketDemo.app/SocketDemo
dyld: loaded: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libBacktraceRecording.dylib
dyld: loaded: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libMainThreadChecker.dylib
dyld: loaded: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib
dyld: loaded: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/Foundation.framework/Foundation
dyld: loaded: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libobjc.A.dylib
dyld: loaded: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libSystem.dylib
dyld: loaded: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
dyld: loaded: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/UIKit.framework/UIKit


可以发现,几乎和 DYLD_PRINT_LIBRARIES 一致。


3、DYLD_PRINT_STATISTICS

打印内容如下

Total pre-main time: 1.5 seconds (100.0%)
         dylib loading time: 531.66 milliseconds (33.2%)
        rebase/binding time: 876.81 milliseconds (54.8%)
            ObjC setup time:  60.85 milliseconds (3.8%)
           initializer time: 130.36 milliseconds (8.1%)
           slowest intializers :
               libSystem.dylib :  68.74 milliseconds (4.2%)
    libMainThreadChecker.dylib :  43.35 milliseconds (2.7%)

4、DYLD_PRINT_INITIALIZERS

dyld: calling initializer function 0x1014f69ee in /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libSystem.dylib
dyld: calling -init function 0x10041632a in /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libBacktraceRecording.dylib
dyld: calling initializer function 0x102a172ba in /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libc++.1.dylib
dyld: calling -init function 0x1014fe1f0 in /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
dyld: calling initializer function 0x10165e8f0 in /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
dyld: calling initializer function 0x1058804e0 in /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libnetwork.dylib

5、DYLD_PRINT_SEGMENTS

dyld: Main executable mapped /Users/administrator/Library/Developer/CoreSimulator/Devices/7E3D7605-368C-4DA1-BE76-1100849590C3/data/Containers/Bundle/Application/557FC56B-A0E1-4F55-A06D-AF74862C032F/SocketDemo.app/SocketDemo
        __PAGEZERO at 0x00000000->0x100000000
            __TEXT at 0x1046E9000->0x1046ED000
            __DATA at 0x1046ED000->0x1046EF000
        __LINKEDIT at 0x1046EF000->0x1046F7000
dyld: Mapping /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libBacktraceRecording.dylib
            __TEXT at 0x10477A000->0x104781FFF with permissions r.x
            __DATA at 0x104782000->0x104782FFF with permissions rw.
        __LINKEDIT at 0x104783000->0x104788AFF with permissions r..

6、DYLD_PRINT_BINDINGS

一直打印,很疯狂
这就是所谓的动态绑定?


dyld: bind: GeoServices:0x11660C620 = libobjc.A.dylib:__objc_empty_cache, *0x11660C620 = 0x10373A610
dyld: bind: GeoServices:0x11660C648 = libobjc.A.dylib:__objc_empty_cache, *0x11660C648 = 0x10373A610
dyld: bind: GeoServices:0x11660C670 = libobjc.A.dylib:__objc_empty_cache, *0x11660C670 = 0x10373A610
dyld: bind: GeoServices:0x11660C698 = libobjc.A.dylib:__objc_empty_cache, *0x11660C698 = 0x10373A610
dyld: bind: GeoServices:0x11660C6C0 = libobjc.A.dylib:__objc_empty_cache, *0x11660C6C0 = 0x10373A610
dyld: bind: GeoServices:0x11660C6E8 = libobjc.A.dylib:__objc_empty_cache, *0x11660C6E8 = 0x10373A610

dyld: bind: Contacts:0x1142B71C0 = libobjc.A.dylib:_OBJC_METACLASS_$_NSObject, *0x1142B71C0 = 0x103DCAE58
dyld: bind: Contacts:0x1142B71C8 = libobjc.A.dylib:_OBJC_METACLASS_$_NSObject, *0x1142B71C8 = 0x103DCAE58
dyld: bind: Contacts:0x1142B7210 = libobjc.A.dylib:_OBJC_METACLASS_$_NSObject, *0x1142B7210 = 0x103DCAE58


dyld: bind: vCard:0x1173B4DC0 = libobjc.A.dylib:_OBJC_METACLASS_$_NSObject, *0x1173B4DC0 = 0x103DCAE58
dyld: bind: vCard:0x1173B4E08 = libobjc.A.dylib:_OBJC_METACLASS_$_NSObject, *0x1173B4E08 = 0x103DCAE58
dyld: bind: vCard:0x1173B4E10 = libobjc.A.dylib:_OBJC_METACLASS_$_NSObject, *0x1173B4E10 = 0x103DCAE58
dyld: bind: vCard:0x1173A2068 = libobjc.A.dylib:___objc_personality_v0, *0x1173A2068 = 0x10371EF69
dyld: bind: vCard:0x1173B3838 = libobjc.A.dylib:__objc_empty_cache, *0x1173B3838 = 0x10373A610
dyld: bind: vCard:0x1173B3860 = libobjc.A.dylib:__objc_empty_cache, *0x1173B3860 = 0x10373A610
dyld: bind: vCard:0x1173B3888 = libobjc.A.dylib:__objc_empty_cache, *0x1173B3888 = 0x10373A610


原文地址:https://blog.csdn.net/lovechris00/article/details/82290773

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


在有效期内的苹果开发者账号(类型为个人或者公司账号)。还有一种情况,就是你的Apple ID被添加到公司开发者账号团队里面,这样也是可以的,但是需要叫管理员给你开通相应的账号权限,如下截图:这里可能有些同学会问,苹果开发者账号是什么?如何申请?那么可以看看我的上一篇文章:iOS苹果开发者账号(公司账号)申请流程详解能正常编译打包的iOS工程项目(都不能正常编译谈何出包上架
Appuploader官网--IOS ipa上传发布工具,证书制作工具跨平台版,windows,linux,mac系统都可用 (applicationloader.net)第一步:注册苹果开发者账号,访问以下网址,按照提示注册即可,因为不需要支付688认证苹果开发者,所以没什么好讲的。证书部分:主要是通过工具生成.p12证书文件,后面这个证书要导入mac系统。描述文件:这个文件主要包含了证书,公钥,设备信息等,具体可以百度了解详情。第三步:使用xcode打包导出ipa文件,供其他人内测。..........
苹果在9月13号凌晨(北京时间)发布 iOS 16,该系统的设备可能会因为各种原因,导致功能不可用和UI错乱等问题,我们需要做好适配iOS 16。
计算机图形学--OpenGL递归实现光线追踪
Xcode 14打出来的包在低版本系统运行时会崩溃,报错信息是Library not loaded: /usr/lib/swift/libswiftCoreGraphics.dylib,在苹果开发者论坛搜索报错信息,可以看到会闪退的最高版本是iOS12.1(不敢肯定,毕竟我没测过,不过肯定低于iOS 12.4
iOS16手机开启开发者模式 "developer mode disable"Pod工程中的Bundle target签名报错
【计算机图形学】【实验报告】DDA画线算法、Bresenham中点画线算法、多边形填充算法(附代码)
iOS 16 满载全新的个性化功能、更具深度的智能技术,以及更多无缝的沟通与共享方式,让 iPhone 的体验更进一步。13、隐私权限增强,如通过 UIDevice 获取设备名称时,无法获取用户的信息,只能获取设备对应的名称。
3、回到苹果开发者中心,如下图,点击certificates,点蓝色小加号,就可以开始创建证书,创建证书的时候无论测试还是上传app store打包,都要选ios distribution app store and adhoc,不要选apple和develpment类型的证书。2、如下图,点左边的profiles菜单,点击蓝色加号,创建描述文件,创建过程中会要求我们选择描述文件的类型,假如你想发布app到app store,则选择app store,假如你想真机测试,则选择ad hoc类型。
需要:Unity,IOS平台模块,Xcode,IOS_SDk,MAC电脑,Iphone手机
最近下载安装 xcode 并解压安装,遇到一些问题误以为是错误,记录在此。从百度和谷歌上搜了很多帖子,发现并没有靠谱的 xcode 国内的镜像,这里提供一个可以跳转到官网的下载方式。xcode 不同版本的列表,下载时注意不同 macOs 不同的系统和 Xcode 版本的对应关系。如 要求 及其以上版本。https://xcodereleases.com/注意点击后会跳到官方下载地址,需要登录苹果账号。xcode 文件很大,通常要 10G 以上,下载速度很慢。可以考虑使用 Free Downlo
使用苹果登录作为第三方登录
missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun解决方法
Xcode14 正式版编译报错' does not contain bitcode.You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. file 'xxx' for architecture arm64解决方案
那应该和升级Xcode 14有关系。但是官方还没有给出解决方案。应该后续会有兼容的cocoapods 新版本。
项目中需要用到Xcode将C++代码输出的Mac版本的DLL文件即DYLIB文件,并能够使用C#代码调用。Unity与 DLL文件 ☀️| 怎样使用VC++生成一个DLL文件并调用!这次来看一下在Mac使用Xcode生成的方法吧!本文介绍了在Mac中怎样使用 Xcode项目使用C++生成 .dylib文件的方法。相对于在Windows中使用AndroidStudio创建动态链接库的方法来说,使用Xcode创建.dylib文件确实简单了很多。