xCode 技巧大全

来源:互联网 发布:a javascript void 0 编辑:程序博客网 时间:2024/05/20 06:53

用windows编程4年了,其vs调试功能可谓强大啊。包括计数断点,条件断点,断点打印,地址断点等。现在接触了Mac的xCode之后,发现xCode在调试方面和vs有很大差距,至少在用户UI操作友好行方面,而且目前没发现可以下地址断点的。不管怎么样,既然用着了,就只能先适应着学着。以后会将工作中学习到的技巧记录在此,以便回顾。

  1. xCode查看数组指针内容。
    1. 在windows中这个操作非常简单,在局部堆栈中对应的指针后面加上,n即可(其中n表示数组长度)。
    2. GDB调试器比较简单:print *pointer@n 其中pointer就是指针变量,n是数组元素个数。
    3. 但是在xCode4.6版本的lldb调试器下,想要看个指针指向的数组内容可不容易。这边使用google上的一个解决方案。

      The only way I found was via a Python scripting module:

      """ File: parray.py """import lldbimport shlexdef parray(debugger, command, result, dict):    args = shlex.split(command)    va = lldb.frame.FindVariable(args[0])    for i in range(0, int(args[1])):        print va.GetChildAtIndex(i, 0, 1)

      Define a command "parray" in lldb:

      (lldb) command script import /path/to/parray.py(lldb) command script add --function parray.parray parray

      Now you can use "parray variable length":

      (lldb) parray a 5(double) *a = 0(double) [1] = 0(double) [2] = 1.14468(double) [3] = 2.28936(double) [4] = 3.43404
      参考帖子:LLDB equivalent of GDB's '@' operator in Xcode 4.1