您的位置:首页 > 运维架构 > Linux

linux-0.11调试教程,HIST_ENTRY结构中data域的用处

2013-03-06 20:27 411 查看
HIST_ENTRY结构中data域的使用出现在history.c文件中的replace_history_entry ()函数中。

而replace_history_entry ()函数在readline.c文件中有如下两处调用

char *

readline_internal ()

{

......

    if (entry && rl_undo_list)

      {

    char *temp = savestring (the_line);

    rl_revert_line ();

    entry = replace_history_entry (where_history (), the_line,

                       (HIST_ENTRY *)NULL);

    free_history_entry (entry);

    strcpy (the_line, temp);

    free (temp);

      }

  }

/* Perhaps put back the current line if it has changed. */

maybe_replace_line ()

{

  HIST_ENTRY *temp = current_history ();

  /* If the current line has changed, save the changes. */

  if (temp && ((UNDO_LIST *)(temp->data) != rl_undo_list))

    {

      temp = replace_history_entry (where_history (), the_line, rl_undo_list);

      free (temp->line);

      free (temp);

    }

}

下面是在[/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的值!!!

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: