在定位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