linux-0.11调试教程,rl_get_previous_history 调用过程


linux-0.11调试教程,bash-1.12中readline()调用过程
http://blog.csdn.net/sitelist/article/details/8602108

这篇文是面这篇文的后续,rl_get_previous_history (count)函数位于readline.c文件中,previous_history ()函数位于history.c文件中。rl_initialize ()函数中有调用using_history ()函数。

readline ()
    rl_initialize ()
        start_using_history ()
            using_history ()


/* Begin a session in which the history functions might be used.  This
   initializes interactive variables. */
void
using_history ()
{
  history_offset = history_length;
}


/* Get the previous item out of our interactive history, making it the current
   line.  If there is no previous history, just ding. */
rl_get_previous_history (count)
     int count;
{
  HIST_ENTRY *old_temp = (HIST_ENTRY *)NULL;
  HIST_ENTRY *temp = (HIST_ENTRY *)NULL;

  if (count < 0)
    {
      rl_get_next_history (-count);
      return;
    }

  if (!count)
    return;

  /* If we don't have a line saved, then save this one. */
  maybe_save_line ();

  /* If the current line has changed, save the changes. */
  maybe_replace_line ();

  while (count)
    {
      temp = previous_history ();
      if (!temp)
    break;
      else
    old_temp = temp;
      --count;
    }

  /* If there was a large argument, and we moved back to the start of the
     history, that is not an error.  So use the last value found. */
  if (!temp && old_temp)
    temp = old_temp;

  if (!temp)
    ding ();
  else
    {
      int line_len;

      line_len = strlen (temp->line);

      if (line_len >= rl_line_buffer_len)
    rl_extend_line_buffer (line_len);

      strcpy (the_line, temp->line);
      rl_undo_list = (UNDO_LIST *)temp->data;
      rl_end = rl_point = line_len;

#if defined (VI_MODE)
      if (rl_editing_mode == vi_mode)
    rl_point = 0;
#endif /* VI_MODE */
    }
}



/* Back up history_offset to the previous history entry, and return

   a pointer to that entry.  If there is no previous entry then return
   a NULL pointer. */
HIST_ENTRY *
previous_history ()
{
  if (!history_offset)
    return ((HIST_ENTRY *)NULL);
  else
    return (the_history[--history_offset]);

}


the_history的值为0x424c4是个二级指针,the_history[]数组是个指针数组。

history_offset的值为0x1f4。

the_history[--history_offset]的值为0x4faac是HIST_ENTRY类型指针

typedef struct _hist_entry {
  char *line;
  char *data;
} HIST_ENTRY;

the_history[--history_offset] ->line为0x4fa8c

linux-0.11调试教程,rl_get_previous_history 调用过程_第1张图片


下面是键入abcd回车后按下向上方向键后在previous_history ()函数处下断点时的情形


你可能感兴趣的:(linux-0.11调试教程,rl_get_previous_history 调用过程)