gdb
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Advice on extending gdb


From: amit.chaudhuri
Subject: Advice on extending gdb
Date: Thu, 13 Nov 2014 07:24:20 +0000

Hi,

Just how do parameters work with user defined commands?

I recently saw an example in which someone prints the contents of std::vector 
(and other container types) using user defined commands:

      http://www.yolinux.com/TUTORIALS/src/dbinit_stl_views-1.03.txt

Very nice.

<snip>

# apologies for loss of indentation

define pvector
if $argc == 0
help pvector
else
set $size = $arg0._M_impl._M_finish - $arg0._M_impl._M_start
set $capacity = $arg0._M_impl._M_end_of_storage - $arg0._M_impl._M_start
set $size_max = $size - 1
end

</snip>

If I try this in gdb it works if passed a std::vector<int>.

If I try to compile a short test app that tries to access v._M_impl (v is a 
populated std::vector<int>) I get:

In file included from /usr/include/c++/4.8/vector:64:0,
                 from main.cpp:3:
/usr/include/c++/4.8/bits/stl_vector.h: In function ‘int main()’:
/usr/include/c++/4.8/bits/stl_vector.h:164:20: error: ‘std::_Vector_base<int, 
std::allocator<int> >::_Vector_impl std::_Vector_base<int, std::allocator<int> 
>::_M_impl’ is inaccessible
       _Vector_impl _M_impl;
                    ^
main.cpp:17:22: error: within this context
  cout << "here "<< v._M_impl << endl;

.. followed by lots of complaints about operator<< overloads

It looks to me as though gdb does a bunch of stuff that is very powerful but 
poorly explained in the docs. It does not seem to use the C++ language rules so 
what rules do the arguments follow?

    http://ftp.gnu.org/old-gnu/Manuals/gdb/html_node/gdb_34.html

Looking for pointers to more detailed documentation of this feature/source code 
references to explore etc.

Regards,


Amit


P.S. am aware that the use case of p std::list is supported out of the box too. 
 A more likely use case for me will be debugging application code using various 
boost libs/shared_ptrs etc.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]