Debugging C++ Applications Using HP WDB (766162-001, March 2014)
type = char enum class GECC {GECC::aa4, GECC::bb4}
(gdb) pt nsec
type = enum class myNS::EC {myNS::EC::green, myNS::EC::yellow, myNS::EC::red}
(gdb) p ECC::yellow
$1 = ECC::yellow
(gdb) p ecc
$1 = ECC::yellow
(gdb) s
inline AA::fun(float,int) (y=1) at my_enum_class.cc:19
19 AAABCEC aaabcec = AAABCEC::a1;
(gdb) n
20 return y+1;
(gdb) pt aaabcec
type = enum class AAABCEC {AAABCEC::a1, AAABCEC::b2}
(gdb) q
Debugging rvalue reference
In C++11, however, there is a new reference called the "rvalue reference", that allows you to
bind a mutable reference to an rvalue, but not an lvalue. In other words, rvalue references
are perfect for detecting if a value is a temporary object or not. rvalue references use the &&
syntax instead of just &, and can be a const and a non-const.
Example 26 (page 38) shows a sample program for debugging rvalue reference:
Example 26 Sample program for debugging rvalue reference
1 int main()
2 {
3 int abc;
4 int &l_ref = abc;
5 int &&r_ref = 100;
6 int * ptr;
7 abc = 100;
8 r_ref = 999;
9 ptr = &l_ref;
10 return 0;
11 }
The following is the WDB output snippet for this program:
(gdb) b 10
Breakpoint 1 at 0x4000890:2:file my_rvalue_reference.cc, line 10 from
/user/usr1/my_rvalue_reference.
(gdb) r
Starting program: /user/usr1/my_rvalue_reference
Breakpoint 1, main () at my_rvalue_reference.cc:10
10 return 0;
(gdb) pt r_ref
type = int &&
(gdb) p r_ref
$2 = (int &&) @0x7fffedd0: 999
(gdb) p -r_ref
$1 = -999
(gdb) p ~r_ref
$3 = -1000
(gdb) find &r_ref,+sizeof(int), (int)0x3e7
0x7fffedd0
1 pattern found.
Debugging variadic template functions
C++0x features are the “variadic templates” that are template classes and functions with a variable
number of parameterized types.
38