Xcode崩溃调试

xcode还是比较好用的,搜索方便,只有充分的摸索各个窗口能找到各种信息。

可以在下面console台输入命令行查看:

thread info :可以查看当前断点线程的信息,如果再加上一个数字参数表示查看某个线程号的信息

thread backtrace: 可以查看调用栈

 

1.EXEC_BAD_ACCESS

 

有时候在程序出错的时候不能能准确定位到崩溃那一行代码,而是直接跑到main循环或者Appdelegate里面, 或者会给你

EXEC_BAD_ACCESS的提示。如下图,在断点的导航面板建立了exception断点全局断点,这样只要遇到错误,debug程序就会自动定位到栈底的信息,也就是你最先出错的代码的那一行

 

2.Symbolic Breakpoint

如上图,第四个,增加函数断点,输入要断的函数名 funcxxx,这样一来,在程序中所有的 funcxxx 方法被调用时都会触发断点。

 

3.instruments性能分析工具

https://blog.csdn.net/ggghub/article/details/50325637

4.lldb的常用命令

https://juejin.im/post/5c8702db5188257ded10db58

1.help

 

2.print

 

3.expression

 

4.breakpoint

 


 

5.malloc: pointer being freed was not allocated set a breakpoint in malloc_error_break to debug

崩溃时候的日志

appname(3781,0x1084fabc0) malloc: *** error for object 0x14984b210: pointer being freed was not allocated
appname(3781,0x1084fabc0) malloc: *** set a breakpoint in malloc_error_break to debug

输入lldb调试器命令 bt 看栈信息 (thread info  、   thread backtrace

或者

直接选中左侧的栈信息,复制粘贴到文本,这个比较详细(直接bt不会显示出下文中加粗的部分)

 

#0  0x000000022947a0dc in __pthread_kill ()
#1  0x00000002294f79b0 in pthread_kill$VARIANT$armv81 ()
#2  0x00000002293d3ea8 in abort ()
#3  0x00000002294cd780 in malloc_vreport ()
#4  0x00000002294cd938 in malloc_report ()
#5  0x00000002294c05e8 in free ()
#6  0x00000001057adaa8 in b2Free(void*) at /Users/mobile/Downloads/CliNet6/CliNet/base/b2Settings.cpp:33
#7  0x00000001057ac214 in b2BlockAllocator::~b2BlockAllocator() at /Users/mobile/Downloads/CliNet6/CliNet/base/b2BlockAllocator.cpp:88
#8  0x00000001057ac240 in b2BlockAllocator::~b2BlockAllocator() at /Users/mobile/Downloads/CliNet6/CliNet/base/b2BlockAllocator.cpp:82
#9  0x000000010519b00c in delete_internal<b2World> [inlined] at /Users/builduser/buildslave/unity/build/Runtime/Allocator/MemoryMacros.h:187
#10 0x000000010519b008 in ::DestroyWorld() at /Users/builduser/buildslave/unity/build/Modules/Physics2D/Public/PhysicsScene2D.cpp:176
#11 0x0000000105176048 in ::RecreateWorld() at /Users/builduser/buildslave/unity/build/Modules/Physics2D/PhysicsManager2D.cpp:500
#12 0x0000000105066c24 in Invoke [inlined] at /Users/builduser/buildslave/unity/build/Runtime/Core/Callbacks/CallbackArray.h:70
#13 0x0000000105066c04 in ::Invoke() at /Users/builduser/buildslave/unity/build/Runtime/Core/Callbacks/CallbackArray.h:331
#14 0x0000000105056518 in ::UnloadGameScene() at /Users/builduser/buildslave/unity/build/Runtime/Misc/SceneUnloading.cpp:63
#15 0x000000010506f014 in ::PlayerLoadSceneFromThread() at /Users/builduser/buildslave/unity/build/Runtime/PreloadManager/LoadSceneOperation.cpp:628
#16 0x000000010506f15c in ::CompleteLoadFirstScene() at /Users/builduser/buildslave/unity/build/Runtime/PreloadManager/LoadSceneOperation.cpp:674
#17 0x000000010506ee24 in ::IntegrateMainThread() at /Users/builduser/buildslave/unity/build/Runtime/PreloadManager/LoadSceneOperation.cpp:351
#18 0x000000010506fcc4 in ::UpdatePreloadingSingleStep() at /Users/builduser/buildslave/unity/build/Runtime/PreloadManager/PreloadManager.cpp:431
#19 0x0000000105070374 in ::UpdatePreloading() at /Users/builduser/buildslave/unity/build/Runtime/PreloadManager/PreloadManager.cpp:568
#20 0x000000010532a24c in ::UnityPlayerLoopImpl() at /Users/builduser/buildslave/unity/build/PlatformDependent/iPhonePlayer/LibEntryPoint.mm:281
#21 0x0000000104b00b28 in ::UnityRepaint() at /Users/mobile/Documents/workspace/Dios/MClient/Build/unity2018withlib/101/Classes/UnityAppController+Rendering.mm:277
#22 0x0000000104b00a04 in ::-[UnityAppController(Rendering) repaintDisplayLink]() at /Users/mobile/Documents/workspace/Dios/MClient/Build/unity2018withlib/101/Classes/UnityAppController+Rendering.mm:71
#23 0x00000001083d49fc in -[DYDisplayLinkInterposer forwardDisplayLinkCallback:] ()
#24 0x000000022dc64f90 in CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) ()
#25 0x000000022dd2eb10 in display_timer_callback(__CFMachPort*, void*, long, void*) ()
#26 0x0000000229848a8c in __CFMachPortPerform ()
#27 0x000000022986f690 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ ()
#28 0x000000022986eddc in __CFRunLoopDoSource1 ()
#29 0x0000000229869c00 in __CFRunLoopRun ()
#30 0x00000002298690b0 in CFRunLoopRunSpecific ()
#31 0x000000022ba6979c in GSEventRunModal ()
#32 0x00000002560d5978 in UIApplicationMain ()
#33 0x0000000104af7f50 in main at /Users/mobile/Documents/workspace/Dios/MClient/Build/unity2018withlib/101/Classes/main.mm:41
#34 0x000000022932e8e0 in start ()
 

错误原因:本来是执行unity中的源码,但是后来执行到了网络库中的一个free函数了,原因是unity中和网络库CliNet中一个类重名了b2BlockAllocator类【xcode编译过去了有warning(我没看)】。

而且两个类的同名函数实现不一致。

在静态链接的过程中,会进行符号的解析,如果有多个同名符号会根据一个规则最终选择一个符号的地址。

上面可以看到是b2BlockAllocator::~b2BlockAllocator 这个符号本来需要调用的是unity的静态库中的函数,但是最终调用到了项目中自己实现的网络库中的函数。最终在执行这个项目中这个函数的时出现了崩溃,因为free了一个没有分配过的内存。

因为ios是静态库,在链接是最终生成的可执行文件中就会对符号进行决议。

但是如果是android平台,用的是动态链接,不会出现这个问题。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ivy_0709

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值