美文网首页技能点汇总EMoney 学习
iOS - lldb、 Clang、llvm个人理解

iOS - lldb、 Clang、llvm个人理解

作者: 码代码的小马 | 来源:发表于2021-07-20 13:40 被阅读0次

    lldb

    调试器,主要用于编程中调试
    其中

    快捷键有:

    命令 快捷功能
    command+shift+y 暂停/继续
    command+y 开启/关闭断点功能
    command+shift+c 将光标切换到控制台
    command+shift+y 隐藏/显示控制台
    command+k 清空控制台

    查询命令

    pexpresion --print: 打印对应类型、地址信息、值
    poexpresion --o --: 打印对象值

    附:每次使用p后,lldb会自动分配变量,后边想继续使用这个变量,可以通过$后的数字取该变量

    修改操作

    eexpresion:修改变量,修改后,变量的地址也发生了改变

    断点

    1. 全局断点
      出现异常会自动暂停
    2. 符号断点Symbolic Breakpoint

    当想知道方法testCalled什么时候调用时,添加对应的符号断点


    WX20210602-113621@2x.png
    1. watch point
      观察对象、属性的改变
    添加方式

    改变时会自动暂停到代码处并打印old valuenew value

    改变时自动暂停到对应代码并打印值
    1. tb 打印当前断点信息
    (lldb) tb
    Current breakpoints:
    1: name = 'objc_exception_throw', locations = 1, resolved = 1, hit count = 0
    
      1.1: where = libobjc.A.dylib`objc_exception_throw, address = 0x00007fff20193fc5, resolved, hit count = 0 
    
    2: names = {'[ViewController testCalled]', '[ViewController testCalled]', '[ViewController testCalled]'}, locations = 1, resolved = 1, hit count = 0
    
      2.1: where = LLDBDemo`-[ViewController testCalled] + 23 at ViewController.m:56:5, address = 0x000000010bea5dd7, resolved, hit count = 0 
    
    3: file = '/Users/ternence/Documents/技术/面试技术练手Demo/LLDBDemo/LLDBDemo/ViewController.m', line = 21, exact_match = 0, locations = 1, resolved = 1, hit count = 1
    
      3.1: where = LLDBDemo`-[ViewController viewDidLoad] + 51 at ViewController.m:21:33, address = 0x000000010bea5be3, resolved, hit count = 1 
    
    (lldb) 
    

    4. 堆栈

    1. bt thread backtrack 打印当前线程信息
    (lldb) bt
    * thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 3.1
      * frame #0: 0x000000010bea5be3 LLDBDemo`-[ViewController viewDidLoad](self=0x00007fb2d7c0cd00, _cmd="viewDidLoad") at ViewController.m:21:33
        frame #1: 0x00007fff23f806a9 UIKitCore`-[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 88
        frame #2: 0x00007fff23f8504c UIKitCore`-[UIViewController loadViewIfRequired] + 1084
        frame #3: 0x00007fff23f85436 UIKitCore`-[UIViewController view] + 27
        frame #4: 0x00007fff246ffc73 UIKitCore`-[UIWindow addRootViewControllerViewIfPossible] + 313
        frame #5: 0x00007fff246ff362 UIKitCore`-[UIWindow _updateLayerOrderingAndSetLayerHidden:actionBlock:] + 219
        frame #6: 0x00007fff24700325 UIKitCore`-[UIWindow _setHidden:forced:] + 362
        frame #7: 0x000000010e15a748 UIKit`-[UIWindowAccessibility _orderFrontWithoutMakingKey] + 84
        frame #8: 0x00007fff247133a6 UIKitCore`-[UIWindow _mainQueue_makeKeyAndVisible] + 42
        frame #9: 0x00007fff24951c05 UIKitCore`-[UIWindowScene _makeKeyAndVisibleIfNeeded] + 202
        frame #10: 0x00007fff23b0e80c UIKitCore`+[UIScene _sceneForFBSScene:create:withSession:connectionOptions:] + 1671
        frame #11: 0x00007fff246c2df9 UIKitCore`-[UIApplication _connectUISceneFromFBSScene:transitionContext:] + 1114
        frame #12: 0x00007fff246c3128 UIKitCore`-[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 289
        frame #13: 0x00007fff241a4ab4 UIKitCore`-[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 358
        frame #14: 0x00007fff25a1b40b FrontBoardServices`-[FBSScene _callOutQueue_agent_didCreateWithTransitionContext:completion:] + 398
        frame #15: 0x00007fff25a43e55 FrontBoardServices`__94-[FBSWorkspaceScenesClient createWithSceneID:groupID:parameters:transitionContext:completion:]_block_invoke.176 + 102
        frame #16: 0x00007fff25a28f12 FrontBoardServices`-[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 209
        frame #17: 0x00007fff25a43b28 FrontBoardServices`__94-[FBSWorkspaceScenesClient createWithSceneID:groupID:parameters:transitionContext:completion:]_block_invoke + 352
        frame #18: 0x000000010c11b74e libdispatch.dylib`_dispatch_client_callout + 8
        frame #19: 0x000000010c11e656 libdispatch.dylib`_dispatch_block_invoke_direct + 295
        frame #20: 0x00007fff25a695d0 FrontBoardServices`__FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 30
        frame #21: 0x00007fff25a692b6 FrontBoardServices`-[FBSSerialQueue _targetQueue_performNextIfPossible] + 433
        frame #22: 0x00007fff25a6977b FrontBoardServices`-[FBSSerialQueue _performNextFromRunLoopSource] + 22
        frame #23: 0x00007fff20390ede CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
        frame #24: 0x00007fff20390dd6 CoreFoundation`__CFRunLoopDoSource0 + 180
        frame #25: 0x00007fff20390300 CoreFoundation`__CFRunLoopDoSources0 + 340
        frame #26: 0x00007fff2038a9f7 CoreFoundation`__CFRunLoopRun + 875
        frame #27: 0x00007fff2038a1a7 CoreFoundation`CFRunLoopRunSpecific + 567
        frame #28: 0x00007fff2b874d85 GraphicsServices`GSEventRunModal + 139
        frame #29: 0x00007fff246c14df UIKitCore`-[UIApplication _run] + 912
        frame #30: 0x00007fff246c639c UIKitCore`UIApplicationMain + 101
        frame #31: 0x000000010bea60e2 LLDBDemo`main(argc=1, argv=0x00007ffee3d59ca0) at main.m:17:12
        frame #32: 0x00007fff2025abbd libdyld.dylib`start + 1
    (lldb) 
    
    1. thread return<expr>调试时在断点处return想要的值

    执行后,条件语句会指向else里的NSLog(@"thread have return NO");

    Clang

    Clang项目为LLVM 项目的C语言系列(C,C ++,Objective C / C ++,OpenCL,CUDA和RenderScript)中的语言提供语言前端和工具基础结构。提供了与GCC兼容的编译器驱动程序(clang)和与MSVC兼容的编译器驱动程序(clang-cl.exe)

    3222021-3c2efc79572ced7e.png 3222021-466f2636db5a38ab.png

    相关文章

      网友评论

        本文标题:iOS - lldb、 Clang、llvm个人理解

        本文链接:https://www.haomeiwen.com/subject/eqonsltx.html