zoukankan      html  css  js  c++  java
  • swap变量交换&&递归调用栈帧

    (lldb) po a

    0x00007ffeefbff60c

     

    (lldb) po b

    0x00007ffeefbff608

     

    (lldb) p a

    (int *) $2 = 0x00007ffeefbff60c

    (lldb) bt

    * thread #1, queue = 'com.apple.main-thread', stop reason = step over

      * frame #0: 0x0000000100000f3a 1`swap(a=0x00007ffeefbff60c, b=0x00007ffeefbff608) at main.cpp:8

        frame #1: 0x0000000100000f63 1`main at main.cpp:13

        frame #2: 0x00007fff7018d015 libdyld.dylib`start + 1

    (lldb) p b

    (int *) $3 = 0x00007ffeefbff608

    (lldb) p t

    (int) $4 = 3

    (lldb) p *a

    (int) $5 = 4

    (lldb) p *b

    (int) $6 = 3

    (lldb) up

    frame #1: 0x0000000100000f63 1`main at main.cpp:13

       10  {

       11      int a,b;

       12      a = 3, b = 4;

    -> 13      [4ms[0mwap(&a,&b);

       14      printf("%d %d ",a,b);

       15  }

    (lldb) p a

    (int) $7 = 4

    (lldb) p b

    (int) $8 = 3

    (lldb) p &a

    (int *) $9 = 0x00007ffeefbff60c

    (lldb) p &b

    (int *) $10 = 0x00007ffeefbff608

    (lldb) q

    Program ended with exit code: 9

    如果第三个变量改成int *t;

     但却错了,原来是*t只读的,内存地址“0”不能写。

    还有一种是交换了地址,但是没有修改它们指向的内容。

     

     

    指向函数的指针,万能的指针const void *,可以强制转换成任意类型的指针。

    排序的对象是整型数组。

    (lldb) bt

    * thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1

      * frame #0: 0x0000000100000f2b 1`f(n=3) at main.cpp:4

        frame #1: 0x0000000100000f72 1`main at main.cpp:8

        frame #2: 0x00007fff7018d015 libdyld.dylib`start + 1

    (lldb) up

    frame #1: 0x0000000100000f72 1`main at main.cpp:8

       5   }

       6   int main()

       7   {

    -> 8       printf("%d ",[4mf[0m(3));

       9   }

    (lldb) p f

    (int (*)(int)) $0 = 0x0000000100000f20 (1`f(int) at main.cpp:3)

    (lldb) s

    (lldb) bt

    * thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1

      * frame #0: 0x0000000100000f2b 1`f(n=2) at main.cpp:4

        frame #1: 0x0000000100000f4f 1`f(n=3) at main.cpp:4

        frame #2: 0x0000000100000f72 1`main at main.cpp:8

        frame #3: 0x00007fff7018d015 libdyld.dylib`start + 1

    (lldb) s

    (lldb) bt

    * thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1

      * frame #0: 0x0000000100000f2b 1`f(n=1) at main.cpp:4

        frame #1: 0x0000000100000f4f 1`f(n=2) at main.cpp:4

        frame #2: 0x0000000100000f4f 1`f(n=3) at main.cpp:4

        frame #3: 0x0000000100000f72 1`main at main.cpp:8

        frame #4: 0x00007fff7018d015 libdyld.dylib`start + 1

    (lldb) s

    (lldb) bt

    * thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1

      * frame #0: 0x0000000100000f2b 1`f(n=0) at main.cpp:4

        frame #1: 0x0000000100000f4f 1`f(n=1) at main.cpp:4

        frame #2: 0x0000000100000f4f 1`f(n=2) at main.cpp:4

        frame #3: 0x0000000100000f4f 1`f(n=3) at main.cpp:4

        frame #4: 0x0000000100000f72 1`main at main.cpp:8

        frame #5: 0x00007fff7018d015 libdyld.dylib`start + 1

    (lldb) s

    (lldb) bt

    * thread #1, queue = 'com.apple.main-thread', stop reason = step in

      * frame #0: 0x0000000100000f4f 1`f(n=1) at main.cpp:4

        frame #1: 0x0000000100000f4f 1`f(n=2) at main.cpp:4

        frame #2: 0x0000000100000f4f 1`f(n=3) at main.cpp:4

        frame #3: 0x0000000100000f72 1`main at main.cpp:8

        frame #4: 0x00007fff7018d015 libdyld.dylib`start + 1

    (lldb) s

    (lldb) bt

    * thread #1, queue = 'com.apple.main-thread', stop reason = step in

      * frame #0: 0x0000000100000f4f 1`f(n=2) at main.cpp:4

        frame #1: 0x0000000100000f4f 1`f(n=3) at main.cpp:4

        frame #2: 0x0000000100000f72 1`main at main.cpp:8

        frame #3: 0x00007fff7018d015 libdyld.dylib`start + 1

    (lldb) s

    (lldb) bt

    * thread #1, queue = 'com.apple.main-thread', stop reason = step in

      * frame #0: 0x0000000100000f4f 1`f(n=3) at main.cpp:4

        frame #1: 0x0000000100000f72 1`main at main.cpp:8

        frame #2: 0x00007fff7018d015 libdyld.dylib`start + 1

    (lldb) s

    (lldb) bt

    * thread #1, queue = 'com.apple.main-thread', stop reason = step in

      * frame #0: 0x0000000100000f72 1`main at main.cpp:8

        frame #1: 0x00007fff7018d015 libdyld.dylib`start + 1

    (lldb) s

    6

    (lldb) 

  • 相关阅读:
    待续中的图灵机与有限状态机
    barabasilab-networkScience学习笔记6-evolving networks
    pythonyCool-moviepy
    各种方法合成地震图的对应单位
    matla互相关协方差的计算和理解
    matlab运行中出现“Caught "std::exception" Exception message is: Message Catalog MATLAB:builtins was not loaded from the file."
    对拉普拉斯平滑 的认识
    关于小波变换
    随笔学习
    关于滤波频段的选取(近震波形)
  • 原文地址:https://www.cnblogs.com/longxue1991/p/12553134.html
Copyright © 2011-2022 走看看