1 http://sourceware.org/ml/gdb-patches/2011-04/msg00125.html
2 Subject: [patch 2/3] case insensitive: re_comp->regcomp
6 re_comp cannot be passed REG_ICASE. Therefore change the code. The should
7 have no functionality impact.
9 The new boolean field `preg_p' could be maybe replaced by a conditional
10 `preg.buffer != NULL' which would work with libiberty regcomp implementation
11 but I do not see it guaranteed anywhere. GDB is always using static libiberty
12 implementation which I do not see why in the case it is running on glibc.
13 But if it gets fixed one day and it starts to use externally linked
14 regcomp/regexec I would find the `preg.buffer != NULL' conditional dangerous.
22 2011-04-08 Jan Kratochvil <jan.kratochvil@redhat.com>
24 Replace re_comp/re_exec by regcomp/regexec.
25 * symtab.c (struct search_symbols_data): New fields preg, preg_p.
26 (search_symbols_name_matches): Use them, use regexec.
27 (search_symbols): New variable retval_chain, adjust the use of
28 old_chain against it. Replace re_comp by regcomp. Use the new struct
29 search_symbols_data fields, use regexec instead of re_exec.
31 Index: gdb-7.2.90.20110429/gdb/symtab.c
32 ===================================================================
33 --- gdb-7.2.90.20110429.orig/gdb/symtab.c 2011-04-29 09:43:33.000000000 +0200
34 +++ gdb-7.2.90.20110429/gdb/symtab.c 2011-04-29 09:43:55.000000000 +0200
35 @@ -2958,7 +2958,10 @@ struct search_symbols_data
41 + /* It is true if PREG contains valid data, false otherwise. */
42 + unsigned preg_p : 1;
46 /* A callback for expand_symtabs_matching. */
47 @@ -2976,7 +2979,7 @@ search_symbols_name_matches (const char
49 struct search_symbols_data *data = user_data;
51 - return data->regexp == NULL || re_exec (symname);
52 + return !data->preg_p || regexec (&data->preg, symname, 0, NULL, 0) == 0;
55 /* Search the symbol table for matches to the regular expression REGEXP,
56 @@ -3023,9 +3026,13 @@ search_symbols (char *regexp, domain_enu
57 struct symbol_search *sr;
58 struct symbol_search *psr;
59 struct symbol_search *tail;
60 - struct cleanup *old_chain = NULL;
61 struct search_symbols_data datum;
63 + /* OLD_CHAIN .. RETVAL_CHAIN is always freed, RETVAL_CHAIN .. current
64 + CLEANUP_CHAIN is freed only in the case of an error. */
65 + struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
66 + struct cleanup *retval_chain;
68 if (kind < VARIABLES_DOMAIN || kind >= ALL_DOMAIN)
69 error (_("must search on specific domain"));
71 @@ -3036,6 +3043,7 @@ search_symbols (char *regexp, domain_enu
79 @@ -3045,6 +3053,7 @@ search_symbols (char *regexp, domain_enu
80 and <TYPENAME> or <OPERATOR>. */
82 char *opname = operator_chars (regexp, &opend);
87 @@ -3073,8 +3082,16 @@ search_symbols (char *regexp, domain_enu
91 - if (0 != (val = re_comp (regexp)))
92 - error (_("Invalid regexp (%s): %s"), val, regexp);
93 + errcode = regcomp (&datum.preg, regexp, REG_NOSUB);
96 + char *err = get_regcomp_error (errcode, &datum.preg);
98 + make_cleanup (xfree, err);
99 + error (_("Invalid regexp (%s): %s"), err, regexp);
102 + make_regfree_cleanup (&datum.preg);
105 /* Search through the partial symtabs *first* for all symbols
106 @@ -3083,7 +3100,6 @@ search_symbols (char *regexp, domain_enu
108 datum.nfiles = nfiles;
110 - datum.regexp = regexp;
111 ALL_OBJFILES (objfile)
114 @@ -3094,6 +3110,8 @@ search_symbols (char *regexp, domain_enu
118 + retval_chain = old_chain;
120 /* Here, we search through the minimal symbol tables for functions
121 and variables that match, and force their symbols to be read.
122 This is in particular necessary for demangled variable names,
123 @@ -3117,8 +3135,9 @@ search_symbols (char *regexp, domain_enu
124 MSYMBOL_TYPE (msymbol) == ourtype3 ||
125 MSYMBOL_TYPE (msymbol) == ourtype4)
128 - || re_exec (SYMBOL_NATURAL_NAME (msymbol)) != 0)
130 + || regexec (&datum.preg, SYMBOL_NATURAL_NAME (msymbol), 0,
133 if (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol)))
135 @@ -3156,8 +3175,9 @@ search_symbols (char *regexp, domain_enu
138 if (file_matches (real_symtab->filename, files, nfiles)
139 - && ((regexp == NULL
140 - || re_exec (SYMBOL_NATURAL_NAME (sym)) != 0)
142 + || regexec (&datum.preg, SYMBOL_NATURAL_NAME (sym), 0,
144 && ((kind == VARIABLES_DOMAIN
145 && SYMBOL_CLASS (sym) != LOC_TYPEDEF
146 && SYMBOL_CLASS (sym) != LOC_UNRESOLVED
147 @@ -3199,7 +3219,7 @@ search_symbols (char *regexp, domain_enu
148 tail = sort_search_symbols (&dummy, nfound);
151 - old_chain = make_cleanup_free_search_symbols (sr);
152 + make_cleanup_free_search_symbols (sr);
155 tail = sort_search_symbols (prevtail, nfound);
156 @@ -3221,8 +3241,9 @@ search_symbols (char *regexp, domain_enu
157 MSYMBOL_TYPE (msymbol) == ourtype3 ||
158 MSYMBOL_TYPE (msymbol) == ourtype4)
161 - || re_exec (SYMBOL_NATURAL_NAME (msymbol)) != 0)
163 + || regexec (&datum.preg, SYMBOL_NATURAL_NAME (msymbol), 0,
166 /* Functions: Look up by address. */
167 if (kind != FUNCTIONS_DOMAIN ||
168 @@ -3244,7 +3265,7 @@ search_symbols (char *regexp, domain_enu
172 - old_chain = make_cleanup_free_search_symbols (sr);
173 + make_cleanup_free_search_symbols (sr);
177 @@ -3256,9 +3277,9 @@ search_symbols (char *regexp, domain_enu
181 + discard_cleanups (retval_chain);
182 + do_cleanups (old_chain);
185 - discard_cleanups (old_chain);
188 /* Helper function for symtab_symbol_info, this function uses