GDB中 打印出链表的值

user defined commands

相关的命令

(gdb) help user-defined

显示自定义了哪些函数

(gdb)help user-defined

显示函数定义,若不指定名称,则全打印

(gdb)show user [command-name]

从文件中导入命令

(gdb)source file-name

其他参见 Debugging with gdb

 

一个例子

define addr
    if $argc == 2
        print $arg0 + $arg1
    end
end

 

document addr

    addr is a user-defined command example

end

 

好了现在进入正题,借用了这个里面的一个例子,天啊,真是难找阿 http://www.ibm.com/developerworks/aix/library/au-gdb.html

 

source code

---------------------------------------------------------

// =====================================================================================
//
//       Filename:  list.cpp
//
//    Description:  link list in cpp
//
//        Version:  1.0
//        Created:  07/21/2010 10:20:47 AM
//       Revision:  none
//       Compiler:  g++
//
//         Author:  Wizard (), wizarddewhite@gmail.com
//        Company: 
//
// =====================================================================================

#include    <iostream>
using namespace std;

class Node
{
public:
    Node(){};
    Node(int n, Node* np):value(n),next(np){};
    int value;
    Node* next;
};

class List
{
public:
    Node* head;
    List():head(0){}
    void insert(int n)
    {
        head = new Node(n, head);
    }
    void print()
    {
        Node *tmp = head;
        while(tmp)
        {
            cout << tmp->value << endl;
            tmp = tmp->next;
        }
    }
};

int main ( int argc, char *argv[] )
{
    List l;
    l.insert(4);
    l.insert(3);
    l.insert(2);
    l.print();
    return 0;
}                // ----------  end of function main  ----------

 

command

-------------------------------------------

define dump_list
    set $_node = (Node*)$arg0
    while $_node
        printf "value is %d/n", $_node->value
        set $_node = $_node->next
    end
end

document dump_list
    This is a command to dump all elements in Linked List
    arg0 is the head
end

 

这个语法真是老奇怪了,

变量定义用了 set ,且变量名要加$。

变量赋值也用set。

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值