"Research on the principle of Coredump" Linux version x86 7.7 section set object

Source: Internet
Author: User

Take a look at Bits/stl_map and Bits/stl_set can see the definition of map and set such as the following:


_key, TypeName _tp, typename _compare = Std::less<_key>, <typename typename _alloc = STD::ALLOCATOR&LT;STD::p air<const _key, _tp> > > class map, public:89 typedef _k EY Key_type; a typedef _TP Mapped_type; The Air<const-typedef std::p _key, _tp> value_type; key_compare typedef _compare; allocator_type typedef _alloc; 94 private:96//concept requirements, typedef typename _ALLOC::VALUE_TYPE _alloc _value_type; 98 __glibcxx_class_requires (_TP, _sgiassignableconcept) __glibcxx_class_requires4 (_Compare, bool, _Key, _Ke y,100 _binaryfunctionconcept) 101 __glibcxx_class_requires2 (Value_type, _alloc_value_type, _SameTypeC Oncept) 102103 public:104 class Value_compare105:public Std::binary_function<value_type, Value_type, bool>106     {107 friend Class Map<_key, _TP, _compare, _alloc>;108 protected:109 _compare comp;110 111 Value_compare (_compare __c) 112:comp (__c) {}113 public:115 bool operator () (const value_type& __x, Const value_type& __y) const116 {return comp (__x.first, __y.first);} 117};118 119 private:120//This turns a red-black tree into a [multi]map. 121 typedef TypeName _alloc::template rebind<value_type>::other122 _pair_alloc_type;123 124 type def _rb_tree<key_type, Value_type, _select1st<value_type>,125 key_compare, _pair_alloc_type> _R EP_TYPE;126 127///The actual tree structure.128 _rep_type _m_t;

Template<typename _key, typename _compare = Std::less<_key>, + typename _alloc = Std::allocator<_                   Key> > Concept class Set (_alloc::value_type)//Requirements TypeDef typename _alloc_value_type; __glibcxx_class_requires (_key, _sgiassignableconcept) __glibcxx_class_requires4 (_compare, bool, _Key, _K EY, _binaryfunctionconcept) 94 __glibcxx_class_requires2 (_key, _alloc_value_type, _SAMETYPECONCEP T) public:97//typedefs:98//@{//Public typedefs.100 typedef _key KEY_TYPE        ; 101 typedef _key VALUE_TYPE;102 typedef _compare KEY_COMPARE;103 typedef _compare VALUE_COMPARE;104 typedef _alloc ALLOCATOR_TYPE;105//@}106 107 private:108 typedef typename _alloc::template Rebin D<_key>::other _key_alloc_type;109 typedef _rb_tree<key_type, Value_type, _identity<value_type>,111 Key_compare, _key_alloc_type> _rep_type;112 _rep_type _m_t; Red-black Tree representing set.113

Since Map,set itself is defined as declaring whatever member variable, all member variables are inherited from _rb_tree, the only difference being that the definition of the last argument is not the same as the _rb_tree.

The characteristics of set are as follows:

1. The set object has five members _m_node_count indicate how many elements map has, and three pointers point to the leftmost node in the tree, the root node of the tree, the right node of the tree, and _m_color indicates whether it is a mangrove or a black tree. _m_key_compare pointing to the comparative function

2. The _m_parent of the root node of the tree points to the head node

3. The values of each node follow the _m_right

Take a look at the examples:

  1 #include <set>  2   3 int main ()  4 {  5     std::set<int> iSet;  6     Iset.insert (0x523);  7     Iset.insert (0x352);  8     Iset.insert (0x808);  9     return 0; 11}

Take a look at the assembly of the main function:

(GDB) disassemble maindump of assembler code for function main:0x08048634 <+0>:lea 0x4 (%ESP),%ecx 0x08048638 <+4>:and $0xfffffff0,%esp 0x0804863b <+7>:p ushl-0x4 (%ecx) 0x0804863e <+10>:p ush%ebp 0x080 4863f <+11>:mov%esp,%ebp 0x08048641 <+13>:p ush%esi 0x08048642 <+14>:p ush%ebx 0x08048643 <+15>:p ush%ecx 0x08048644 <+16>:sub $0x5c,%esp 0x08048647 <+19>:lea-0x54 (%EBP),%eax 0x08   04864a <+22>:mov%eax, (%ESP) 0x0804864d <+25>:call 0x8048712 <_ZNSt3setIiSt4lessIiESaIiEEC2Ev> 0x08048652 <+30>:movl $0x523,-0x34 (%EBP) 0x08048659 <+37>:lea-0x3c (%EBP),%eax 0x0804865c <+40>   : lea-0x34 (%EBP),%edx 0x0804865f <+43>:mov%edx,0x8 (%ESP) 0x08048663 <+47>:lea-0x54 (%EBP),%edx   0x08048666 <+50>:mov%edx,0x4 (%esp) 0x0804866a <+54>:mov%eax, (%ESP) 0x0804866d <+57>:call 0x804878c <_znst3setiist4lessiiesaiiee6inserterki> 0x08048672 <+62>:sub $0x4,%esp 0x08048675 <+65>:movl $0x352,-0x28 (%e BP) 0x0804867c <+72>:lea-0x30 (%EBP),%eax---Type <return> to continue, or Q <return> to quit---0    x0804867f <+75>:lea-0x28 (%EBP),%edx 0x08048682 <+78>:mov%edx,0x8 (%esp) 0x08048686 <+82>:lea -0x54 (%EBP),%edx 0x08048689 <+85>:mov%edx,0x4 (%esp) 0x0804868d <+89>:mov%eax, (%ESP) 0x0804869   0 <+92>:call 0x804878c <_ZNSt3setIiSt4lessIiESaIiEE6insertERKi> 0x08048695 <+97>:sub $0x4,%esp 0x08048698 <+100>:movl $0x808,-0x1c (%EBP) 0x0804869f <+107>:lea-0x24 (%EBP),%eax 0x080486a2 <+110& GT;:LEA-0X1C (%EBP),%edx 0x080486a5 <+113>:mov%edx,0x8 (%ESP) 0x080486a9 <+117>:lea-0x54 (%EBP),% EdX 0x080486ac <+120>:mov%edx,0x4 (%esp) 0x080486b0 <+124>:mov%eax, (%ESP) 0x080486b3 <+127> : Call 0x804878c <_znst3setiist4lessiiesaiiee6inserterki> 0x080486b8 <+132>:sub $0x4,%esp 0x080486bb <+135>:mov $0x0, %EBX 0x080486c0 <+140>:lea-0x54 (%EBP),%eax 0x080486c3 <+143>:mov%eax, (%ESP) 0x080486c6 <+146& Gt;:call 0x80486fe <_ZNSt3setIiSt4lessIiESaIiEED2Ev> 0x080486cb <+151>:mov%ebx,%eax 0x080486cd <+ 153&GT;:LEA-0XC (%EBP),%esp 0x080486d0 <+156>:add $0x0,%esp---Type <return> to continue, or Q <retu Rn> to quit---0x080486d3 <+159>:p op%ecx 0x080486d4 <+160>:p op%ebx 0x080486d5 <+161>:p o P%esi 0x080486d6 <+162>:p op%ebp 0x080486d7 <+163>:lea-0x4 (%ecx),%esp 0x080486da <+166> : ret 0x080486db <+167>:mov%edx,%ebx 0x080486dd <+169>:mov%eax,%esi 0x080486df <+171>:l Ea-0x54 (%EBP),%eax 0x080486e2 <+174>:mov%eax, (%ESP) 0x080486e5 <+177>:call 0x80486fe <_ZNSt3s Etiist4lessiiesaiieed2ev> 0x080486ea <+182>:mov%esi,%eax 0x080486ec <+184>:mov%ebx,%edx 0x080486ee <+186>:mov %eax, (%ESP) 0x080486f1 <+189>:call 0x8048564 <[email protected]>end of assembler dump.

As the above assembly shows, ebp-0x54 is the this pointer to set.

At the 0X080486B8 command address break point, verify that the set features are not right.

(gdb) x/8wx $ebp -0x540xbffff234:0xbffff2700x000000000x0804b0080x0804b0200xbffff244:0 x0804b0380x000000030x0804b0080xbffff201 (GDB) x/8wx 0x0804b0080x804b008:0 x000000010xbffff2380x0804b0200x0804b0380x804b018:0x000005230x000000190x000000000x0804b008 (GDB) x/8x 0x0804b0200x804b020:0x000000000x0804b0080x000000000x000000000x804b030:0x000003520x000000190x000000000x0804b008 (GDB) X/8wx 0x0804b0380x804b038:0x000000000x0804b0080x000000000x000000000x804b048:0 x000008080x00020fb90x000000000x00000000

Available Representations:

The feature is no problem


"Research on the principle of Coredump" Linux version x86 7.7 section set object

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.