MyException - 我的异常网
当前位置:我的异常网» 操作系统 » xcode反汇编调试iOS模拟器程序(7)Debug与Release

xcode反汇编调试iOS模拟器程序(7)Debug与Release的区别

www.myexceptions.net  网友分享于:2013-04-10  浏览:51次
xcode反汇编调试iOS模拟器程序(七)Debug与Release的区别

首先自己写一段代码,加好断点,分别在Build Configuration为Debug和Release下运行,查看反汇编

- (void)test
{
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(10.0, 20.0f, 30.1, 40)];
    [button setTitle:@"test" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    [button release];
}
debug下的反汇编结果:

0x6a10:  pushl  %ebp
0x6a11:  movl   %esp, %ebp
0x6a13:  pushl  %ebx
0x6a14:  pushl  %edi
0x6a15:  pushl  %esi
0x6a16:  subl   $108, %esp
0x6a19:  calll  0x6a1e                    ; -[ViewController test] + 14 at ViewController.mm:375
0x6a1e:  popl   %eax
0x6a1f:  movl   12(%ebp), %ecx
0x6a22:  movl   8(%ebp), %edx
0x6a25:  leal   -40(%ebp), %esi
0x6a28:  movl   $10, %edi
0x6a2d:  cvtsi2ss%edi, %xmm0
0x6a31:  movl   $20, %edi
0x6a36:  cvtsi2ss%edi, %xmm1
0x6a3a:  movss  44642(%eax), %xmm2
0x6a42:  movl   $40, %edi
0x6a47:  cvtsi2ss%edi, %xmm3
0x6a4b:  movl   %edx, -16(%ebp)
0x6a4e:  movl   %ecx, -20(%ebp)
0x6a51:  movl   57106(%eax), %ecx
0x6a57:  movl   56146(%eax), %edx
0x6a5d:  movl   %ecx, (%esp)
0x6a60:  movl   %edx, 4(%esp)
0x6a64:  movl   %eax, -44(%ebp)
0x6a67:  movss  %xmm2, -48(%ebp)
0x6a6c:  movss  %xmm3, -52(%ebp)
0x6a71:  movl   %esi, -56(%ebp)
0x6a74:  movss  %xmm0, -60(%ebp)
0x6a79:  movss  %xmm1, -64(%ebp)
0x6a7e:  calll  0xe56a                    ; symbol stub for: objc_msgSend
0x6a83:  movl   -56(%ebp), %ecx
0x6a86:  movl   %ecx, (%esp)
0x6a89:  movss  -60(%ebp), %xmm0
0x6a8e:  movss  %xmm0, 4(%esp)
0x6a94:  movss  -64(%ebp), %xmm1
0x6a99:  movss  %xmm1, 8(%esp)
0x6a9f:  movss  -48(%ebp), %xmm2
0x6aa4:  movss  %xmm2, 12(%esp)
0x6aaa:  movss  -52(%ebp), %xmm3
0x6aaf:  movss  %xmm3, 16(%esp)
0x6ab5:  movl   %eax, -68(%ebp)
0x6ab8:  calll  0x6900                    ; CGRectMake(float, float, float, float) at CGGeometry.h:269
0x6abd:  subl   $4, %esp
0x6ac0:  movl   $64, %eax
0x6ac5:  movl   $0, %ecx
0x6aca:  movl   -44(%ebp), %edx
0x6acd:  leal   58762(%edx), %esi
0x6ad3:  leal   -40(%ebp), %edi
0x6ad6:  movl   56158(%edx), %ebx
0x6adc:  movl   -68(%ebp), %edx
0x6adf:  movl   %edx, (%esp)
0x6ae2:  movl   %ebx, 4(%esp)
0x6ae6:  movl   (%edi), %edx
0x6ae8:  movl   %edx, 8(%esp)
0x6aec:  movl   4(%edi), %edx
0x6aef:  movl   %edx, 12(%esp)
0x6af3:  movl   8(%edi), %edx
0x6af6:  movl   %edx, 16(%esp)
0x6afa:  movl   12(%edi), %edx
0x6afd:  movl   %edx, 20(%esp)
0x6b01:  movl   %eax, -72(%ebp)
0x6b04:  movl   %ecx, -76(%ebp)
0x6b07:  movl   %esi, -80(%ebp)
0x6b0a:  calll  0xe56a                    ; symbol stub for: objc_msgSend
0x6b0f:  movl   %eax, -24(%ebp)
0x6b12:  movl   -24(%ebp), %eax
0x6b15:  movl   -44(%ebp), %ecx
0x6b18:  movl   56374(%ecx), %edx
0x6b1e:  movl   %eax, (%esp)
0x6b21:  movl   %edx, 4(%esp)
0x6b25:  movl   -80(%ebp), %eax
0x6b28:  movl   %eax, 8(%esp)
0x6b2c:  movl   $0, 12(%esp)
0x6b34:  calll  0xe56a                    ; symbol stub for: objc_msgSend
0x6b39:  movl   -24(%ebp), %eax
0x6b3c:  movl   -44(%ebp), %ecx
0x6b3f:  movl   57074(%ecx), %edx
0x6b45:  movl   56274(%ecx), %esi
0x6b4b:  movl   %edx, (%esp)
0x6b4e:  movl   %esi, 4(%esp)
0x6b52:  movl   %eax, -84(%ebp)
0x6b55:  calll  0xe56a                    ; symbol stub for: objc_msgSend
0x6b5a:  movl   -44(%ebp), %ecx
0x6b5d:  movl   56386(%ecx), %edx
0x6b63:  movl   -84(%ebp), %esi
0x6b66:  movl   %esi, (%esp)
0x6b69:  movl   %edx, 4(%esp)
0x6b6d:  movl   %eax, 8(%esp)
0x6b71:  movl   $0, 12(%esp)
0x6b79:  calll  0xe56a                    ; symbol stub for: objc_msgSend
0x6b7e:  movl   -24(%ebp), %eax
0x6b81:  movl   -16(%ebp), %ecx
0x6b84:  movl   -44(%ebp), %edx
0x6b87:  movl   56454(%edx), %esi
0x6b8d:  movl   56394(%edx), %edi
0x6b93:  movl   %eax, (%esp)
0x6b96:  movl   %edi, 4(%esp)
0x6b9a:  movl   %ecx, 8(%esp)
0x6b9e:  movl   %esi, 12(%esp)
0x6ba2:  movl   $64, 16(%esp)
0x6baa:  calll  0xe56a                    ; symbol stub for: objc_msgSend
0x6baf:  movl   -16(%ebp), %eax
0x6bb2:  movl   -44(%ebp), %ecx
0x6bb5:  movl   56350(%ecx), %edx
0x6bbb:  movl   %eax, (%esp)
0x6bbe:  movl   %edx, 4(%esp)
0x6bc2:  calll  0xe56a                    ; symbol stub for: objc_msgSend
0x6bc7:  movl   -24(%ebp), %ecx
0x6bca:  movl   -44(%ebp), %edx
0x6bcd:  movl   56354(%edx), %esi
0x6bd3:  movl   %eax, (%esp)
0x6bd6:  movl   %esi, 4(%esp)
0x6bda:  movl   %ecx, 8(%esp)
0x6bde:  calll  0xe56a                    ; symbol stub for: objc_msgSend
0x6be3:  movl   -24(%ebp), %eax
0x6be6:  movl   -44(%ebp), %ecx
0x6be9:  movl   56138(%ecx), %edx
0x6bef:  movl   %eax, (%esp)
0x6bf2:  movl   %edx, 4(%esp)
0x6bf6:  calll  0xe56a                    ; symbol stub for: objc_msgSend
0x6bfb:  addl   $108, %esp
0x6bfe:  popl   %esi
0x6bff:  popl   %edi
0x6c00:  popl   %ebx
0x6c01:  popl   %ebp
0x6c02:  ret    
release下的反汇编结果:
0x5310:  pushl  %ebp
0x5311:  movl   %esp, %ebp
0x5313:  pushl  %ebx
0x5314:  pushl  %edi
0x5315:  pushl  %esi
0x5316:  subl   $44, %esp
0x5319:  calll  0x531e                    ; -[ViewController test] + 14 at ViewController.mm:377
0x531e:  popl   %edi
0x531f:  movl   46610(%edi), %eax
0x5325:  movl   45650(%edi), %ecx
0x532b:  movl   %ecx, 4(%esp)
0x532f:  movl   %eax, (%esp)
0x5332:  calll  0xa78e                    ; symbol stub for: objc_msgSend
0x5337:  movl   $1092616192, -32(%ebp)
0x533e:  movl   $1101004800, -28(%ebp)
0x5345:  movl   $1106300109, -24(%ebp)
0x534c:  movl   $1109393408, -20(%ebp)
0x5353:  movl   45662(%edi), %ecx
0x5359:  movsd  -32(%ebp), %xmm0
0x535e:  movsd  -24(%ebp), %xmm1
0x5363:  movsd  %xmm1, 16(%esp)
0x5369:  movsd  %xmm0, 8(%esp)
0x536f:  movl   %ecx, 4(%esp)
0x5373:  movl   %eax, (%esp)
0x5376:  calll  0xa78e                    ; symbol stub for: objc_msgSend
0x537b:  movl   %eax, %esi
0x537d:  movl   45878(%edi), %eax
0x5383:  leal   48262(%edi), %ecx
0x5389:  movl   %ecx, 8(%esp)
0x538d:  movl   %eax, 4(%esp)
0x5391:  movl   %esi, (%esp)
0x5394:  movl   $0, 12(%esp)
0x539c:  calll  0xa78e                    ; symbol stub for: objc_msgSend
0x53a1:  movl   46578(%edi), %eax
0x53a7:  movl   45778(%edi), %ecx
0x53ad:  movl   %ecx, 4(%esp)
0x53b1:  movl   %eax, (%esp)
0x53b4:  calll  0xa78e                    ; symbol stub for: objc_msgSend
0x53b9:  movl   45890(%edi), %ecx
0x53bf:  movl   %eax, 8(%esp)
0x53c3:  movl   %ecx, 4(%esp)
0x53c7:  movl   %esi, (%esp)
0x53ca:  movl   $0, 12(%esp)
0x53d2:  calll  0xa78e                    ; symbol stub for: objc_msgSend
0x53d7:  movl   45898(%edi), %eax
0x53dd:  movl   45958(%edi), %ecx
0x53e3:  movl   %ecx, 12(%esp)
0x53e7:  movl   8(%ebp), %ebx
0x53ea:  movl   %ebx, 8(%esp)
0x53ee:  movl   %eax, 4(%esp)
0x53f2:  movl   %esi, (%esp)
0x53f5:  movl   $64, 16(%esp)
0x53fd:  calll  0xa78e                    ; symbol stub for: objc_msgSend
0x5402:  movl   45854(%edi), %eax
0x5408:  movl   %eax, 4(%esp)
0x540c:  movl   %ebx, (%esp)
0x540f:  calll  0xa78e                    ; symbol stub for: objc_msgSend
0x5414:  movl   45858(%edi), %ecx
0x541a:  movl   %esi, 8(%esp)
0x541e:  movl   %ecx, 4(%esp)
0x5422:  movl   %eax, (%esp)
0x5425:  calll  0xa78e                    ; symbol stub for: objc_msgSend
0x542a:  movl   45642(%edi), %eax
0x5430:  movl   %eax, 4(%esp)
0x5434:  movl   %esi, (%esp)
0x5437:  calll  0xa78e                    ; symbol stub for: objc_msgSend
0x543c:  addl   $44, %esp
0x543f:  popl   %esi
0x5440:  popl   %edi
0x5441:  popl   %ebx
0x5442:  popl   %ebp
0x5443:  ret  
单从行数上看,debug是127行,release是72行,差距很大。这当然是编译器优化的结果,特别对于一些分支多的、带循环的源码时,反汇编和源码的实际动作执行顺序都可能不同。

可以看到:

debug版在0x6ab8调用CGRectMake之前做了好多多余动作,往返访问xmm寄存器。debug版的浮点数,像30.1这样的数值才被真正当做浮点,10.0和20.0f都被当整数了。而release版都是立即数。反汇编中会把float所占的4字节空间的值显示为十进制数,需要自行转换实际的值,转换方法参见http://blog.csdn.net/hursing/article/details/8688862。

CGRectMake的实质是个inline函数,在debug版还存在单独的函数代码入口位置,但release版就没有了。

函数的开头表示debug版要用108字节作为局部变量空间,而release版只需要44字节。

这样的区别还有很多,可通过反汇编自己的代码来观察到。当调试进入系统的代码时,可以看出都是release版的,即debug版链接的仍是release版的静态库。


转载请注明出处:http://blog.csdn.net/hursing

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有