"Research on the principle of Coredump" Linux x86 version 7.8 vector-related iterator objects

Source: Internet
Author: User

In front of a vectorcoredump example, contact with the vector iterator, can know that the vector iterator only one member _m_current point to a vector element.

First look at the example:

1 #include <vector>  2   3 void init (std::vector<int>& vec)  4 {  5 for     (int i = 0; I &l T 0x10 i++)  6     {  7         vec.push_back (i);  8     }  9}  getsum int (std::vector<int>& VEC) {     std::vector<int>::iterator Iter     int result = 0;     (iter = Vec.begin (); ITER! = Vec.end (); iter++) (     +)         + result + = *iter;  (     ) +     return result; () the (). (  ). {     std::vector<int> Vec;     VEC);     getsum return (VEC); 30}

Because it is only to examine iterator, only to see the Getsum assembly:

(GDB) disassemble getsumdump of assembler code for function _Z6GETSUMRST6VECTORIISAIIEE:0X080486CD <+0>:p ush%e bp 0x080486ce <+1>:mov%esp,%ebp 0x080486d0 <+3>:sub $0x38,%esp 0x080486d3 <+6>:lea-0x18 (%EBP),%eax 0x080486d6 <+9>:mov%eax, (%ESP) 0x080486d9 <+12>:call 0x8048840 <_zn9__gnu_cxx17__norm Al_iteratoripist6vectoriisaiieeec2ev> 0x080486de <+17>:movl $0x0,-0xc (%EBP) 0x080486e5 <+24>:lea-  0x1c (%EBP),%eax 0x080486e8 <+27>:mov 0x8 (%EBP),%edx 0x080486eb <+30>:mov%edx,0x4 (%ESP) 0x080486ef <+34>:mov%eax, (%ESP) 0x080486f2 <+37>:call 0x804884e <_ZNSt6vectorIiSaIiEE5beginEv> 0x080486f 7 <+42>:sub $0x4,%esp 0x080486fa <+45>:mov-0x1c (%EBP),%eax 0x080486fd <+48>:mov%eax,-0x18 (%EBP) 0x08048700 <+51>:jmp 0x804872f <_Z6getSumRSt6vectorIiSaIiEE+98> 0x08048702 <+53>:lea-0 X18 (%EBP),%eax 0x08048705 <+56>:mov%eax, (%ESP) 0x08048708 <+59>:call 0x80488f8 <_znk9__gnu_cxx17__normal_iteratoripist6ve Ctoriisaiieeedeev> 0x0804870d <+64>:mov (%eax),%eax 0x0804870f <+66>:add%eax,-0xc (%EBP) 0x0804 8712 <+69>:lea-0x10 (%EBP),%eax 0x08048715 <+72>:movl $0x0,0x8 (%esp) 0x0804871d <+80>:lea-0 X18 (%EBP),%edx 0x08048720 <+83>:mov%edx,0x4 (%esp) 0x08048724 <+87>:mov%eax, (%ESP) 0x08048727 &lt ; +90>:call 0x80488c4 <_ZN9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEppEi> 0x0804872c <+95>: Sub $0x4,%esp 0x0804872f <+98>:lea-0x14 (%EBP),%eax 0x08048732 <+101>:mov 0x8 (%EBP),%edx 0x0804 8735 <+104>:mov%edx,0x4 (%esp) 0x08048739 <+108>:mov%eax, (%ESP) 0x0804873c <+111>:call 0x80 48872 <_ZNSt6vectorIiSaIiEE3endEv> 0x08048741 <+116>:sub $0x4,%esp 0x08048744 <+119>:lea-0x14 (%EBP),%eax 0x08048747 <+122>:mov%eax,0x4 (%ESP) 0x0804874b <+126>:lea-0x18 (%EBP),%eax 0x0804874e <+129>:mov%eax, (%e SP) 0x08048751 <+132>:call 0x8048898 <_zn9__gnu_cxxneipist6vectoriisaiieeeebrkns_17__normal_iteratorit_t0 _eesa_> 0x08048756 <+137>:test%al,%al 0x08048758 <+139>:jne 0x8048702 <_Z6getSumRSt6vectorIiSa Iiee+53> 0x0804875a <+141>:mov-0xc (%EBP),%eax 0x0804875d <+144>:leave 0x0804875e <+145>:r Et End of assembler dump.

At the 0x0804874b break point. By the above assembly, ITER's this pointer is ebp-0x18, and the VEC's this pointer is placed in ebp+0x8.

Run to the breakpoint and look at the contents of the VEC:

(GDB) x $ebp +80xbffff5a0:0xbffff5b4 (gdb) x/4x 0xbffff5b40xbffff5b4:0x0804b0680x0804b0a80x0804b0a80x080491f0 (GDB) x/ 16x 0x0804b0680x804b068:0x000000000x000000010x000000020x000000030x804b078:0 x000000040x000000050x000000060x000000070x804b088:0x000000080x000000090x0000000a0x0000000b0x804b098:0 x0000000c0x0000000d0x0000000e0x0000000f

Take a look at how the contents of ITER change, after running a few C commands (note that the breakpoint address is after running iter++):


It is true that the iterator of a vector does have only one member _ptr, and its value range is

Vec. _m_start? <= _m_current < VEC. _m_finish


"Research on the principle of Coredump" Linux x86 version 7.8 vector-related iterator objects

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.