代码: 全选
hala@hala-desktop:~/test$ gdb 1
GNU gdb 6.6-debian
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...
Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) list
1 #include<iostream.h>
2 int main()
3 {
4 int a(8);
5 int &ra=a;
6 cout<<(ra==a)<<endl;
7 cout<<(&ra==&a)<<endl;
8 cout<<(sizeof(ra)==sizeof(a))<<endl;
9 if(ra==a)cout<<"1";
10 else cout<<"0";
(gdb) break 2
Breakpoint 1 at 0x8048706: file 1.cpp, line 2.
(gdb) run
Starting program: /home/hala/test/1
Breakpoint 1, main () at 1.cpp:2
2 int main()
(gdb) step
main () at 1.cpp:4
4 int a(8);
(gdb) print a
$1 = 134514729
(gdb) step
5 int &ra=a;
(gdb) print ra
$2 = (int &) @0xb7fe0800: 1474660693
(gdb) print &a
$3 = (int *) 0xbffc2ecc
(gdb) print &ra
$4 = (int *) 0xb7fe0800
(gdb) step
6 cout<<(ra==a)<<endl;
(gdb) print a
$5 = 8
(gdb) print ra
$6 = (int &) @0xbffc2ecc: 8
(gdb) print &a
$7 = (int *) 0xbffc2ecc
(gdb) print &ra
$8 = (int *) 0xbffc2ecc
(gdb)
代码: 全选
main () at 1.cpp:4
4 int a(8);
(gdb) print a
$1 = 134514729
(gdb) step
5 int &ra=a;
(gdb) print ra
$2 = (int &) @0xb7fe0800: 1474660693
(gdb) print &a
$3 = (int *) 0xbffc2ecc
(gdb) print &ra
$4 = (int *) 0xb7fe0800
而到后面这里
代码: 全选
(gdb) step
6 cout<<(ra==a)<<endl;
(gdb) print a
$5 = 8
(gdb) print ra
$6 = (int &) @0xbffc2ecc: 8
(gdb) print &a
$7 = (int *) 0xbffc2ecc
(gdb) print &ra
$8 = (int *) 0xbffc2ecc
(gdb)