本文共 17098 字,大约阅读时间需要 56 分钟。
事实上我还是觉得原生的 GDB 就挺好,速度快,需要查看什么执行命令就可以。
$sudo mkdir -m 777 ~/gdbinit; cd ~/gdbinit$git clone https://github.com/cyrus-and/gdb-dashboard.git; sudo cp gdb-dashboard/.gdbinit ~/$sudo echo 'set auto-load safe-path /' >> ~/.gdbinit
$cd ~/; $git clone https://github.com/gdbinit/Gdbinit.git$sudo mv ~/.gdbinit ~/.gdbinit-rain; sudo cp ~/Gdbinit/gdbinit ~/.gdbinit$sudo echo 'set auto-load safe-path /' >> ~/.gdbinit
$sudo yum install texinfo
# Compile and install readline$cd ~/; wget http://git.savannah.gnu.org/cgit/readline.git/snapshot/readline-master.tar.gz$tar -zxvf readline-master.tar.gz; cd readline-master/$./configure$make$sudo make install# Check current lib link$ldconfig -p | grep 'readline\|history'# Update lib link if needed$sudo ldconfig /usr/local/lib
# Clone cgdb source$cd ~/; git clone git://github.com/cgdb/cgdb.git; cd ~/cgdb# Generate configure file which is not in source code$./autogen.sh# Configure cgdb to be installed to /usr/local$./configure --prefix=/usr/local# Compile$make
有可能在编译 ~/cgdb/lib/kui 会报如下错误
【原因】
kui.cpp 里面用了 C11 的特性 auto,但是在编译的时候 makefile 里面没有指定【解决方法】
$vim ~/cgdb/lib/kui/Makefile
添加 -std=c++11
编译安装cgdb$sudo make & make install
$cd ~/; wget http://www.yolinux.com/TUTORIALS/src/dbinit_stl_views-1.03.txt$echo 'source ~/dbinit_stl_views-1.03.txt' >> ~/.gdbinit# Run such command in GDB directly# source ~/dbinit_stl_views-1.03.txt
dbinit_stl_views-1.03.txt :
# # STL GDB evaluators/views/utilities - 1.03## The new GDB commands: # are entirely non instrumental # do not depend on any "inline"(s) - e.g. size(), [], etc# are extremely tolerant to debugger settings# # This file should be "included" in .gdbinit as following:# source stl-views.gdb or just paste it into your .gdbinit file## The following STL containers are currently supported:## std::vector-- via pvector command# std::list -- via plist or plist_member command# std::map -- via pmap or pmap_member command# std::multimap -- via pmap or pmap_member command# std::set -- via pset command# std::multiset -- via pset command# std::deque -- via pdequeue command# std::stack -- via pstack command# std::queue -- via pqueue command# std::priority_queue -- via ppqueue command# std::bitset -- via pbitset command# std::string -- via pstring command# std::widestring -- via pwstring command## The end of this file contains (optional) C++ beautifiers# Make sure your debugger supports $argc## Simple GDB Macros writen by Dan Marinescu (H-PhD) - License GPL# Inspired by intial work of Tom Malnar, # Tony Novac (PhD) / Cornell / Stanford,# Gilad Mishne (PhD) and Many Many Others.# Contact: dan_c_marinescu@yahoo.com (Subject: STL)## Modified to work with g++ 4.3 by Anders Elton# Also added _member functions, that instead of printing the entire class in map, prints a member.## std::vector<>#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 if $argc == 1 set $i = 0 while $i < $size printf "elem[%u]: ", $i p *($arg0._M_impl._M_start + $i) set $i++ end end if $argc == 2 set $idx = $arg1 if $idx < 0 || $idx > $size_max printf "idx1, idx2 are not in acceptable range: [0..%u].\n", $size_max else printf "elem[%u]: ", $idx p *($arg0._M_impl._M_start + $idx) end end if $argc == 3 set $start_idx = $arg1 set $stop_idx = $arg2 if $start_idx > $stop_idx set $tmp_idx = $start_idx set $start_idx = $stop_idx set $stop_idx = $tmp_idx end if $start_idx < 0 || $stop_idx < 0 || $start_idx > $size_max || $stop_idx > $size_max printf "idx1, idx2 are not in acceptable range: [0..%u].\n", $size_max else set $i = $start_idx while $i <= $stop_idx printf "elem[%u]: ", $i p *($arg0._M_impl._M_start + $i) set $i++ end end end if $argc > 0 printf "Vector size = %u\n", $size printf "Vector capacity = %u\n", $capacity printf "Element " whatis $arg0._M_impl._M_start endenddocument pvector Prints std::vector information. Syntax: pvector Note: idx, idx1 and idx2 must be in acceptable range [0.. .size()-1]. Examples: pvector v - Prints vector content, size, capacity and T typedef pvector v 0 - Prints element[idx] from vector pvector v 1 2 - Prints elements in range [idx1..idx2] from vectorend ## std::list<>#define plist if $argc == 0 help plist else set $head = &$arg0._M_impl._M_node set $current = $arg0._M_impl._M_node._M_next set $size = 0 while $current != $head if $argc == 2 printf "elem[%u]: ", $size p *($arg1*)($current + 1) end if $argc == 3 if $size == $arg2 printf "elem[%u]: ", $size p *($arg1*)($current + 1) end end set $current = $current._M_next set $size++ end printf "List size = %u \n", $size if $argc == 1 printf "List " whatis $arg0 printf "Use plist to see the elements in the list.\n" end endenddocument plist Prints std::list information. Syntax: plist
: Prints list size, if T defined all elements or just element at idx Examples: plist l - prints list size and definition plist l int - prints all elements and list size plist l int 2 - prints the third element in the list (if exists) and list sizeenddefine plist_member if $argc == 0 help plist_member else set $head = &$arg0._M_impl._M_node set $current = $arg0._M_impl._M_node._M_next set $size = 0 while $current != $head if $argc == 3 printf "elem[%u]: ", $size p (*($arg1*)($current + 1)).$arg2 end if $argc == 4 if $size == $arg3 printf "elem[%u]: ", $size p (*($arg1*)($current + 1)).$arg2 end end set $current = $current._M_next set $size++ end printf "List size = %u \n", $size if $argc == 1 printf "List " whatis $arg0 printf "Use plist_member to see the elements in the list.\n" end endenddocument plist_member Prints std::list information. Syntax: plist
: Prints list size, if T defined all elements or just element at idx Examples: plist_member l int member - prints all elements and list size plist_member l int member 2 - prints the third element in the list (if exists) and list sizeend## std::map and std::multimap#define pmap if $argc == 0 help pmap else set $tree = $arg0 set $i = 0 set $node = $tree._M_t._M_impl._M_header._M_left set $end = $tree._M_t._M_impl._M_header set $tree_size = $tree._M_t._M_impl._M_node_count if $argc == 1 printf "Map " whatis $tree printf "Use pmap to see the elements in the map.\n" end if $argc == 3 while $i < $tree_size set $value = (void *)($node + 1) printf "elem[%u].left: ", $i p *($arg1*)$value set $value = $value + sizeof($arg1) printf "elem[%u].right: ", $i p *($arg2*)$value if $node._M_right != 0 set $node = $node._M_right while $node._M_left != 0 set $node = $node._M_left end else set $tmp_node = $node._M_parent while $node == $tmp_node._M_right set $node = $tmp_node set $tmp_node = $tmp_node._M_parent end if $node._M_right != $tmp_node set $node = $tmp_node end end set $i++ end end if $argc == 4 set $idx = $arg3 set $ElementsFound = 0 while $i < $tree_size set $value = (void *)($node + 1) if *($arg1*)$value == $idx printf "elem[%u].left: ", $i p *($arg1*)$value set $value = $value + sizeof($arg1) printf "elem[%u].right: ", $i p *($arg2*)$value set $ElementsFound++ end if $node._M_right != 0 set $node = $node._M_right while $node._M_left != 0 set $node = $node._M_left end else set $tmp_node = $node._M_parent while $node == $tmp_node._M_right set $node = $tmp_node set $tmp_node = $tmp_node._M_parent end if $node._M_right != $tmp_node set $node = $tmp_node end end set $i++ end printf "Number of elements found = %u\n", $ElementsFound end if $argc == 5 set $idx1 = $arg3 set $idx2 = $arg4 set $ElementsFound = 0 while $i < $tree_size set $value = (void *)($node + 1) set $valueLeft = *($arg1*)$value set $valueRight = *($arg2*)($value + sizeof($arg1)) if $valueLeft == $idx1 && $valueRight == $idx2 printf "elem[%u].left: ", $i p $valueLeft printf "elem[%u].right: ", $i p $valueRight set $ElementsFound++ end if $node._M_right != 0 set $node = $node._M_right while $node._M_left != 0 set $node = $node._M_left end else set $tmp_node = $node._M_parent while $node == $tmp_node._M_right set $node = $tmp_node set $tmp_node = $tmp_node._M_parent end if $node._M_right != $tmp_node set $node = $tmp_node end end set $i++ end printf "Number of elements found = %u\n", $ElementsFound end printf "Map size = %u\n", $tree_size endenddocument pmap Prints std::map or std::multimap information. Works for std::multimap as well. Syntax: pmap
转载地址:http://vgsxx.baihongyu.com/