配置GDB以支援查看stl容器資料

來源:互聯網
上載者:User

1. 下載 http://www.yolinux.com/TUTORIALS/src/dbinit_stl_views-1.03.txt   2. #cat dbinit_stl_views-1.03.txt >> ~/.gdbinit   3. 若正處於gdb中,運行命令:    (gdb) source ~/.gdbinit   4. 例如,如下代碼: bugging.cpp

# include < vector >
using namespace std ;

int main( )
{
        vector < int > vec;
        vec. push_back( 2) ;
        vec. push_back( 3) ;
        vec. push_back( 4) ;
        return 0;
}

編譯:#g+ + - o bugging - g bugging. cpp

gdb調試:

# gdb bugging
GNU gdb 6. 8
Copyright ( C) 2008 Free Software Foundation, Inc.
License GPLv3+ : GNU GPL version 3 or later < http: //gnu.org/licenses/gpl.html>

This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-slackware-linux" . . .
( gdb) help pvector
Prints std : : vector < T> information.
Syntax: pvector < vector > < idx1> < idx2>
Note: idx, idx1 and idx2 must be in acceptable range [ 0. . < vector > . 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 vector
( gdb) break main
Breakpoint 1 at 0x80485c6: file bugging. cpp, line 6.
( gdb) run
Starting program: / root/ learn/ c+ + / bugging

Breakpoint 1, main ( ) at bugging. cpp: 6
6        vector < int > vec;
( gdb) n
7        vec. push_back( 2) ;
( gdb)
8        vec. push_back( 3) ;
( gdb) pvector
Prints std : : vector < T> information.
Syntax: pvector < vector > < idx1> < idx2>
Note: idx, idx1 and idx2 must be in acceptable range [ 0. . < vector > . 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 vector
( gdb) pvector vec
elem[ 0] : $1 = 2
Vector size = 1
Vector capacity = 1
Element type = int *
( gdb) n
9        vec. push_back( 4) ;
( gdb)
10        return 0;
( gdb) pvector vec
elem[ 0] : $2 = 2
elem[ 1] : $3 = 3
elem[ 2] : $4 = 4
Vector size = 3
Vector capacity = 4
Element type = int *
( gdb)

5. 預設情況下gdb不能用[]查看stl容器的資料元素,提示如下錯誤:

( gdb) print vec[ 0]
One of the arguments you tried to pass to operator [ ] could not be converted to what the function wants.

轉自:http://blogold.chinaunix.net/u1/44543/showart_1953788.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.