《coredump问题原理探究》Linux x86版7.11节string对象

在定位map coredump的那一节已经接触了string对象.在这里重温一下.

看一个例子:

 

  1 #include <string>
  2 #include <stdio.h>
  3 
  4 int main()
  5 {
  6     std::string str;
  7     char* ptr = "hello world!";
  8 
  9     for ( int i = 0; i < 0x10; i++ )
 10     {
 11         str.append( ptr );
 12     }
 13 
 14     return 0;
 15 }

 

 

 

看一下汇编:

(gdb) disassemble main 
Dump of assembler code for function main:
   0x08048584 <+0>:	push   %ebp
   0x08048585 <+1>:	mov    %esp,%ebp
   0x08048587 <+3>:	and    $0xfffffff0,%esp
   0x0804858a <+6>:	push   %esi
   0x0804858b <+7>:	push   %ebx
   0x0804858c <+8>:	sub    $0x28,%esp
   0x0804858f <+11>:	lea    0x14(%esp),%eax
   0x08048593 <+15>:	mov    %eax,(%esp)
   0x08048596 <+18>:	call   0x8048460 <_ZNSsC1Ev@plt>
   0x0804859b <+23>:	movl   $0x80486d4,0x18(%esp)
   0x080485a3 <+31>:	movl   $0x0,0x1c(%esp)
   0x080485ab <+39>:	jmp    0x80485c6 <main+66>
   0x080485ad <+41>:	mov    0x18(%esp),%eax
   0x080485b1 <+45>:	mov    %eax,0x4(%esp)
   0x080485b5 <+49>:	lea    0x14(%esp),%eax
   0x080485b9 <+53>:	mov    %eax,(%esp)
   0x080485bc <+56>:	call   0x80484a0 <_ZNSs6appendEPKc@plt>
   0x080485c1 <+61>:	addl   $0x1,0x1c(%esp)
   0x080485c6 <+66>:	cmpl   $0xf,0x1c(%esp)
   0x080485cb <+71>:	setle  %al
   0x080485ce <+74>:	test   %al,%al
   0x080485d0 <+76>:	jne    0x80485ad <main+41>
   0x080485d2 <+78>:	mov    $0x0,%ebx
   0x080485d7 <+83>:	lea    0x14(%esp),%eax
   0x080485db <+87>:	mov    %eax,(%esp)
   0x080485de <+90>:	call   0x8048490 <_ZNSsD1Ev@plt>
   0x080485e3 <+95>:	mov    %ebx,%eax
   0x080485e5 <+97>:	add    $0x28,%esp
   0x080485e8 <+100>:	pop    %ebx
   0x080485e9 <+101>:	pop    %esi
   0x080485ea <+102>:	mov    %ebp,%esp
   0x080485ec <+104>:	pop    %ebp
   0x080485ed <+105>:	ret    
   0x080485ee <+106>:	mov    %edx,%ebx
   0x080485f0 <+108>:	mov    %eax,%esi
   0x080485f2 <+110>:	lea    0x14(%esp),%eax
   0x080485f6 <+114>:	mov    %eax,(%esp)
   0x080485f9 <+117>:	call   0x8048490 <_ZNSsD1Ev@plt>
   0x080485fe <+122>:	mov    %esi,%eax
   0x08048600 <+124>:	mov    %ebx,%edx
   0x08048602 <+126>:	mov    %eax,(%esp)
   0x08048605 <+129>:	call   0x80484c0 <_Unwind_Resume@plt>
End of assembler dump.

更多内容请关注微信公众号”debugeeker", 链接为https://mp.weixin.qq.com/s/79_BpvGFuqBJII7YNWUiHw

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值