HIST_ENTRY结构中data域的使用出现在history.c文件中的replace_history_entry ()函数中。
而replace_history_entry ()函数在readline.c文件中有如下两处调用
char *
readline_internal ()}
下面是在[/root]# abcad ---> [/root]# aabcad之后按下向上方向键时在replace_history_entry ()函数出被截获。
其中参数rl_undo_list的值为0x5d7cc。指向undo_list结构,下面是undo_list结构的定义(readline.h中):
enum undo_code { UNDO_DELETE, UNDO_INSERT, UNDO_BEGIN, UNDO_END };
/* What an element of THE_UNDO_LIST looks like. */
typedef struct undo_list {
struct undo_list *next;
int start, end; /* Where the change took place. */
char *text; /* The text to insert, if undoing a delete. */
enum undo_code what; /* Delete, Insert, Begin, End. */
} UNDO_LIST;
/* The current undo list for RL_LINE_BUFFER. */
extern UNDO_LIST *rl_undo_list;
rl_undo_list->next的值为0x5d78c
rl_undo_list->start的值为1
rl_undo_list->end的值为2
rl_undo_list->text的值为0既NULL
rl_undo_list->what的值为1既UNDO_INSERT
按下向下方向键,再按下向上方向键,
再次在previous_history ()函数下断点截获后发现data域不是0既NULL了。
这时是0x5d7cc,既是刚才的rl_undo_list的值!!!