现在的位置: 首页 > 综合 > 正文

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

2014年02月10日 ⁄ 综合 ⁄ 共 1482字 ⁄ 字号 评论关闭

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的值!!!



抱歉!评论已关闭.