23 #include "filenames.h"
39 #include "readline/readline.h"
72 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,";
78 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
83 static char *gdb_completer_file_name_break_characters =
" \t\n*|\"';:?><";
105 rl_line_buffer, rl_point);
112 const char *text,
const char *prefix)
120 const char *text,
const char *word)
130 p = rl_filename_completion_function (text, subsequent_name);
140 if (p[strlen (p) - 1] ==
'~')
149 else if (word > text)
153 strcpy (q, p + (word - text));
159 q =
xmalloc (strlen (p) + (text - word) + 5);
160 strncpy (q, word, text - word);
161 q[text -
word] =
'\0';
173 rl_completer_word_break_characters =
"";
189 const char *text,
const char *word)
191 int n_syms, n_files, ix;
196 int quoted = *text ==
'\'' || *text ==
'"';
197 int quote_char =
'\0';
198 const char *colon = NULL;
199 char *file_to_match = NULL;
200 const char *symbol_start = text;
201 const char *orig_text = text;
205 for (p = text; *p !=
'\0'; ++p)
207 if (*p ==
'\\' && p[1] ==
'\'')
209 else if (*p ==
'\'' || *p ==
'"')
213 while (*p !=
'\0' && *p != quote_found)
215 if (*p ==
'\\' && p[1] == quote_found)
220 if (*p == quote_found)
225 #if HAVE_DOS_BASED_FILE_SYSTEM
229 else if (p < text + 3 && *p ==
':' && p == text + 1 + quoted)
232 else if (*p ==
':' && !colon)
235 symbol_start = p + 1;
238 symbol_start = p + 1;
243 text_len = strlen (text);
250 file_to_match = (
char *)
xmalloc (colon - text + 1);
251 strncpy (file_to_match, text, colon - text + 1);
253 for (s = file_to_match + (colon - text);
256 if (*s ==
':' || *s == quote_char)
264 list = make_file_symbol_completion_list (symbol_start, word,
266 xfree (file_to_match);
270 list = make_symbol_completion_list (symbol_start, word);
274 gdb_completer_file_name_break_characters) == text_len)
275 fn_list = make_source_files_completion_list (text, text);
297 if (n_syms && n_files)
322 memmove (fn, fn + (word - text),
323 strlen (fn) + 1 - (word - text));
330 list = make_symbol_completion_list (orig_text, word);
341 char *fieldname,
int namelen)
344 int computed_type_name = 0;
345 const char *type_name = NULL;
352 output, fieldname, namelen);
366 output, fieldname, namelen);
375 if (name && ! strncmp (name, fieldname, namelen))
377 if (!computed_type_name)
380 computed_type_name = 1;
383 if (!type_name || strcmp (type_name, name))
394 const char *text,
const char *word)
396 struct type *type = NULL;
414 if (fieldname && type)
428 int flen = strlen (fieldname);
441 result = make_symbol_completion_type (fieldname, fieldname, code);
450 p > text && p[-1] !=
' ' && p[-1] !=
'\t';
455 return location_completer (ignore, p, word);
465 if (fn == filename_completer)
466 rl_completer_word_break_characters
469 rl_completer_word_break_characters
533 complete_line_internal (
const char *text,
534 const char *line_buffer,
int point,
540 int ignore_help_classes;
552 rl_completer_word_break_characters =
557 tmp_command = (
char *) alloca (point + 1);
563 strncpy (tmp_command, line_buffer, point);
564 tmp_command[
point] =
'\0';
568 word = tmp_command + point - strlen (text);
583 while (*p ==
' ' || *p ==
'\t')
601 while (*q && (isalnum (*q) || *q ==
'-' || *q ==
'_'))
603 if (q != tmp_command + point)
619 list = complete_on_cmdlist (*result_list->
prefixlist, p,
620 word, ignore_help_classes);
625 list = complete_on_cmdlist (
cmdlist, p, word,
626 ignore_help_classes);
630 rl_completer_word_break_characters =
638 if (p == tmp_command + point)
643 if (p[-1] ==
' ' || p[-1] ==
'\t')
652 list = complete_on_cmdlist (*c->
prefixlist, p, word,
653 ignore_help_classes);
657 rl_completer_word_break_characters =
665 list = complete_on_enum (c->
enums, p, word);
666 rl_completer_word_break_characters =
685 && strchr (gdb_completer_file_name_break_characters, p[-1]) == NULL;
688 rl_completer_word_break_characters =
691 else if (c->
completer == location_completer)
697 && p[-1] !=
' ' && p[-1] !=
'\t';
718 while (q > tmp_command)
720 if (isalnum (q[-1]) || q[-1] ==
'-' || q[-1] ==
'_')
727 list = complete_on_cmdlist (result_list, q, word,
728 ignore_help_classes);
732 rl_completer_word_break_characters =
751 list = complete_on_enum (c->
enums, p, word);
762 && strchr (gdb_completer_file_name_break_characters,
766 rl_completer_word_break_characters =
769 else if (c->
completer == location_completer)
773 && p[-1] !=
' ' && p[-1] !=
'\t';
791 int max_completions = 200;
798 if (max_completions <= 0)
801 return htab_create_alloc (max_completions,
802 htab_hash_string, (htab_eq)
streq,
814 htab_delete (*tracker_ptr);
823 if (*tracker_ptr == NULL)
836 if (max_completions < 0)
838 if (max_completions == 0)
843 if (htab_elements (tracker) >= max_completions)
846 slot = htab_find_slot (tracker, name, INSERT);
848 if (*slot != HTAB_EMPTY_ENTRY)
853 return (htab_elements (tracker) < max_completions
878 complete_line (
const char *text,
const char *line_buffer,
int point)
887 if (max_completions == 0)
889 list = complete_line_internal (text, line_buffer, point,
891 if (max_completions < 0)
905 for (ix = 0, max_reached = 0;
937 const char *text,
const char *word)
939 return complete_line_internal (word, text,
947 const char *text,
const char *word)
950 size_t len = strlen (word);
957 if (signum == GDB_SIGNAL_0)
963 if (!signame || strcmp (signame,
"?") == 0)
966 if (strncasecmp (signame, word, len) == 0)
978 complete_register_names = 0x1,
979 complete_reggroup_names = 0x2
987 const char *text,
const char *word,
991 size_t len = strlen (word);
992 struct gdbarch *gdbarch;
995 gdb_assert ((targets & (complete_register_names
996 | complete_reggroup_names)) != 0);
999 if ((targets & complete_register_names) != 0)
1007 if (*name !=
'\0' && strncmp (word, name, len) == 0)
1012 if ((targets & complete_reggroup_names) != 0)
1021 if (strncmp (word, name, len) == 0)
1033 const char *text,
const char *word)
1035 return reg_or_group_completer_1 (ignore, text, word,
1036 (complete_register_names
1037 | complete_reggroup_names));
1044 const char *text,
const char *word)
1046 return reg_or_group_completer_1 (ignore, text, word,
1047 complete_reggroup_names);
1058 list = complete_line_internal (rl_line_buffer, rl_line_buffer, rl_point,
1061 return rl_completer_word_break_characters;
1087 char *line_buffer,
int point)
1091 char *output = NULL;
1108 list = complete_line (text, line_buffer, point);
1131 rl_completer_word_break_characters =
1146 const char *breakchars)
1148 char quote_char =
'\0';
1151 if (quotechars == NULL)
1154 if (breakchars == NULL)
1157 for (scan = str; *scan !=
'\0'; scan++)
1159 if (quote_char !=
'\0')
1162 if (*scan == quote_char)
1169 else if (strchr (quotechars, *scan))
1174 else if (strchr (breakchars, *scan))
1199 return _(
"*** List may be truncated, max-completions reached. ***");
1217 #undef VISIBLE_STATS
1219 #if defined (HANDLE_MULTIBYTE)
1220 #define MB_INVALIDCH(x) ((x) == (size_t)-1 || (x) == (size_t)-2)
1221 #define MB_NULLWCH(x) ((x) == 0)
1224 #define ELLIPSIS_LEN 3
1239 RL_SETSTATE (RL_STATE_MOREINPUT);
1240 c = displayer->
read_key (displayer);
1241 RL_UNSETSTATE (RL_STATE_MOREINPUT);
1243 if (c ==
'y' || c ==
'Y' || c ==
' ')
1245 if (c ==
'n' || c ==
'N' || c == RUBOUT)
1247 if (c == ABORT_CHAR || c < 0)
1256 if (for_pager && (c == NEWLINE || c == RETURN))
1258 if (for_pager && (c ==
'q' || c ==
'Q'))
1260 displayer->
beep (displayer);
1278 displayer->
puts (displayer,
"--More--");
1279 displayer->
flush (displayer);
1298 return (stat (filename, &finfo) == 0 && S_ISDIR (finfo.st_mode));
1317 if (rl_filename_completion_desired == 0)
1320 temp = strrchr (pathname,
'/');
1321 #if defined (__MSDOS__)
1322 if (temp == 0 && ISALPHA ((
unsigned char)pathname[0]) && pathname[1] ==
':')
1323 temp = pathname + 1;
1326 if (temp == 0 || *temp ==
'\0')
1332 else if (temp[1] ==
'\0')
1334 for (x = temp - 1; x > pathname; x--)
1337 return ((*x ==
'/') ? x + 1 : pathname);
1350 #if defined (HANDLE_MULTIBYTE)
1356 left = strlen (
string) + 1;
1357 memset (&ps, 0,
sizeof (mbstate_t));
1363 if (
CTRL_CHAR (
string[pos]) ||
string[pos] == RUBOUT)
1370 #if defined (HANDLE_MULTIBYTE)
1371 clen = mbrtowc (&wc,
string + pos, left - pos, &ps);
1372 if (MB_INVALIDCH (clen))
1376 memset (&ps, 0,
sizeof (mbstate_t));
1378 else if (MB_NULLWCH (clen))
1384 width += (w >= 0) ? w : 1;
1406 #if defined (HANDLE_MULTIBYTE)
1413 end = to_print + strlen (to_print) + 1;
1414 memset (&ps, 0,
sizeof (mbstate_t));
1421 if (to_print[prefix_bytes] ==
'\0')
1428 ellipsis = (to_print[prefix_bytes] ==
'.') ?
'_' :
'.';
1430 displayer->
putch (displayer, ellipsis);
1434 s = to_print + prefix_bytes;
1439 displayer->
putch (displayer,
'^');
1440 displayer->
putch (displayer, UNCTRL (*s));
1443 #if defined (HANDLE_MULTIBYTE)
1444 memset (&ps, 0,
sizeof (mbstate_t));
1447 else if (*s == RUBOUT)
1449 displayer->
putch (displayer,
'^');
1450 displayer->
putch (displayer,
'?');
1453 #if defined (HANDLE_MULTIBYTE)
1454 memset (&ps, 0,
sizeof (mbstate_t));
1459 #if defined (HANDLE_MULTIBYTE)
1460 tlen = mbrtowc (&wc, s, end - s, &ps);
1461 if (MB_INVALIDCH (tlen))
1465 memset (&ps, 0,
sizeof (mbstate_t));
1467 else if (MB_NULLWCH (tlen))
1472 width = (w >= 0) ? w : 1;
1474 for (w = 0; w < tlen; ++w)
1475 displayer->
putch (displayer, s[w]);
1477 printed_len += width;
1479 displayer->
putch (displayer, *s);
1498 int printed_len, extension_char, slen, tlen;
1499 char *s, c, *new_full_pathname, *dn;
1500 extern int _rl_complete_mark_directories;
1503 printed_len =
gdb_fnprint (to_print, prefix_bytes, displayer);
1505 #if defined (VISIBLE_STATS)
1506 if (rl_filename_completion_desired && (rl_visible_stats || _rl_complete_mark_directories))
1508 if (rl_filename_completion_desired && _rl_complete_mark_directories)
1514 if (to_print != full_pathname)
1518 to_print[-1] =
'\0';
1525 if (full_pathname == 0 || *full_pathname == 0)
1527 else if (full_pathname[0] !=
'/')
1529 else if (full_pathname[1] == 0)
1531 else if (full_pathname[1] ==
'/' && full_pathname[2] == 0)
1535 s = tilde_expand (dn);
1536 if (rl_directory_completion_hook)
1537 (*rl_directory_completion_hook) (&s);
1540 tlen = strlen (to_print);
1541 new_full_pathname = (
char *)
xmalloc (slen + tlen + 2);
1542 strcpy (new_full_pathname, s);
1543 if (s[slen - 1] ==
'/')
1546 new_full_pathname[slen] =
'/';
1547 new_full_pathname[slen] =
'/';
1548 strcpy (new_full_pathname + slen + 1, to_print);
1550 #if defined (VISIBLE_STATS)
1551 if (rl_visible_stats)
1552 extension_char = stat_char (new_full_pathname);
1556 extension_char =
'/';
1558 xfree (new_full_pathname);
1563 s = tilde_expand (full_pathname);
1564 #if defined (VISIBLE_STATS)
1565 if (rl_visible_stats)
1566 extension_char = stat_char (s);
1570 extension_char =
'/';
1576 displayer->
putch (displayer, extension_char);
1590 return displayer->
width;
1597 typedef int QSFUNC (
const void *,
const void *);
1607 int count, limit, printed_len, lines, cols;
1608 int i, j, k, l, common_length, sind;
1614 common_length = sind = 0;
1615 if (_rl_completion_prefix_display_length > 0)
1618 temp = strrchr (t,
'/');
1620 sind = temp ? strlen (temp) : strlen (t);
1622 if (common_length > _rl_completion_prefix_display_length && common_length >
ELLIPSIS_LEN)
1625 common_length = sind = 0;
1632 if (limit != 1 && (limit * max == cols))
1636 if (cols < displayer->width && limit < 0)
1645 count = (len + (limit - 1)) / limit;
1652 if (rl_ignore_completion_duplicates == 0 && rl_sort_completion_matches)
1655 displayer->
crlf (displayer);
1658 if (_rl_print_completions_horizontally == 0)
1661 for (i = 1; i <= count; i++)
1663 for (j = 0, l = i; j < limit; j++)
1665 if (l > len || matches[l] == 0)
1674 for (k = 0; k < max - printed_len; k++)
1675 displayer->
putch (displayer,
' ');
1679 displayer->
crlf (displayer);
1681 if (page_completions && lines >= (displayer->
height - 1) && i < count)
1692 for (i = 1; matches[i]; i++)
1699 if (i && (limit > 1) && (i % limit) == 0)
1701 displayer->
crlf (displayer);
1703 if (page_completions && lines >= displayer->
height - 1)
1711 for (k = 0; k < max - printed_len; k++)
1712 displayer->
putch (displayer,
' ');
1715 displayer->
crlf (displayer);
1735 if (max_completions > 0)
1738 if (rl_completion_query_items > 0 && len >= rl_completion_query_items)
1746 displayer->
crlf (displayer);
1749 "Display all %d possibilities? (y or n)", len);
1750 displayer->
puts (displayer, msg);
1751 displayer->
flush (displayer);
1755 displayer->
crlf (displayer);
1763 if (len == max_completions)
1769 displayer->
puts (displayer, message);
1770 displayer->
crlf (displayer);
1781 &max_completions,
_(
"\
1782 Set maximum number of completion candidates."),
_(
"\
1783 Show maximum number of completion candidates."),
_(
"\
1784 Use this to limit the number of candidates considered\n\
1785 during completion. Specifying \"unlimited\" or -1\n\
1786 disables limiting. Note that setting either no limit or\n\
1787 a very large limit can make completion slow."),
const char * user_reg_map_regnum_to_name(struct gdbarch *gdbarch, int regnum)
static char * gdb_printable_part(char *pathname)
static int gdb_fnwidth(const char *string)
struct cleanup * make_cleanup_free_completion_tracker(completion_tracker_t *tracker_ptr)
char * get_gdb_completer_quote_characters(void)
char *(* la_word_break_characters)(void)
initialize_file_ftype _initialize_completer
#define TYPE_FIELD_NAME(thistype, n)
#define TYPE_N_BASECLASSES(thistype)
completer_ftype_void * completer_handle_brkchars
#define TYPE_NFN_FIELDS(thistype)
static void scan(struct macro_buffer *dest, struct macro_buffer *src, struct macro_name_list *no_loop, macro_lookup_ftype *lookup_func, void *lookup_baton)
const char *const * enums
static int gdb_path_isdir(const char *filename)
unsigned int allow_unknown
static char * line_completion_function(const char *text, int matches, char *line_buffer, int point)
static char * gdb_completer_command_word_break_characters
struct cmd_list_element * lookup_cmd_1(const char **text, struct cmd_list_element *clist, struct cmd_list_element **result_list, int ignore_help_classes)
#define VEC_safe_push(T, V, O)
static int gdb_print_filename(char *to_print, char *full_pathname, int prefix_bytes, const struct match_list_displayer *displayer)
struct cmd_list_element * cmdlist
static int gdb_display_match_list_pager(int lines, const struct match_list_displayer *displayer)
complete_line_internal_reason
#define TYPE_FIELD_TYPE(thistype, n)
mld_read_key_ftype * read_key
const char * skip_quoted_chars(const char *str, const char *quotechars, const char *breakchars)
const char * get_max_completions_reached_message(void)
static char * gdb_completer_quote_characters
void null_cleanup(void *arg)
struct cmd_list_element * setlist
#define VEC_iterate(T, V, I, P)
#define CATCH(EXCEPTION, MASK)
void initialize_file_ftype(void)
static char * gdb_completer_file_name_break_characters
const char * skip_quoted(const char *str)
htab_t completion_tracker_t
struct cmd_list_element * showlist
int streq(const char *lhs, const char *rhs)
#define gdb_assert_not_reached(message)
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
static int gdb_get_y_or_n(int for_pager, const struct match_list_displayer *displayer)
struct cleanup * make_cleanup_free_char_ptr_vec(VEC(char_ptr)*char_ptr_vec)
static int gdb_complete_get_screenwidth(const struct match_list_displayer *displayer)
#define VEC_index(T, V, I)
struct gdbarch * get_current_arch(void)
EXTERN_C int _rl_qsort_string_compare(const void *, const void *)
#define CMD_LIST_AMBIGUOUS
const char * gdb_signal_to_name(enum gdb_signal)
#define TYPE_BASECLASS(thistype, index)
int QSFUNC(const void *, const void *)
void set_gdb_completion_word_break_characters(completer_ftype *fn)
char * gdb_completion_word_break_characters(void)
const struct language_defn * current_language
#define TYPE_TARGET_TYPE(thistype)
void add_setshow_zuinteger_unlimited_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
int xsnprintf(char *str, size_t size, const char *format,...)
#define TYPE_CODE(thistype)
maybe_add_completion_enum
int _rl_completion_prefix_display_length
char * readline_line_completion_function(const char *text, int matches)
#define TYPE_NFIELDS(thistype)
#define CHECK_TYPEDEF(TYPE)
mld_erase_entire_line_ftype * erase_entire_line
int _rl_print_completions_horizontally
struct cmd_list_element ** prefixlist
static void add_struct_fields(struct type *type, VEC(char_ptr)**output, char *fieldname, int namelen)
struct reggroup * reggroup_next(struct gdbarch *gdbarch, struct reggroup *last)
struct type * parse_expression_for_completion(const char *, char **, enum type_code *)
#define TYPE_FN_FIELDLIST_NAME(thistype, n)
completion_tracker_t new_completion_tracker(void)
const char * type_name_no_tag(const struct type *type)
completer_ftype * completer
void gdb_display_match_list(char **matches, int len, int max, const struct match_list_displayer *displayer)
void throw_max_completions_reached_error(void)
static int gdb_display_match_list_1(char **matches, int len, int max, const struct match_list_displayer *displayer)
PTR xcalloc(size_t number, size_t size)
static int gdb_fnprint(const char *to_print, int prefix_bytes, const struct match_list_displayer *displayer)
void throw_error(enum errors error, const char *fmt,...)
const char * reggroup_name(struct reggroup *group)
void do_cleanups(struct cleanup *old_chain)
enum maybe_add_completion_enum maybe_add_completion(completion_tracker_t tracker, char *name)
static void free_completion_tracker(void *p)