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\n",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\n",[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) 

posted @ 2020-03-23 16:45  龙雪可可  阅读(239)  评论(0编辑  收藏  举报
****************************************** 页脚Html代码 ******************************************