This page shows some tips how to debug the
queue in
C++ example from
cpp queue transaction page.
-
The project's main page shows a very simple example of
using queues. There is no real challenge in
debugging this small program, but to demonstrate how
to view transactions (
smart pointer of a queue
element), with gdb. As you will see printing
an array of transactions is simple, but on
my gdb version, it takes more than a single print
to get to the output.
-
First one needs to make sure compile option is
specified correctly in the makefile (-g or -ggdb
is fine):
#Pini
#gdb -x br.txt run.exe
DEBUG = -g
#DEBUG = -ggdb
-
Next, I usually prepare a file (br.txt)
with my current
gdb commands. In this case it is not too
complex. The file contains a single command.
b my_queue_example.cpp:38
-
From the linux command line, gdb is fired
using the following command:
gdb -x br.txt run.exe
Than hit r (run) and you get:
Breakpoint 1, main () at my_queue_example.cpp:38
38 c_trans c = myqueue.front();
In my simple case I prepared an array. Each of
the entries of the array is to be pushed to the
queue.
...
queue myqueue;
unsigned da[BSZ]={1,2,3,4,5,6,7,8};
const c_trans arr[2] = {c_trans(), c_trans(da, 1)};
cout << "start" << endl;
myqueue.push (arr[0]);
myqueue.push (arr[1]);
...
So first it is desired to see the content of the
array:
(gdb) p arr
$1 = {
seq_n = 0, data = {0, 0, 0, 0, 0, 0, 0, 0}},
seq_n = 1, data = {1, 2, 3, 4, 5, 6, 7, 8}}
}
-
Now we are ready to see what is in queue just
before we are going to use it, by printing
first myqueue:
(gdb) p myqueue
$2 = {c = {<std::_Deque_base<c_trans, std::allocator<c_trans> >> = {
_M_impl = {<std::allocator<c_trans>> = {<__gnu_cxx::new_allocator<c_trans>> = {<No data fields>}, <No data fields>}, _M_map = 0x804b230,
_M_map_size = 8, _M_start = {_M_cur = 0x804b258, _M_first = 0x804b258,
_M_last = 0x804b450, _M_node = 0x804b23c}, _M_finish = {
...
And some useful commands to inspect the queue:
(gdb) p myqueue->c->_M_impl->_M_start->_M_first
$3 = (c_trans *) 0x804b258
(gdb) p *(c_trans *) 0x804b258
$4 = {seq_n = 0, data = {0, 0, 0, 0, 0, 0, 0, 0}}
(gdb) p *(c_trans *) 0x804b258@2
$6 = {
{seq_n = 0, data = {0, 0, 0, 0, 0, 0, 0, 0}},
{seq_n = 1, data = {1, 2, 3, 4, 5, 6, 7, 8}}
}
|