欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Xcode崩溃调试

程序员文章站 2022-03-12 19:32:32
崩溃时候的日志appname(3781,0x1084fabc0) malloc: *** error for object 0x14984b210: pointer being freed was not allocatedappname(3781,0x1084fabc0) malloc: *** set a breakpoint in malloc_error_break to debug输入lldb调试器命令 bt 看栈信息或者直接选中复制看栈信息这个比较详细(直接bt不会显示出下...

1.EXEC_BAD_ACCESS

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

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

Xcode崩溃调试

2.Symbolic Breakpoint

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

3.instruments性能分析工具

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

4.lldb的常用命令

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

1.help

Xcode崩溃调试

 

2.print

Xcode崩溃调试

 

3.expression

Xcode崩溃调试

 

4.breakpoint

Xcode崩溃调试

 


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(我没看)】。本来应该走unity内置的析构的时候,却走到了网络库中,没初始化过,所以就崩了。 

由于ios平台的.a是静态编译的,两个类重名,加载的时候,第一个加载完,第二个再加载就把这段内存覆盖了,就是自定义的这个类覆盖了unity内置的类。而其他平台比如android,同一个网络库没事是因为android是dll动态链接库,内存应该是分配在自己的dll里面,不和运行程序在一起,重名好像也能调用到自己。

似乎编译器就是靠类名分配内存之类的。

本文地址:https://blog.csdn.net/u012138730/article/details/107463567

相关标签: IOS