]>
Commit | Line | Data |
---|---|---|
6ed6bacf AM |
1 | http://sourceware.org/ml/gdb-patches/2011-04/msg00125.html |
2 | Subject: [patch 2/3] case insensitive: re_comp->regcomp | |
3 | ||
4 | Hi, | |
5 | ||
6 | re_comp cannot be passed REG_ICASE. Therefore change the code. The should | |
7 | have no functionality impact. | |
8 | ||
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. | |
15 | ||
16 | ||
17 | Thanks, | |
18 | Jan | |
19 | ||
20 | ||
21 | gdb/ | |
22 | 2011-04-08 Jan Kratochvil <jan.kratochvil@redhat.com> | |
23 | ||
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. | |
30 | ||
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 | |
36 | { | |
37 | int nfiles; | |
38 | char **files; | |
39 | - char *regexp; | |
40 | + | |
41 | + /* It is true if PREG contains valid data, false otherwise. */ | |
42 | + unsigned preg_p : 1; | |
43 | + regex_t preg; | |
44 | }; | |
45 | ||
46 | /* A callback for expand_symtabs_matching. */ | |
47 | @@ -2976,7 +2979,7 @@ search_symbols_name_matches (const char | |
48 | { | |
49 | struct search_symbols_data *data = user_data; | |
50 | ||
51 | - return data->regexp == NULL || re_exec (symname); | |
52 | + return !data->preg_p || regexec (&data->preg, symname, 0, NULL, 0) == 0; | |
53 | } | |
54 | ||
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; | |
62 | ||
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; | |
67 | + | |
68 | if (kind < VARIABLES_DOMAIN || kind >= ALL_DOMAIN) | |
69 | error (_("must search on specific domain")); | |
70 | ||
71 | @@ -3036,6 +3043,7 @@ search_symbols (char *regexp, domain_enu | |
72 | ||
73 | sr = *matches = NULL; | |
74 | tail = NULL; | |
75 | + datum.preg_p = 0; | |
76 | ||
77 | if (regexp != NULL) | |
78 | { | |
79 | @@ -3045,6 +3053,7 @@ search_symbols (char *regexp, domain_enu | |
80 | and <TYPENAME> or <OPERATOR>. */ | |
81 | char *opend; | |
82 | char *opname = operator_chars (regexp, &opend); | |
83 | + int errcode; | |
84 | ||
85 | if (*opname) | |
86 | { | |
87 | @@ -3073,8 +3082,16 @@ search_symbols (char *regexp, domain_enu | |
88 | } | |
89 | } | |
90 | ||
91 | - if (0 != (val = re_comp (regexp))) | |
92 | - error (_("Invalid regexp (%s): %s"), val, regexp); | |
93 | + errcode = regcomp (&datum.preg, regexp, REG_NOSUB); | |
94 | + if (errcode != 0) | |
95 | + { | |
96 | + char *err = get_regcomp_error (errcode, &datum.preg); | |
97 | + | |
98 | + make_cleanup (xfree, err); | |
99 | + error (_("Invalid regexp (%s): %s"), err, regexp); | |
100 | + } | |
101 | + datum.preg_p = 1; | |
102 | + make_regfree_cleanup (&datum.preg); | |
103 | } | |
104 | ||
105 | /* Search through the partial symtabs *first* for all symbols | |
106 | @@ -3083,7 +3100,6 @@ search_symbols (char *regexp, domain_enu | |
107 | ||
108 | datum.nfiles = nfiles; | |
109 | datum.files = files; | |
110 | - datum.regexp = regexp; | |
111 | ALL_OBJFILES (objfile) | |
112 | { | |
113 | if (objfile->sf) | |
114 | @@ -3094,6 +3110,8 @@ search_symbols (char *regexp, domain_enu | |
115 | &datum); | |
116 | } | |
117 | ||
118 | + retval_chain = old_chain; | |
119 | + | |
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) | |
126 | { | |
127 | - if (regexp == NULL | |
128 | - || re_exec (SYMBOL_NATURAL_NAME (msymbol)) != 0) | |
129 | + if (!datum.preg_p | |
130 | + || regexec (&datum.preg, SYMBOL_NATURAL_NAME (msymbol), 0, | |
131 | + NULL, 0) == 0) | |
132 | { | |
133 | if (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol))) | |
134 | { | |
135 | @@ -3156,8 +3175,9 @@ search_symbols (char *regexp, domain_enu | |
136 | QUIT; | |
137 | ||
138 | if (file_matches (real_symtab->filename, files, nfiles) | |
139 | - && ((regexp == NULL | |
140 | - || re_exec (SYMBOL_NATURAL_NAME (sym)) != 0) | |
141 | + && ((!datum.preg_p | |
142 | + || regexec (&datum.preg, SYMBOL_NATURAL_NAME (sym), 0, | |
143 | + NULL, 0) == 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); | |
149 | sr = dummy.next; | |
150 | ||
151 | - old_chain = make_cleanup_free_search_symbols (sr); | |
152 | + make_cleanup_free_search_symbols (sr); | |
153 | } | |
154 | else | |
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) | |
159 | { | |
160 | - if (regexp == NULL | |
161 | - || re_exec (SYMBOL_NATURAL_NAME (msymbol)) != 0) | |
162 | + if (!datum.preg_p | |
163 | + || regexec (&datum.preg, SYMBOL_NATURAL_NAME (msymbol), 0, | |
164 | + NULL, 0) == 0) | |
165 | { | |
166 | /* Functions: Look up by address. */ | |
167 | if (kind != FUNCTIONS_DOMAIN || | |
168 | @@ -3244,7 +3265,7 @@ search_symbols (char *regexp, domain_enu | |
169 | if (tail == NULL) | |
170 | { | |
171 | sr = psr; | |
172 | - old_chain = make_cleanup_free_search_symbols (sr); | |
173 | + make_cleanup_free_search_symbols (sr); | |
174 | } | |
175 | else | |
176 | tail->next = psr; | |
177 | @@ -3256,9 +3277,9 @@ search_symbols (char *regexp, domain_enu | |
178 | } | |
179 | } | |
180 | ||
181 | + discard_cleanups (retval_chain); | |
182 | + do_cleanups (old_chain); | |
183 | *matches = sr; | |
184 | - if (sr != NULL) | |
185 | - discard_cleanups (old_chain); | |
186 | } | |
187 | ||
188 | /* Helper function for symtab_symbol_info, this function uses |