这一节。看一下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. TWaver可视化编辑器的前世今生(一)电信网管编辑器

    走到今天,TWaver,一个致力于在技术领域(Technology)的弄潮儿(Waver),已经是第十二个年头.当年网吧的小网管都是IDC机房的运维人员了,TWaver也见证了这个时代的成长变迁. 萌 ...

  2. encodeURI()与decodeURI()等转码方法

    只针对文本编码 encodeURI() 只针对文本解码 decodeURI()针对文本和特殊字符的编码  encodeURIComponent()针对文本和特殊字符的解码  decodeURIComp ...

  3. VS C++项目报错warning C4199: ……use /Zc:twoPhase-

    具体的报错如下: c1xx : warning C4199: two-phase name lookup is not supported for C++/CLI, C++/CX, or OpenMP ...

  4. Specified VM install not found: type Standard VM, name JDK1.8

    真正的问题解决方法在这里:在项目中,右键点击ant文件,选择Run As -- External Tools Configuration,在这个页面的顶端就会看到有红叉叉的报错,报错信息就是Speci ...

  5. pwntools各使用模块简介

    pwntools pwntools 是一款专门用于CTF Exploit的python库,能够很方便的进行本地与远程利用的切换,并且里面包含多个模块,使利用变得简单.可以在github上直接搜索pwn ...

  6. 《算法导论》 — Chapter 8 线性时间排序

    序 到目前为止,关于排序的问题,前面已经介绍了很多,从插入排序.合并排序.堆排序以及快速排序,每一种都有其适用的情况,在时间和空间复杂度上各有优势.它们都有一个相同的特点,以上所有排序的结果序列,各个 ...

  7. LeetCode(25)Reverse Nodes in k-Group

    题目 Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. ...

  8. NYOJ 1875 畅通工程再续 (无节点间距离求最小生成树)

    Description 相信大家都听说一个“百岛湖”的地方吧,百岛湖的居民生活在不同的小岛中,当他们想去其他的小岛时都要通过划小船来实现.现在政府决定大力发展百岛湖,发展首先要解决的问题当然是交通问题 ...

  9. NBUT 1651 - Red packet (求运气王的钱数)(二分法)

    Description New Year is coming! Our big boss Wine93 will distribute some “Red Package”, just like Al ...

  10. 安装weblogic时,运行configure.cmd报错、闪退、无法创建域

    直接运行configure.cmd时在jar包加载完成时,不提示创建域的过程,而是直接退出程序 命令行: cd /d F:\00uep_rfs\wls1212_dev\wls12120 切换至解压路径 ...