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。