这一节。看一下list的iterator对象在内存的布局

1 #include <list>
2
3 void init( std::list<int>& lst )
4 {
5 for ( int i = 0; i < 0x10; i++ )
6 {
7 lst.push_back( i );
8 }
9 }
10
11 int getSum( std::list<int>& lst )
12 {
13 std::list<int>::iterator iter;
14 int result = 0;
15
16 for ( iter = lst.begin(); iter != lst.end(); iter++ )
17 {
18 result += *iter;
19 }
20
21 return result;
22 }
23
24 int main()
25 {
26 std::list<int> lst;
27 init( lst );
28
29 return getSum( lst );
30 }

看getSum函数的汇编:

(gdb) disassemble getSum
Dump of assembler code for function _Z6getSumRSt4listIiSaIiEE:
0x080486cd <+0>: push %ebp
0x080486ce <+1>: mov %esp,%ebp
0x080486d0 <+3>: sub $0x38,%esp
0x080486d3 <+6>: lea -0x18(%ebp),%eax
0x080486d6 <+9>: mov %eax,(%esp)
0x080486d9 <+12>: call 0x8048816 <_ZNSt14_List_iteratorIiEC2Ev>
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 0x8048824 <_ZNSt4listIiSaIiEE5beginEv>
0x080486f7 <+42>: sub $0x4,%esp
0x080486fa <+45>: mov -0x1c(%ebp),%eax
0x080486fd <+48>: mov %eax,-0x18(%ebp)
0x08048700 <+51>: jmp 0x804872f <_Z6getSumRSt4listIiSaIiEE+98>
0x08048702 <+53>: lea -0x18(%ebp),%eax
0x08048705 <+56>: mov %eax,(%esp)
0x08048708 <+59>: call 0x80488ba <_ZNKSt14_List_iteratorIiEdeEv>
0x0804870d <+64>: mov (%eax),%eax
0x0804870f <+66>: add %eax,-0xc(%ebp)
0x08048712 <+69>: lea -0x10(%ebp),%eax
0x08048715 <+72>: movl $0x0,0x8(%esp)
0x0804871d <+80>: lea -0x18(%ebp),%edx
0x08048720 <+83>: mov %edx,0x4(%esp)
0x08048724 <+87>: mov %eax,(%esp)
0x08048727 <+90>: call 0x8048882 <_ZNSt14_List_iteratorIiEppEi>
0x0804872c <+95>: sub $0x4,%esp
0x0804872f <+98>: lea -0x14(%ebp),%eax
0x08048732 <+101>: mov 0x8(%ebp),%edx
0x08048735 <+104>: mov %edx,0x4(%esp)
0x08048739 <+108>: mov %eax,(%esp)
0x0804873c <+111>: call 0x804884a <_ZNSt4listIiSaIiEE3endEv>
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,(%esp)
0x08048751 <+132>: call 0x804886e <_ZNKSt14_List_iteratorIiEneERKS0_>
0x08048756 <+137>: test %al,%al
0x08048758 <+139>: jne 0x8048702 <_Z6getSumRSt4listIiSaIiEE+53>
0x0804875a <+141>: mov -0xc(%ebp),%eax
0x0804875d <+144>: leave
0x0804875e <+145>: ret
End of assembler dump.

能够看到list的this指针在ebp+0x8,iter的this指针在ebp-0x18.

在0x0804874b指令地址打断点.

看一下list的内容:

(gdb) x $ebp+0x8
0xbffff5a0: 0xbffff5b8
(gdb) x /8x 0xbffff5b8
0xbffff5b8: 0x0804b008 0x0804b0f8 0x08048c60 0x080485e0
0xbffff5c8: 0x002edff4 0x00000000 0x08048c60 0x00000000
(gdb) x /4x 0x0804b008
0x804b008: 0x0804b018 0xbffff5b8 0x00000000 0x00000011
(gdb) x /4x 0x0804b018
0x804b018: 0x0804b028 0x0804b008 0x00000001 0x00000011
(gdb) x /4x 0x0804b028
0x804b028: 0x0804b038 0x0804b018 0x00000002 0x00000011
(gdb) x /4x 0x0804b038
0x804b038: 0x0804b048 0x0804b028 0x00000003 0x00000011
(gdb) x /4x 0x0804b048
0x804b048: 0x0804b058 0x0804b038 0x00000004 0x00000011
(gdb) x /4x 0x0804b058
0x804b058: 0x0804b068 0x0804b048 0x00000005 0x00000011
(gdb) x /4x 0x0804b0f8
0x804b0f8: 0xbffff5b8 0x0804b0e8 0x0000000f 0x00020f01
(gdb) x /4x 0x0804b0e8
0x804b0e8: 0x0804b0f8 0x0804b0d8 0x0000000e 0x00000011
(gdb) x /4x 0x0804b0d8
0x804b0d8: 0x0804b0e8 0x0804b0c8 0x0000000d 0x00000011

看一下iter的内容变化:

Breakpoint 1, 0x0804874b in getSum(std::list<int, std::allocator<int> >&) ()
(gdb) x /4x $ebp-0x18
0xbffff580: 0x0804b018 0xbffff5b8 0x0804b008 0x00000000
(gdb) c
Continuing. Breakpoint 1, 0x0804874b in getSum(std::list<int, std::allocator<int> >&) ()
(gdb) x /4x $ebp-0x18
0xbffff580: 0x0804b028 0xbffff5b8 0x0804b018 0x00000001
(gdb) c
Continuing. Breakpoint 1, 0x0804874b in getSum(std::list<int, std::allocator<int> >&) ()
(gdb) x /4x $ebp-0x18
0xbffff580: 0x0804b038 0xbffff5b8 0x0804b028 0x00000003
(gdb) c
Continuing. Breakpoint 1, 0x0804874b in getSum(std::list<int, std::allocator<int> >&) ()
(gdb) x /4x $ebp-0x18
0xbffff580: 0x0804b048 0xbffff5b8 0x0804b038 0x00000006

能够得到list的iterator也仅仅有一个成员_M_node,指向list每一个节点(头节点除外).

《coredump问题原理探究》Linux x86版7.9节list相关的iterator对象的更多相关文章

  1. 《coredump问题原理探究》Linux x86版7.8节vector相关的iterator对象

    在前面看过了一个vectorcoredump的样例,接触了vector的iterator,能够知道vector的iterator仅仅有一个成员_M_current指向vector某一个元素. 先看一个 ...

  2. 《coredump问题原理探究》Linux x86版7.7节 set对象

    看一下bits/stl_map和bits/stl_set能够看到map和set的定义例如以下: 84 template <typename _Key, typename _Tp, typenam ...

  3. [原] KVM 虚拟化原理探究(2)— QEMU启动过程

    KVM 虚拟化原理探究- QEMU启动过程 标签(空格分隔): KVM [TOC] 虚拟机启动过程 第一步,获取到kvm句柄 kvmfd = open("/dev/kvm", O_ ...

  4. 十款最常见的Linux发行版及目标用户(1)

    1. Debian Debian运行起来极其稳定,这使得它非常适合用于服务器.Debian平 时维护三套正式的软件库和一套非免费软件库,这给另外几款发行版(比如Ubuntu和Kali等)带来了灵感.D ...

  5. [原] KVM 虚拟化原理探究(1)— overview

    KVM 虚拟化原理探究- overview 标签(空格分隔): KVM 写在前面的话 本文不介绍kvm和qemu的基本安装操作,希望读者具有一定的KVM实践经验.同时希望借此系列博客,能够对KVM底层 ...

  6. [原] KVM 虚拟化原理探究(6)— 块设备IO虚拟化

    KVM 虚拟化原理探究(6)- 块设备IO虚拟化 标签(空格分隔): KVM [toc] 块设备IO虚拟化简介 上一篇文章讲到了网络IO虚拟化,作为另外一个重要的虚拟化资源,块设备IO的虚拟化也是同样 ...

  7. [原] KVM 虚拟化原理探究(5)— 网络IO虚拟化

    KVM 虚拟化原理探究(5)- 网络IO虚拟化 标签(空格分隔): KVM IO 虚拟化简介 前面的文章介绍了KVM的启动过程,CPU虚拟化,内存虚拟化原理.作为一个完整的风诺依曼计算机系统,必然有输 ...

  8. [原] KVM 虚拟化原理探究(3)— CPU 虚拟化

    KVM 虚拟化原理探究(3)- CPU 虚拟化 标签(空格分隔): KVM [TOC] CPU 虚拟化简介 上一篇文章笼统的介绍了一个虚拟机的诞生过程,从demo中也可以看到,运行一个虚拟机再也不需要 ...

  9. 最适合和最不适合新手使用的几款 Linux 发行版

    大多数知名的Linux发行版都属于"比较容易使用"这一类.一些观察人士可能会驳斥这个观点,但事实上,说到Linux,大多数并非从事IT或软件开发工作的人会被最容易的使用体验所吸引. ...

随机推荐

  1. AHOI2014/JSOI2014 奇怪的计算器

    题目描述 题解: 考虑到经过一系列变化后小数不可能比大数大,我们可以用线段树维护区间修改. 重点是,每个节点都可以通过$a[i]=a[i]*t1+a0[i]*t2+t3$这个函数来表示,我们就可以把三 ...

  2. CSS--浮动与定位

    *浮动布局能够实现横向多列布局. 1.在网页中,元素有三种布局模型: 1.流动模型(Flow) 2.浮动模型 (Float) 3.层模型(Layer) 流动(Flow)是默认的网页布局模式.流动布局模 ...

  3. Java:追加文件内容

    文章来源:https://www.cnblogs.com/hello-tl/p/9139367.html import java.io.*; public class FileBasicOperati ...

  4. uwsgs loading shared libraries: libicui18n.so.58 异常处理

    背景 想使用 ningx + uwsgi + flask 搭建 python 应用环境 Python使用的是anaconda3(pyhton 3.6) 依赖包安装完毕,但是执行 uwsgi 的时候出现 ...

  5. luogu3302 [SDOI2013]森林

    前置技能:Count on a tree 然后带上一个启发式合并 #include <algorithm> #include <iostream> #include <c ...

  6. XTU 二分图和网络流 练习题 J. Drainage Ditches

    J. Drainage Ditches Time Limit: 1000ms Memory Limit: 32768KB 64-bit integer IO format: %I64d      Ja ...

  7. Python内置函数—bytearray

    英文文档: class bytearray([source[, encoding[, errors]]]) Return a new array of bytes. The bytearray cla ...

  8. HaHa's Morning(状压DP)

    描述 HaHa is so happy today, he is going to participate the 7th Hunan University Programming Contest. ...

  9. php 时间 数组替换

    //随机数和时间//随机数生产器//echo rand();//echo "<br>";//生成某个范围的随机数//echo rand(0,10);//echo &qu ...

  10. PTA 05-树7 堆中的路径 (25分)

    题目地址 https://pta.patest.cn/pta/test/15/exam/4/question/713 5-5 堆中的路径   (25分) 将一系列给定数字插入一个初始为空的小顶堆H[] ...