]>
Commit | Line | Data |
---|---|---|
bd5635a1 | 1 | /* Symbol table lookup for the GNU debugger, GDB. |
9b041f69 | 2 | Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995 |
87041845 | 3 | Free Software Foundation, Inc. |
bd5635a1 RP |
4 | |
5 | This file is part of GDB. | |
6 | ||
997a978c | 7 | This program is free software; you can redistribute it and/or modify |
bd5635a1 | 8 | it under the terms of the GNU General Public License as published by |
997a978c JG |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. | |
bd5635a1 | 11 | |
997a978c | 12 | This program is distributed in the hope that it will be useful, |
bd5635a1 RP |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
997a978c | 18 | along with this program; if not, write to the Free Software |
f21c9aec | 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
bd5635a1 | 20 | |
bd5635a1 RP |
21 | #include "defs.h" |
22 | #include "symtab.h" | |
cba0d141 | 23 | #include "gdbtypes.h" |
bd5635a1 RP |
24 | #include "gdbcore.h" |
25 | #include "frame.h" | |
26 | #include "target.h" | |
27 | #include "value.h" | |
28 | #include "symfile.h" | |
35a25840 | 29 | #include "objfiles.h" |
bd5635a1 | 30 | #include "gdbcmd.h" |
35a25840 | 31 | #include "call-cmds.h" |
811f1bdc | 32 | #include "gnu-regex.h" |
cba0d141 | 33 | #include "expression.h" |
997a978c | 34 | #include "language.h" |
f70be3e4 | 35 | #include "demangle.h" |
bd5635a1 | 36 | |
1750a5ef | 37 | #include "obstack.h" |
bd5635a1 RP |
38 | |
39 | #include <sys/types.h> | |
40 | #include <fcntl.h> | |
2b576293 C |
41 | #include "gdb_string.h" |
42 | #include "gdb_stat.h" | |
2cd99985 | 43 | #include <ctype.h> |
bd5635a1 | 44 | |
cba0d141 | 45 | /* Prototypes for local functions */ |
bd5635a1 | 46 | |
2cd99985 | 47 | extern int |
2e4964ad | 48 | find_methods PARAMS ((struct type *, char *, struct symbol **)); |
cba0d141 JG |
49 | |
50 | static void | |
f1ed4330 | 51 | completion_list_add_name PARAMS ((char *, char *, int, char *, char *)); |
cba0d141 | 52 | |
6f87ec4a PS |
53 | static void |
54 | build_canonical_line_spec PARAMS ((struct symtab_and_line *, char *, char ***)); | |
55 | ||
cba0d141 | 56 | static struct symtabs_and_lines |
6f87ec4a | 57 | decode_line_2 PARAMS ((struct symbol *[], int, int, char ***)); |
cba0d141 JG |
58 | |
59 | static void | |
35a25840 | 60 | rbreak_command PARAMS ((char *, int)); |
cba0d141 JG |
61 | |
62 | static void | |
35a25840 | 63 | types_info PARAMS ((char *, int)); |
cba0d141 JG |
64 | |
65 | static void | |
35a25840 | 66 | functions_info PARAMS ((char *, int)); |
cba0d141 JG |
67 | |
68 | static void | |
35a25840 | 69 | variables_info PARAMS ((char *, int)); |
cba0d141 JG |
70 | |
71 | static void | |
35a25840 | 72 | sources_info PARAMS ((char *, int)); |
cba0d141 JG |
73 | |
74 | static void | |
ae6d035d | 75 | list_symbols PARAMS ((char *, int, int, int)); |
cba0d141 JG |
76 | |
77 | static void | |
78 | output_source_filename PARAMS ((char *, int *)); | |
79 | ||
80 | static char * | |
81 | operator_chars PARAMS ((char *, char **)); | |
82 | ||
018ab14f | 83 | static int find_line_common PARAMS ((struct linetable *, int, int *)); |
cba0d141 JG |
84 | |
85 | static struct partial_symbol * | |
86 | lookup_partial_symbol PARAMS ((struct partial_symtab *, const char *, | |
1750a5ef | 87 | int, namespace_enum)); |
cba0d141 | 88 | |
cba0d141 JG |
89 | static struct symtab * |
90 | lookup_symtab_1 PARAMS ((char *)); | |
91 | ||
b607efe7 FF |
92 | static void |
93 | cplusplus_hint PARAMS ((char *)); | |
94 | ||
cba0d141 | 95 | /* */ |
bd5635a1 | 96 | |
997a978c | 97 | /* The single non-language-specific builtin type */ |
bd5635a1 RP |
98 | struct type *builtin_type_error; |
99 | ||
100 | /* Block in which the most recently searched-for symbol was found. | |
101 | Might be better to make this a parameter to lookup_symbol and | |
102 | value_of_this. */ | |
cba0d141 JG |
103 | |
104 | const struct block *block_found; | |
bd5635a1 RP |
105 | |
106 | char no_symtab_msg[] = "No symbol table is loaded. Use the \"file\" command."; | |
107 | ||
f70be3e4 JG |
108 | /* While the C++ support is still in flux, issue a possibly helpful hint on |
109 | using the new command completion feature on single quoted demangled C++ | |
110 | symbols. Remove when loose ends are cleaned up. FIXME -fnf */ | |
111 | ||
b607efe7 | 112 | static void |
f70be3e4 JG |
113 | cplusplus_hint (name) |
114 | char *name; | |
115 | { | |
9b041f69 PS |
116 | while (*name == '\'') |
117 | name++; | |
1c95d7ab JK |
118 | printf_filtered ("Hint: try '%s<TAB> or '%s<ESC-?>\n", name, name); |
119 | printf_filtered ("(Note leading single quote.)\n"); | |
f70be3e4 JG |
120 | } |
121 | ||
bd5635a1 RP |
122 | /* Check for a symtab of a specific name; first in symtabs, then in |
123 | psymtabs. *If* there is no '/' in the name, a match after a '/' | |
124 | in the symtab filename will also work. */ | |
125 | ||
126 | static struct symtab * | |
127 | lookup_symtab_1 (name) | |
128 | char *name; | |
129 | { | |
130 | register struct symtab *s; | |
131 | register struct partial_symtab *ps; | |
35a25840 | 132 | register char *slash; |
cba0d141 | 133 | register struct objfile *objfile; |
bd5635a1 | 134 | |
784fd92b | 135 | got_symtab: |
35a25840 | 136 | |
784fd92b SG |
137 | /* First, search for an exact match */ |
138 | ||
139 | ALL_SYMTABS (objfile, s) | |
2e4964ad | 140 | if (STREQ (name, s->filename)) |
784fd92b | 141 | return s; |
35a25840 SG |
142 | |
143 | slash = strchr (name, '/'); | |
784fd92b SG |
144 | |
145 | /* Now, search for a matching tail (only if name doesn't have any dirs) */ | |
35a25840 | 146 | |
bd5635a1 | 147 | if (!slash) |
784fd92b SG |
148 | ALL_SYMTABS (objfile, s) |
149 | { | |
150 | char *p = s -> filename; | |
151 | char *tail = strrchr (p, '/'); | |
152 | ||
153 | if (tail) | |
154 | p = tail + 1; | |
155 | ||
2e4964ad | 156 | if (STREQ (p, name)) |
784fd92b SG |
157 | return s; |
158 | } | |
159 | ||
160 | /* Same search rules as above apply here, but now we look thru the | |
161 | psymtabs. */ | |
162 | ||
ad0a2521 JK |
163 | ps = lookup_partial_symtab (name); |
164 | if (!ps) | |
165 | return (NULL); | |
784fd92b SG |
166 | |
167 | if (ps -> readin) | |
35fcebce PB |
168 | error ("Internal: readin %s pst for `%s' found when no symtab found.", |
169 | ps -> filename, name); | |
784fd92b SG |
170 | |
171 | s = PSYMTAB_TO_SYMTAB (ps); | |
172 | ||
173 | if (s) | |
174 | return s; | |
175 | ||
176 | /* At this point, we have located the psymtab for this file, but | |
177 | the conversion to a symtab has failed. This usually happens | |
178 | when we are looking up an include file. In this case, | |
179 | PSYMTAB_TO_SYMTAB doesn't return a symtab, even though one has | |
180 | been created. So, we need to run through the symtabs again in | |
181 | order to find the file. | |
182 | XXX - This is a crock, and should be fixed inside of the the | |
183 | symbol parsing routines. */ | |
184 | goto got_symtab; | |
bd5635a1 RP |
185 | } |
186 | ||
187 | /* Lookup the symbol table of a source file named NAME. Try a couple | |
188 | of variations if the first lookup doesn't work. */ | |
189 | ||
190 | struct symtab * | |
191 | lookup_symtab (name) | |
192 | char *name; | |
193 | { | |
194 | register struct symtab *s; | |
1c95d7ab | 195 | #if 0 |
bd5635a1 | 196 | register char *copy; |
1c95d7ab | 197 | #endif |
bd5635a1 RP |
198 | |
199 | s = lookup_symtab_1 (name); | |
200 | if (s) return s; | |
201 | ||
d8a66e60 JK |
202 | #if 0 |
203 | /* This screws c-exp.y:yylex if there is both a type "tree" and a symtab | |
204 | "tree.c". */ | |
205 | ||
bd5635a1 | 206 | /* If name not found as specified, see if adding ".c" helps. */ |
ad0a2521 JK |
207 | /* Why is this? Is it just a user convenience? (If so, it's pretty |
208 | questionable in the presence of C++, FORTRAN, etc.). It's not in | |
209 | the GDB manual. */ | |
bd5635a1 RP |
210 | |
211 | copy = (char *) alloca (strlen (name) + 3); | |
212 | strcpy (copy, name); | |
213 | strcat (copy, ".c"); | |
214 | s = lookup_symtab_1 (copy); | |
215 | if (s) return s; | |
d8a66e60 | 216 | #endif /* 0 */ |
bd5635a1 RP |
217 | |
218 | /* We didn't find anything; die. */ | |
219 | return 0; | |
220 | } | |
221 | ||
ad0a2521 JK |
222 | /* Lookup the partial symbol table of a source file named NAME. |
223 | *If* there is no '/' in the name, a match after a '/' | |
224 | in the psymtab filename will also work. */ | |
bd5635a1 RP |
225 | |
226 | struct partial_symtab * | |
227 | lookup_partial_symtab (name) | |
228 | char *name; | |
229 | { | |
cba0d141 JG |
230 | register struct partial_symtab *pst; |
231 | register struct objfile *objfile; | |
bd5635a1 | 232 | |
35a25840 | 233 | ALL_PSYMTABS (objfile, pst) |
bd5635a1 | 234 | { |
2e4964ad | 235 | if (STREQ (name, pst -> filename)) |
bd5635a1 | 236 | { |
35a25840 | 237 | return (pst); |
bd5635a1 | 238 | } |
35a25840 | 239 | } |
ad0a2521 JK |
240 | |
241 | /* Now, search for a matching tail (only if name doesn't have any dirs) */ | |
242 | ||
243 | if (!strchr (name, '/')) | |
244 | ALL_PSYMTABS (objfile, pst) | |
245 | { | |
246 | char *p = pst -> filename; | |
247 | char *tail = strrchr (p, '/'); | |
248 | ||
249 | if (tail) | |
250 | p = tail + 1; | |
251 | ||
252 | if (STREQ (p, name)) | |
253 | return (pst); | |
254 | } | |
255 | ||
cba0d141 | 256 | return (NULL); |
bd5635a1 | 257 | } |
cba0d141 | 258 | \f |
0b28c260 JK |
259 | /* Demangle a GDB method stub type. |
260 | Note that this function is g++ specific. */ | |
261 | ||
bd5635a1 | 262 | char * |
bcccec8c | 263 | gdb_mangle_name (type, i, j) |
bd5635a1 | 264 | struct type *type; |
bcccec8c | 265 | int i, j; |
bd5635a1 | 266 | { |
bcccec8c PB |
267 | int mangled_name_len; |
268 | char *mangled_name; | |
269 | struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i); | |
270 | struct fn_field *method = &f[j]; | |
271 | char *field_name = TYPE_FN_FIELDLIST_NAME (type, i); | |
8050a57b | 272 | char *physname = TYPE_FN_FIELD_PHYSNAME (f, j); |
35fcebce | 273 | char *newname = type_name_no_tag (type); |
d47a7f52 JK |
274 | |
275 | /* Does the form of physname indicate that it is the full mangled name | |
276 | of a constructor (not just the args)? */ | |
277 | int is_full_physname_constructor; | |
278 | ||
ad0a2521 | 279 | int is_constructor; |
2d575e6f | 280 | int is_destructor = DESTRUCTOR_PREFIX_P (physname); |
bcccec8c | 281 | /* Need a new type prefix. */ |
bcccec8c PB |
282 | char *const_prefix = method->is_const ? "C" : ""; |
283 | char *volatile_prefix = method->is_volatile ? "V" : ""; | |
bcccec8c | 284 | char buf[20]; |
ad0a2521 | 285 | int len = (newname == NULL ? 0 : strlen (newname)); |
ad0a2521 | 286 | |
d47a7f52 JK |
287 | is_full_physname_constructor = |
288 | ((physname[0]=='_' && physname[1]=='_' && | |
289 | (isdigit(physname[2]) || physname[2]=='Q' || physname[2]=='t')) | |
290 | || (strncmp(physname, "__ct", 4) == 0)); | |
291 | ||
292 | is_constructor = | |
293 | is_full_physname_constructor || (newname && STREQ(field_name, newname)); | |
294 | ||
ad0a2521 JK |
295 | if (!is_destructor) |
296 | is_destructor = (strncmp(physname, "__dt", 4) == 0); | |
35fcebce | 297 | |
d47a7f52 | 298 | if (is_destructor || is_full_physname_constructor) |
35fcebce PB |
299 | { |
300 | mangled_name = (char*) xmalloc(strlen(physname)+1); | |
301 | strcpy(mangled_name, physname); | |
302 | return mangled_name; | |
303 | } | |
304 | ||
ad0a2521 JK |
305 | if (len == 0) |
306 | { | |
307 | sprintf (buf, "__%s%s", const_prefix, volatile_prefix); | |
308 | if (strcmp(buf, "__") == 0) | |
309 | buf[0] = '\0'; | |
310 | } | |
76212295 PS |
311 | else if (newname != NULL && strchr (newname, '<') != NULL) |
312 | { | |
313 | /* Template methods are fully mangled. */ | |
314 | sprintf (buf, "__%s%s", const_prefix, volatile_prefix); | |
315 | newname = NULL; | |
316 | len = 0; | |
317 | } | |
ad0a2521 JK |
318 | else |
319 | { | |
320 | sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len); | |
321 | } | |
35fcebce PB |
322 | mangled_name_len = ((is_constructor ? 0 : strlen (field_name)) |
323 | + strlen (buf) + len | |
324 | + strlen (physname) | |
325 | + 1); | |
326 | ||
327 | /* Only needed for GNU-mangled names. ANSI-mangled names | |
328 | work with the normal mechanisms. */ | |
329 | if (OPNAME_PREFIX_P (field_name)) | |
330 | { | |
b607efe7 | 331 | const char *opname = cplus_mangle_opname (field_name + 3, 0); |
35fcebce PB |
332 | if (opname == NULL) |
333 | error ("No mangling for \"%s\"", field_name); | |
334 | mangled_name_len += strlen (opname); | |
335 | mangled_name = (char *)xmalloc (mangled_name_len); | |
336 | ||
337 | strncpy (mangled_name, field_name, 3); | |
338 | mangled_name[3] = '\0'; | |
339 | strcat (mangled_name, opname); | |
340 | } | |
341 | else | |
342 | { | |
343 | mangled_name = (char *)xmalloc (mangled_name_len); | |
344 | if (is_constructor) | |
345 | mangled_name[0] = '\0'; | |
346 | else | |
347 | strcpy (mangled_name, field_name); | |
348 | } | |
349 | strcat (mangled_name, buf); | |
018ab14f PS |
350 | /* If the class doesn't have a name, i.e. newname NULL, then we just |
351 | mangle it using 0 for the length of the class. Thus it gets mangled | |
2d575e6f | 352 | as something starting with `::' rather than `classname::'. */ |
018ab14f PS |
353 | if (newname != NULL) |
354 | strcat (mangled_name, newname); | |
2d575e6f | 355 | |
35fcebce | 356 | strcat (mangled_name, physname); |
8050a57b | 357 | return (mangled_name); |
bd5635a1 RP |
358 | } |
359 | ||
cba0d141 JG |
360 | \f |
361 | /* Find which partial symtab on contains PC. Return 0 if none. */ | |
f1d77e90 | 362 | |
cba0d141 JG |
363 | struct partial_symtab * |
364 | find_pc_psymtab (pc) | |
365 | register CORE_ADDR pc; | |
d96b54ea | 366 | { |
cba0d141 JG |
367 | register struct partial_symtab *pst; |
368 | register struct objfile *objfile; | |
d96b54ea | 369 | |
35a25840 | 370 | ALL_PSYMTABS (objfile, pst) |
bd5635a1 | 371 | { |
c1878f87 | 372 | if (pc >= pst->textlow && pc < pst->texthigh) |
76212295 PS |
373 | { |
374 | struct minimal_symbol *msymbol; | |
375 | struct partial_symtab *tpst; | |
376 | ||
377 | /* An objfile that has its functions reordered might have | |
378 | many partial symbol tables containing the PC, but | |
379 | we want the partial symbol table that contains the | |
380 | function containing the PC. */ | |
381 | if (!(objfile->flags & OBJF_REORDERED)) | |
382 | return (pst); | |
383 | ||
384 | msymbol = lookup_minimal_symbol_by_pc (pc); | |
385 | if (msymbol == NULL) | |
386 | return (pst); | |
387 | ||
388 | for (tpst = pst; tpst != NULL; tpst = tpst->next) | |
389 | { | |
390 | if (pc >= tpst->textlow && pc < tpst->texthigh) | |
391 | { | |
392 | struct partial_symbol *p; | |
393 | ||
394 | p = find_pc_psymbol (tpst, pc); | |
395 | if (p != NULL | |
396 | && SYMBOL_VALUE_ADDRESS(p) | |
397 | == SYMBOL_VALUE_ADDRESS (msymbol)) | |
398 | return (tpst); | |
399 | } | |
400 | } | |
401 | return (pst); | |
402 | } | |
bd5635a1 | 403 | } |
cba0d141 | 404 | return (NULL); |
bd5635a1 RP |
405 | } |
406 | ||
407 | /* Find which partial symbol within a psymtab contains PC. Return 0 | |
408 | if none. Check all psymtabs if PSYMTAB is 0. */ | |
409 | struct partial_symbol * | |
410 | find_pc_psymbol (psymtab, pc) | |
411 | struct partial_symtab *psymtab; | |
412 | CORE_ADDR pc; | |
413 | { | |
b607efe7 | 414 | struct partial_symbol *best = NULL, *p, **pp; |
bd5635a1 RP |
415 | CORE_ADDR best_pc; |
416 | ||
417 | if (!psymtab) | |
418 | psymtab = find_pc_psymtab (pc); | |
419 | if (!psymtab) | |
420 | return 0; | |
421 | ||
422 | best_pc = psymtab->textlow - 1; | |
423 | ||
d8a66e60 JK |
424 | /* Search the global symbols as well as the static symbols, so that |
425 | find_pc_partial_function doesn't use a minimal symbol and thus | |
426 | cache a bad endaddr. */ | |
b607efe7 FF |
427 | for (pp = psymtab->objfile->global_psymbols.list + psymtab->globals_offset; |
428 | (pp - (psymtab->objfile->global_psymbols.list + psymtab->globals_offset) | |
d8a66e60 | 429 | < psymtab->n_global_syms); |
b607efe7 FF |
430 | pp++) |
431 | { | |
432 | p = *pp; | |
433 | if (SYMBOL_NAMESPACE (p) == VAR_NAMESPACE | |
434 | && SYMBOL_CLASS (p) == LOC_BLOCK | |
435 | && pc >= SYMBOL_VALUE_ADDRESS (p) | |
436 | && SYMBOL_VALUE_ADDRESS (p) > best_pc) | |
437 | { | |
438 | best_pc = SYMBOL_VALUE_ADDRESS (p); | |
439 | best = p; | |
440 | } | |
441 | } | |
442 | for (pp = psymtab->objfile->static_psymbols.list + psymtab->statics_offset; | |
443 | (pp - (psymtab->objfile->static_psymbols.list + psymtab->statics_offset) | |
bd5635a1 | 444 | < psymtab->n_static_syms); |
b607efe7 FF |
445 | pp++) |
446 | { | |
447 | p = *pp; | |
448 | if (SYMBOL_NAMESPACE (p) == VAR_NAMESPACE | |
449 | && SYMBOL_CLASS (p) == LOC_BLOCK | |
450 | && pc >= SYMBOL_VALUE_ADDRESS (p) | |
451 | && SYMBOL_VALUE_ADDRESS (p) > best_pc) | |
452 | { | |
453 | best_pc = SYMBOL_VALUE_ADDRESS (p); | |
454 | best = p; | |
455 | } | |
456 | } | |
bd5635a1 RP |
457 | if (best_pc == psymtab->textlow - 1) |
458 | return 0; | |
459 | return best; | |
460 | } | |
461 | ||
462 | \f | |
463 | /* Find the definition for a specified symbol name NAME | |
464 | in namespace NAMESPACE, visible from lexical block BLOCK. | |
465 | Returns the struct symbol pointer, or zero if no symbol is found. | |
466 | If SYMTAB is non-NULL, store the symbol table in which the | |
467 | symbol was found there, or NULL if not found. | |
468 | C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if | |
469 | NAME is a field of the current implied argument `this'. If so set | |
470 | *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero. | |
471 | BLOCK_FOUND is set to the block in which NAME is found (in the case of | |
472 | a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */ | |
473 | ||
87041845 JK |
474 | /* This function has a bunch of loops in it and it would seem to be |
475 | attractive to put in some QUIT's (though I'm not really sure | |
476 | whether it can run long enough to be really important). But there | |
477 | are a few calls for which it would appear to be bad news to quit | |
478 | out of here: find_proc_desc in alpha-tdep.c and mips-tdep.c, and | |
479 | nindy_frame_chain_valid in nindy-tdep.c. (Note that there is C++ | |
480 | code below which can error(), but that probably doesn't affect | |
481 | these calls since they are looking for a known variable and thus | |
482 | can probably assume it will never hit the C++ code). */ | |
483 | ||
bd5635a1 RP |
484 | struct symbol * |
485 | lookup_symbol (name, block, namespace, is_a_field_of_this, symtab) | |
cba0d141 JG |
486 | const char *name; |
487 | register const struct block *block; | |
1750a5ef | 488 | const namespace_enum namespace; |
bd5635a1 RP |
489 | int *is_a_field_of_this; |
490 | struct symtab **symtab; | |
491 | { | |
492 | register struct symbol *sym; | |
01d3fdba | 493 | register struct symtab *s = NULL; |
bd5635a1 RP |
494 | register struct partial_symtab *ps; |
495 | struct blockvector *bv; | |
cba0d141 JG |
496 | register struct objfile *objfile; |
497 | register struct block *b; | |
cba0d141 | 498 | register struct minimal_symbol *msymbol; |
f70be3e4 | 499 | |
bd5635a1 RP |
500 | /* Search specified block and its superiors. */ |
501 | ||
502 | while (block != 0) | |
503 | { | |
504 | sym = lookup_block_symbol (block, name, namespace); | |
505 | if (sym) | |
506 | { | |
507 | block_found = block; | |
508 | if (symtab != NULL) | |
509 | { | |
510 | /* Search the list of symtabs for one which contains the | |
511 | address of the start of this block. */ | |
35a25840 | 512 | ALL_SYMTABS (objfile, s) |
bd5635a1 | 513 | { |
35a25840 SG |
514 | bv = BLOCKVECTOR (s); |
515 | b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
516 | if (BLOCK_START (b) <= BLOCK_START (block) | |
517 | && BLOCK_END (b) > BLOCK_START (block)) | |
518 | goto found; | |
bd5635a1 | 519 | } |
35a25840 | 520 | found: |
bd5635a1 RP |
521 | *symtab = s; |
522 | } | |
523 | ||
cba0d141 | 524 | return (sym); |
bd5635a1 RP |
525 | } |
526 | block = BLOCK_SUPERBLOCK (block); | |
527 | } | |
528 | ||
0b28c260 JK |
529 | /* FIXME: this code is never executed--block is always NULL at this |
530 | point. What is it trying to do, anyway? We already should have | |
531 | checked the STATIC_BLOCK above (it is the superblock of top-level | |
532 | blocks). Why is VAR_NAMESPACE special-cased? */ | |
2e4964ad | 533 | /* Don't need to mess with the psymtabs; if we have a block, |
b039ac3a JK |
534 | that file is read in. If we don't, then we deal later with |
535 | all the psymtab stuff that needs checking. */ | |
536 | if (namespace == VAR_NAMESPACE && block != NULL) | |
537 | { | |
538 | struct block *b; | |
539 | /* Find the right symtab. */ | |
35a25840 | 540 | ALL_SYMTABS (objfile, s) |
b039ac3a | 541 | { |
35a25840 SG |
542 | bv = BLOCKVECTOR (s); |
543 | b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
544 | if (BLOCK_START (b) <= BLOCK_START (block) | |
545 | && BLOCK_END (b) > BLOCK_START (block)) | |
b039ac3a | 546 | { |
2e4964ad | 547 | sym = lookup_block_symbol (b, name, VAR_NAMESPACE); |
35a25840 | 548 | if (sym) |
b039ac3a | 549 | { |
35a25840 SG |
550 | block_found = b; |
551 | if (symtab != NULL) | |
552 | *symtab = s; | |
553 | return sym; | |
b039ac3a JK |
554 | } |
555 | } | |
556 | } | |
557 | } | |
558 | ||
559 | ||
bd5635a1 RP |
560 | /* C++: If requested to do so by the caller, |
561 | check to see if NAME is a field of `this'. */ | |
562 | if (is_a_field_of_this) | |
563 | { | |
564 | struct value *v = value_of_this (0); | |
565 | ||
566 | *is_a_field_of_this = 0; | |
567 | if (v && check_field (v, name)) | |
568 | { | |
569 | *is_a_field_of_this = 1; | |
570 | if (symtab != NULL) | |
571 | *symtab = NULL; | |
572 | return 0; | |
573 | } | |
574 | } | |
575 | ||
576 | /* Now search all global blocks. Do the symtab's first, then | |
577 | check the psymtab's */ | |
cba0d141 | 578 | |
35a25840 | 579 | ALL_SYMTABS (objfile, s) |
bd5635a1 | 580 | { |
35a25840 SG |
581 | bv = BLOCKVECTOR (s); |
582 | block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
583 | sym = lookup_block_symbol (block, name, namespace); | |
584 | if (sym) | |
bd5635a1 | 585 | { |
35a25840 SG |
586 | block_found = block; |
587 | if (symtab != NULL) | |
588 | *symtab = s; | |
589 | return sym; | |
bd5635a1 RP |
590 | } |
591 | } | |
592 | ||
76212295 PS |
593 | /* Check for the possibility of the symbol being a function or |
594 | a mangled variable that is stored in one of the minimal symbol tables. | |
595 | Eventually, all global symbols might be resolved in this way. */ | |
bd5635a1 RP |
596 | |
597 | if (namespace == VAR_NAMESPACE) | |
598 | { | |
2b576293 | 599 | msymbol = lookup_minimal_symbol (name, NULL, NULL); |
f70be3e4 | 600 | if (msymbol != NULL) |
bd5635a1 | 601 | { |
2e4964ad | 602 | s = find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol)); |
318bf84f | 603 | if (s != NULL) |
bd5635a1 | 604 | { |
76212295 | 605 | /* This is a function which has a symtab for its address. */ |
bd5635a1 | 606 | bv = BLOCKVECTOR (s); |
3ba6a043 | 607 | block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); |
2e4964ad FF |
608 | sym = lookup_block_symbol (block, SYMBOL_NAME (msymbol), |
609 | namespace); | |
318bf84f | 610 | /* We kept static functions in minimal symbol table as well as |
818de002 | 611 | in static scope. We want to find them in the symbol table. */ |
818de002 PB |
612 | if (!sym) { |
613 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
2e4964ad | 614 | sym = lookup_block_symbol (block, SYMBOL_NAME (msymbol), |
318bf84f | 615 | namespace); |
818de002 | 616 | } |
818de002 | 617 | |
cba0d141 | 618 | /* sym == 0 if symbol was found in the minimal symbol table |
bd5635a1 | 619 | but not in the symtab. |
cba0d141 | 620 | Return 0 to use the msymbol definition of "foo_". |
bd5635a1 RP |
621 | |
622 | This happens for Fortran "foo_" symbols, | |
623 | which are "foo" in the symtab. | |
624 | ||
625 | This can also happen if "asm" is used to make a | |
626 | regular symbol but not a debugging symbol, e.g. | |
627 | asm(".globl _main"); | |
628 | asm("_main:"); | |
629 | */ | |
630 | ||
631 | if (symtab != NULL) | |
632 | *symtab = s; | |
633 | return sym; | |
634 | } | |
76212295 PS |
635 | else if (MSYMBOL_TYPE (msymbol) != mst_text |
636 | && MSYMBOL_TYPE (msymbol) != mst_file_text | |
637 | && !STREQ (name, SYMBOL_NAME (msymbol))) | |
638 | { | |
639 | /* This is a mangled variable, look it up by its | |
640 | mangled name. */ | |
641 | return lookup_symbol (SYMBOL_NAME (msymbol), block, | |
642 | namespace, is_a_field_of_this, symtab); | |
643 | } | |
644 | /* There are no debug symbols for this file, or we are looking | |
645 | for an unmangled variable. | |
646 | Try to find a matching static symbol below. */ | |
bd5635a1 RP |
647 | } |
648 | } | |
649 | ||
35a25840 | 650 | ALL_PSYMTABS (objfile, ps) |
cba0d141 | 651 | { |
35a25840 | 652 | if (!ps->readin && lookup_partial_symbol (ps, name, 1, namespace)) |
cba0d141 | 653 | { |
35a25840 SG |
654 | s = PSYMTAB_TO_SYMTAB(ps); |
655 | bv = BLOCKVECTOR (s); | |
656 | block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
657 | sym = lookup_block_symbol (block, name, namespace); | |
658 | if (!sym) | |
35fcebce | 659 | error ("Internal: global symbol `%s' found in %s psymtab but not in symtab", name, ps->filename); |
35a25840 SG |
660 | if (symtab != NULL) |
661 | *symtab = s; | |
662 | return sym; | |
cba0d141 JG |
663 | } |
664 | } | |
bd5635a1 RP |
665 | |
666 | /* Now search all per-file blocks. | |
667 | Not strictly correct, but more useful than an error. | |
668 | Do the symtabs first, then check the psymtabs */ | |
669 | ||
35a25840 | 670 | ALL_SYMTABS (objfile, s) |
bd5635a1 | 671 | { |
35a25840 SG |
672 | bv = BLOCKVECTOR (s); |
673 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
674 | sym = lookup_block_symbol (block, name, namespace); | |
675 | if (sym) | |
bd5635a1 | 676 | { |
35a25840 SG |
677 | block_found = block; |
678 | if (symtab != NULL) | |
679 | *symtab = s; | |
680 | return sym; | |
681 | } | |
682 | } | |
683 | ||
684 | ALL_PSYMTABS (objfile, ps) | |
685 | { | |
686 | if (!ps->readin && lookup_partial_symbol (ps, name, 0, namespace)) | |
687 | { | |
688 | s = PSYMTAB_TO_SYMTAB(ps); | |
cba0d141 JG |
689 | bv = BLOCKVECTOR (s); |
690 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
691 | sym = lookup_block_symbol (block, name, namespace); | |
35a25840 | 692 | if (!sym) |
35fcebce | 693 | error ("Internal: static symbol `%s' found in %s psymtab but not in symtab", name, ps->filename); |
35a25840 SG |
694 | if (symtab != NULL) |
695 | *symtab = s; | |
696 | return sym; | |
697 | } | |
698 | } | |
699 | ||
bd5635a1 RP |
700 | if (symtab != NULL) |
701 | *symtab = NULL; | |
702 | return 0; | |
703 | } | |
704 | ||
705 | /* Look, in partial_symtab PST, for symbol NAME. Check the global | |
706 | symbols if GLOBAL, the static symbols if not */ | |
707 | ||
708 | static struct partial_symbol * | |
709 | lookup_partial_symbol (pst, name, global, namespace) | |
710 | struct partial_symtab *pst; | |
cba0d141 | 711 | const char *name; |
bd5635a1 | 712 | int global; |
1750a5ef | 713 | namespace_enum namespace; |
bd5635a1 | 714 | { |
b607efe7 FF |
715 | struct partial_symbol **start, **psym; |
716 | struct partial_symbol **top, **bottom, **center; | |
bd5635a1 | 717 | int length = (global ? pst->n_global_syms : pst->n_static_syms); |
2e4964ad | 718 | int do_linear_search = 1; |
bd5635a1 | 719 | |
2e4964ad FF |
720 | if (length == 0) |
721 | { | |
722 | return (NULL); | |
723 | } | |
bd5635a1 RP |
724 | |
725 | start = (global ? | |
cba0d141 JG |
726 | pst->objfile->global_psymbols.list + pst->globals_offset : |
727 | pst->objfile->static_psymbols.list + pst->statics_offset ); | |
bd5635a1 | 728 | |
2e4964ad | 729 | if (global) /* This means we can use a binary search. */ |
bd5635a1 | 730 | { |
2e4964ad | 731 | do_linear_search = 0; |
bd5635a1 RP |
732 | |
733 | /* Binary search. This search is guaranteed to end with center | |
734 | pointing at the earliest partial symbol with the correct | |
735 | name. At that point *all* partial symbols with that name | |
736 | will be checked against the correct namespace. */ | |
2e4964ad | 737 | |
bd5635a1 RP |
738 | bottom = start; |
739 | top = start + length - 1; | |
740 | while (top > bottom) | |
741 | { | |
742 | center = bottom + (top - bottom) / 2; | |
76212295 PS |
743 | if (!(center < top)) |
744 | abort (); | |
b607efe7 | 745 | if (!do_linear_search && SYMBOL_LANGUAGE (*center) == language_cplus) |
2e4964ad FF |
746 | { |
747 | do_linear_search = 1; | |
748 | } | |
b607efe7 | 749 | if (STRCMP (SYMBOL_NAME (*center), name) >= 0) |
2e4964ad FF |
750 | { |
751 | top = center; | |
752 | } | |
bd5635a1 | 753 | else |
2e4964ad FF |
754 | { |
755 | bottom = center + 1; | |
756 | } | |
bd5635a1 | 757 | } |
76212295 PS |
758 | if (!(top == bottom)) |
759 | abort (); | |
b607efe7 | 760 | while (STREQ (SYMBOL_NAME (*top), name)) |
bd5635a1 | 761 | { |
b607efe7 | 762 | if (SYMBOL_NAMESPACE (*top) == namespace) |
2e4964ad | 763 | { |
b607efe7 | 764 | return (*top); |
2e4964ad | 765 | } |
bd5635a1 RP |
766 | top ++; |
767 | } | |
768 | } | |
2e4964ad FF |
769 | |
770 | /* Can't use a binary search or else we found during the binary search that | |
771 | we should also do a linear search. */ | |
772 | ||
773 | if (do_linear_search) | |
bd5635a1 | 774 | { |
bd5635a1 | 775 | for (psym = start; psym < start + length; psym++) |
2e4964ad | 776 | { |
b607efe7 | 777 | if (namespace == SYMBOL_NAMESPACE (*psym)) |
2e4964ad | 778 | { |
b607efe7 | 779 | if (SYMBOL_MATCHES_NAME (*psym, name)) |
2e4964ad | 780 | { |
b607efe7 | 781 | return (*psym); |
2e4964ad FF |
782 | } |
783 | } | |
784 | } | |
bd5635a1 RP |
785 | } |
786 | ||
2e4964ad | 787 | return (NULL); |
bd5635a1 RP |
788 | } |
789 | ||
0e2a896c | 790 | /* Find the psymtab containing main(). */ |
c1878f87 SG |
791 | /* FIXME: What about languages without main() or specially linked |
792 | executables that have no main() ? */ | |
0e2a896c PB |
793 | |
794 | struct partial_symtab * | |
795 | find_main_psymtab () | |
796 | { | |
797 | register struct partial_symtab *pst; | |
cba0d141 JG |
798 | register struct objfile *objfile; |
799 | ||
35a25840 | 800 | ALL_PSYMTABS (objfile, pst) |
cba0d141 | 801 | { |
35a25840 | 802 | if (lookup_partial_symbol (pst, "main", 1, VAR_NAMESPACE)) |
cba0d141 | 803 | { |
35a25840 | 804 | return (pst); |
cba0d141 JG |
805 | } |
806 | } | |
807 | return (NULL); | |
0e2a896c PB |
808 | } |
809 | ||
2e4964ad FF |
810 | /* Search BLOCK for symbol NAME in NAMESPACE. |
811 | ||
812 | Note that if NAME is the demangled form of a C++ symbol, we will fail | |
813 | to find a match during the binary search of the non-encoded names, but | |
814 | for now we don't worry about the slight inefficiency of looking for | |
815 | a match we'll never find, since it will go pretty quick. Once the | |
816 | binary search terminates, we drop through and do a straight linear | |
817 | search on the symbols. Each symbol which is marked as being a C++ | |
818 | symbol (language_cplus set) has both the encoded and non-encoded names | |
819 | tested for a match. */ | |
bd5635a1 RP |
820 | |
821 | struct symbol * | |
822 | lookup_block_symbol (block, name, namespace) | |
cba0d141 JG |
823 | register const struct block *block; |
824 | const char *name; | |
1750a5ef | 825 | const namespace_enum namespace; |
bd5635a1 RP |
826 | { |
827 | register int bot, top, inc; | |
2e4964ad FF |
828 | register struct symbol *sym; |
829 | register struct symbol *sym_found = NULL; | |
830 | register int do_linear_search = 1; | |
bd5635a1 RP |
831 | |
832 | /* If the blocks's symbols were sorted, start with a binary search. */ | |
833 | ||
834 | if (BLOCK_SHOULD_SORT (block)) | |
835 | { | |
2e4964ad FF |
836 | /* Reset the linear search flag so if the binary search fails, we |
837 | won't do the linear search once unless we find some reason to | |
838 | do so, such as finding a C++ symbol during the binary search. | |
839 | Note that for C++ modules, ALL the symbols in a block should | |
840 | end up marked as C++ symbols. */ | |
841 | ||
842 | do_linear_search = 0; | |
843 | top = BLOCK_NSYMS (block); | |
844 | bot = 0; | |
845 | ||
846 | /* Advance BOT to not far before the first symbol whose name is NAME. */ | |
bd5635a1 RP |
847 | |
848 | while (1) | |
849 | { | |
850 | inc = (top - bot + 1); | |
851 | /* No need to keep binary searching for the last few bits worth. */ | |
852 | if (inc < 4) | |
2e4964ad FF |
853 | { |
854 | break; | |
855 | } | |
bd5635a1 RP |
856 | inc = (inc >> 1) + bot; |
857 | sym = BLOCK_SYM (block, inc); | |
2e4964ad FF |
858 | if (!do_linear_search && SYMBOL_LANGUAGE (sym) == language_cplus) |
859 | { | |
860 | do_linear_search = 1; | |
861 | } | |
bd5635a1 | 862 | if (SYMBOL_NAME (sym)[0] < name[0]) |
2e4964ad FF |
863 | { |
864 | bot = inc; | |
865 | } | |
bd5635a1 | 866 | else if (SYMBOL_NAME (sym)[0] > name[0]) |
2e4964ad FF |
867 | { |
868 | top = inc; | |
869 | } | |
870 | else if (STRCMP (SYMBOL_NAME (sym), name) < 0) | |
871 | { | |
872 | bot = inc; | |
873 | } | |
bd5635a1 | 874 | else |
2e4964ad FF |
875 | { |
876 | top = inc; | |
877 | } | |
bd5635a1 RP |
878 | } |
879 | ||
f1ed4330 JK |
880 | /* Now scan forward until we run out of symbols, find one whose |
881 | name is greater than NAME, or find one we want. If there is | |
882 | more than one symbol with the right name and namespace, we | |
883 | return the first one; I believe it is now impossible for us | |
884 | to encounter two symbols with the same name and namespace | |
885 | here, because blocks containing argument symbols are no | |
886 | longer sorted. */ | |
bd5635a1 RP |
887 | |
888 | top = BLOCK_NSYMS (block); | |
889 | while (bot < top) | |
890 | { | |
891 | sym = BLOCK_SYM (block, bot); | |
892 | inc = SYMBOL_NAME (sym)[0] - name[0]; | |
893 | if (inc == 0) | |
2e4964ad FF |
894 | { |
895 | inc = STRCMP (SYMBOL_NAME (sym), name); | |
896 | } | |
bd5635a1 | 897 | if (inc == 0 && SYMBOL_NAMESPACE (sym) == namespace) |
2e4964ad FF |
898 | { |
899 | return (sym); | |
900 | } | |
bd5635a1 | 901 | if (inc > 0) |
2e4964ad FF |
902 | { |
903 | break; | |
904 | } | |
bd5635a1 RP |
905 | bot++; |
906 | } | |
bd5635a1 RP |
907 | } |
908 | ||
2e4964ad FF |
909 | /* Here if block isn't sorted, or we fail to find a match during the |
910 | binary search above. If during the binary search above, we find a | |
911 | symbol which is a C++ symbol, then we have re-enabled the linear | |
912 | search flag which was reset when starting the binary search. | |
913 | ||
914 | This loop is equivalent to the loop above, but hacked greatly for speed. | |
bd5635a1 RP |
915 | |
916 | Note that parameter symbols do not always show up last in the | |
917 | list; this loop makes sure to take anything else other than | |
918 | parameter symbols first; it only uses parameter symbols as a | |
919 | last resort. Note that this only takes up extra computation | |
920 | time on a match. */ | |
921 | ||
2e4964ad | 922 | if (do_linear_search) |
bd5635a1 | 923 | { |
2e4964ad FF |
924 | top = BLOCK_NSYMS (block); |
925 | bot = 0; | |
926 | while (bot < top) | |
bd5635a1 | 927 | { |
2e4964ad FF |
928 | sym = BLOCK_SYM (block, bot); |
929 | if (SYMBOL_NAMESPACE (sym) == namespace && | |
930 | SYMBOL_MATCHES_NAME (sym, name)) | |
931 | { | |
932 | sym_found = sym; | |
933 | if (SYMBOL_CLASS (sym) != LOC_ARG && | |
934 | SYMBOL_CLASS (sym) != LOC_LOCAL_ARG && | |
935 | SYMBOL_CLASS (sym) != LOC_REF_ARG && | |
f1ed4330 | 936 | SYMBOL_CLASS (sym) != LOC_REGPARM && |
a1c8d76e JK |
937 | SYMBOL_CLASS (sym) != LOC_REGPARM_ADDR && |
938 | SYMBOL_CLASS (sym) != LOC_BASEREG_ARG) | |
2e4964ad FF |
939 | { |
940 | break; | |
941 | } | |
942 | } | |
943 | bot++; | |
bd5635a1 | 944 | } |
bd5635a1 | 945 | } |
2e4964ad | 946 | return (sym_found); /* Will be NULL if not found. */ |
bd5635a1 | 947 | } |
2e4964ad | 948 | |
bd5635a1 RP |
949 | \f |
950 | /* Return the symbol for the function which contains a specified | |
951 | lexical block, described by a struct block BL. */ | |
952 | ||
953 | struct symbol * | |
954 | block_function (bl) | |
955 | struct block *bl; | |
956 | { | |
957 | while (BLOCK_FUNCTION (bl) == 0 && BLOCK_SUPERBLOCK (bl) != 0) | |
958 | bl = BLOCK_SUPERBLOCK (bl); | |
959 | ||
960 | return BLOCK_FUNCTION (bl); | |
961 | } | |
962 | ||
c1878f87 SG |
963 | /* Find the symtab associated with PC. Look through the psymtabs and read in |
964 | another symtab if necessary. */ | |
bd5635a1 RP |
965 | |
966 | struct symtab * | |
967 | find_pc_symtab (pc) | |
968 | register CORE_ADDR pc; | |
969 | { | |
970 | register struct block *b; | |
971 | struct blockvector *bv; | |
45a655b0 | 972 | register struct symtab *s = NULL; |
ca6a826d | 973 | register struct symtab *best_s = NULL; |
bd5635a1 | 974 | register struct partial_symtab *ps; |
cba0d141 | 975 | register struct objfile *objfile; |
018ab14f | 976 | int distance = 0; |
bd5635a1 | 977 | |
018ab14f PS |
978 | /* Search all symtabs for the one whose file contains our address, and which |
979 | is the smallest of all the ones containing the address. This is designed | |
980 | to deal with a case like symtab a is at 0x1000-0x2000 and 0x3000-0x4000 | |
981 | and symtab b is at 0x2000-0x3000. So the GLOBAL_BLOCK for a is from | |
982 | 0x1000-0x4000, but for address 0x2345 we want to return symtab b. | |
76212295 PS |
983 | |
984 | This happens for native ecoff format, where code from included files | |
985 | gets its own symtab. The symtab for the included file should have | |
986 | been read in already via the dependency mechanism. | |
987 | It might be swifter to create several symtabs with the same name | |
988 | like xcoff does (I'm not sure). | |
989 | ||
990 | It also happens for objfiles that have their functions reordered. | |
991 | For these, the symtab we are looking for is not necessarily read in. */ | |
bd5635a1 | 992 | |
35a25840 | 993 | ALL_SYMTABS (objfile, s) |
bd5635a1 | 994 | { |
35a25840 SG |
995 | bv = BLOCKVECTOR (s); |
996 | b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
997 | if (BLOCK_START (b) <= pc | |
ca6a826d PS |
998 | && BLOCK_END (b) > pc |
999 | && (distance == 0 | |
1000 | || BLOCK_END (b) - BLOCK_START (b) < distance)) | |
1001 | { | |
76212295 PS |
1002 | /* For an objfile that has its functions reordered, |
1003 | find_pc_psymtab will find the proper partial symbol table | |
1004 | and we simply return its corresponding symtab. */ | |
b607efe7 | 1005 | if ((objfile->flags & OBJF_REORDERED) && objfile->psymtabs) |
76212295 PS |
1006 | { |
1007 | ps = find_pc_psymtab (pc); | |
1008 | if (ps) | |
1009 | s = PSYMTAB_TO_SYMTAB (ps); | |
1010 | else | |
1011 | s = NULL; | |
1012 | return (s); | |
1013 | } | |
ca6a826d PS |
1014 | distance = BLOCK_END (b) - BLOCK_START (b); |
1015 | best_s = s; | |
1016 | } | |
bd5635a1 RP |
1017 | } |
1018 | ||
ca6a826d PS |
1019 | if (best_s != NULL) |
1020 | return(best_s); | |
1021 | ||
45a655b0 | 1022 | s = NULL; |
c1878f87 SG |
1023 | ps = find_pc_psymtab (pc); |
1024 | if (ps) | |
bd5635a1 | 1025 | { |
c1878f87 | 1026 | if (ps->readin) |
ac82e9a5 JK |
1027 | /* Might want to error() here (in case symtab is corrupt and |
1028 | will cause a core dump), but maybe we can successfully | |
1029 | continue, so let's not. */ | |
e3d6ec4a | 1030 | /* FIXME-32x64: assumes pc fits in a long */ |
ac82e9a5 | 1031 | warning ("\ |
5573d7d4 JK |
1032 | (Internal error: pc 0x%lx in read in psymtab, but not in symtab.)\n", |
1033 | (unsigned long) pc); | |
c1878f87 | 1034 | s = PSYMTAB_TO_SYMTAB (ps); |
bd5635a1 | 1035 | } |
45a655b0 | 1036 | return (s); |
bd5635a1 | 1037 | } |
e0ea0fbd | 1038 | \f |
a0cf4681 JK |
1039 | #if 0 |
1040 | ||
e0ea0fbd | 1041 | /* Find the closest symbol value (of any sort -- function or variable) |
a0cf4681 JK |
1042 | for a given address value. Slow but complete. (currently unused, |
1043 | mainly because it is too slow. We could fix it if each symtab and | |
1044 | psymtab had contained in it the addresses ranges of each of its | |
1045 | sections, which also would be required to make things like "info | |
1046 | line *0x2345" cause psymtabs to be converted to symtabs). */ | |
e0ea0fbd JG |
1047 | |
1048 | struct symbol * | |
87041845 | 1049 | find_addr_symbol (addr, symtabp, symaddrp) |
e0ea0fbd | 1050 | CORE_ADDR addr; |
87041845 JK |
1051 | struct symtab **symtabp; |
1052 | CORE_ADDR *symaddrp; | |
e0ea0fbd | 1053 | { |
87041845 | 1054 | struct symtab *symtab, *best_symtab; |
e0ea0fbd JG |
1055 | struct objfile *objfile; |
1056 | register int bot, top; | |
1057 | register struct symbol *sym; | |
1058 | register CORE_ADDR sym_addr; | |
1059 | struct block *block; | |
1060 | int blocknum; | |
1061 | ||
1062 | /* Info on best symbol seen so far */ | |
1063 | ||
1064 | register CORE_ADDR best_sym_addr = 0; | |
1065 | struct symbol *best_sym = 0; | |
1066 | ||
1067 | /* FIXME -- we should pull in all the psymtabs, too! */ | |
1068 | ALL_SYMTABS (objfile, symtab) | |
1069 | { | |
1070 | /* Search the global and static blocks in this symtab for | |
1071 | the closest symbol-address to the desired address. */ | |
1072 | ||
1073 | for (blocknum = GLOBAL_BLOCK; blocknum <= STATIC_BLOCK; blocknum++) | |
1074 | { | |
1075 | QUIT; | |
1076 | block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), blocknum); | |
1077 | top = BLOCK_NSYMS (block); | |
1078 | for (bot = 0; bot < top; bot++) | |
1079 | { | |
1080 | sym = BLOCK_SYM (block, bot); | |
1081 | switch (SYMBOL_CLASS (sym)) | |
1082 | { | |
1083 | case LOC_STATIC: | |
1084 | case LOC_LABEL: | |
1085 | sym_addr = SYMBOL_VALUE_ADDRESS (sym); | |
1086 | break; | |
1087 | ||
1088 | case LOC_BLOCK: | |
1089 | sym_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)); | |
1090 | break; | |
1091 | ||
1092 | default: | |
1093 | continue; | |
1094 | } | |
1095 | ||
1096 | if (sym_addr <= addr) | |
1097 | if (sym_addr > best_sym_addr) | |
1098 | { | |
1099 | /* Quit if we found an exact match. */ | |
e0ea0fbd JG |
1100 | best_sym = sym; |
1101 | best_sym_addr = sym_addr; | |
87041845 JK |
1102 | best_symtab = symtab; |
1103 | if (sym_addr == addr) | |
1104 | goto done; | |
e0ea0fbd JG |
1105 | } |
1106 | } | |
1107 | } | |
1108 | } | |
87041845 JK |
1109 | |
1110 | done: | |
1111 | if (symtabp) | |
1112 | *symtabp = best_symtab; | |
1113 | if (symaddrp) | |
1114 | *symaddrp = best_sym_addr; | |
e0ea0fbd JG |
1115 | return best_sym; |
1116 | } | |
a0cf4681 | 1117 | #endif /* 0 */ |
bd5635a1 RP |
1118 | |
1119 | /* Find the source file and line number for a given PC value. | |
1120 | Return a structure containing a symtab pointer, a line number, | |
1121 | and a pc range for the entire source line. | |
1122 | The value's .pc field is NOT the specified pc. | |
1123 | NOTCURRENT nonzero means, if specified pc is on a line boundary, | |
1124 | use the line that ends there. Otherwise, in that case, the line | |
1125 | that begins there is used. */ | |
1126 | ||
b638ca91 SG |
1127 | /* The big complication here is that a line may start in one file, and end just |
1128 | before the start of another file. This usually occurs when you #include | |
1129 | code in the middle of a subroutine. To properly find the end of a line's PC | |
1130 | range, we must search all symtabs associated with this compilation unit, and | |
1131 | find the one whose first PC is closer than that of the next line in this | |
01d3fdba | 1132 | symtab. */ |
b638ca91 | 1133 | |
d34d6f75 JK |
1134 | /* If it's worth the effort, we could be using a binary search. */ |
1135 | ||
bd5635a1 RP |
1136 | struct symtab_and_line |
1137 | find_pc_line (pc, notcurrent) | |
1138 | CORE_ADDR pc; | |
1139 | int notcurrent; | |
1140 | { | |
1141 | struct symtab *s; | |
1142 | register struct linetable *l; | |
1143 | register int len; | |
1144 | register int i; | |
b638ca91 | 1145 | register struct linetable_entry *item; |
bd5635a1 RP |
1146 | struct symtab_and_line val; |
1147 | struct blockvector *bv; | |
1148 | ||
1149 | /* Info on best line seen so far, and where it starts, and its file. */ | |
1150 | ||
b638ca91 | 1151 | struct linetable_entry *best = NULL; |
bd5635a1 RP |
1152 | CORE_ADDR best_end = 0; |
1153 | struct symtab *best_symtab = 0; | |
1154 | ||
1155 | /* Store here the first line number | |
1156 | of a file which contains the line at the smallest pc after PC. | |
1157 | If we don't find a line whose range contains PC, | |
1158 | we will use a line one less than this, | |
1159 | with a range from the start of that file to the first line's pc. */ | |
b638ca91 | 1160 | struct linetable_entry *alt = NULL; |
bd5635a1 RP |
1161 | struct symtab *alt_symtab = 0; |
1162 | ||
1163 | /* Info on best line seen in this file. */ | |
1164 | ||
b638ca91 | 1165 | struct linetable_entry *prev; |
bd5635a1 RP |
1166 | |
1167 | /* If this pc is not from the current frame, | |
1168 | it is the address of the end of a call instruction. | |
1169 | Quite likely that is the start of the following statement. | |
1170 | But what we want is the statement containing the instruction. | |
1171 | Fudge the pc to make sure we get that. */ | |
1172 | ||
1173 | if (notcurrent) pc -= 1; | |
1174 | ||
1175 | s = find_pc_symtab (pc); | |
c1878f87 | 1176 | if (!s) |
bd5635a1 RP |
1177 | { |
1178 | val.symtab = 0; | |
1179 | val.line = 0; | |
1180 | val.pc = pc; | |
1181 | val.end = 0; | |
1182 | return val; | |
1183 | } | |
1184 | ||
1185 | bv = BLOCKVECTOR (s); | |
1186 | ||
1187 | /* Look at all the symtabs that share this blockvector. | |
1188 | They all have the same apriori range, that we found was right; | |
1189 | but they have different line tables. */ | |
1190 | ||
1191 | for (; s && BLOCKVECTOR (s) == bv; s = s->next) | |
1192 | { | |
1193 | /* Find the best line in this symtab. */ | |
1194 | l = LINETABLE (s); | |
4137c5fc JG |
1195 | if (!l) |
1196 | continue; | |
bd5635a1 | 1197 | len = l->nitems; |
01d3fdba | 1198 | if (len <= 0) |
c1878f87 | 1199 | { |
01d3fdba JK |
1200 | /* I think len can be zero if the symtab lacks line numbers |
1201 | (e.g. gcc -g1). (Either that or the LINETABLE is NULL; | |
1202 | I'm not sure which, and maybe it depends on the symbol | |
1203 | reader). */ | |
c1878f87 SG |
1204 | continue; |
1205 | } | |
1206 | ||
b638ca91 SG |
1207 | prev = NULL; |
1208 | item = l->item; /* Get first line info */ | |
c1878f87 SG |
1209 | |
1210 | /* Is this file's first line closer than the first lines of other files? | |
1211 | If so, record this file, and its first line, as best alternate. */ | |
b638ca91 | 1212 | if (item->pc > pc && (!alt || item->pc < alt->pc)) |
c1878f87 SG |
1213 | { |
1214 | alt = item; | |
1215 | alt_symtab = s; | |
1216 | } | |
1217 | ||
b638ca91 | 1218 | for (i = 0; i < len; i++, item++) |
bd5635a1 | 1219 | { |
b607efe7 FF |
1220 | /* Leave prev pointing to the linetable entry for the last line |
1221 | that started at or before PC. */ | |
b638ca91 | 1222 | if (item->pc > pc) |
bd5635a1 | 1223 | break; |
c1878f87 SG |
1224 | |
1225 | prev = item; | |
bd5635a1 RP |
1226 | } |
1227 | ||
c1878f87 SG |
1228 | /* At this point, prev points at the line whose start addr is <= pc, and |
1229 | item points at the next line. If we ran off the end of the linetable | |
1230 | (pc >= start of the last line), then prev == item. If pc < start of | |
1231 | the first line, prev will not be set. */ | |
1232 | ||
bd5635a1 RP |
1233 | /* Is this file's best line closer than the best in the other files? |
1234 | If so, record this file, and its best line, as best so far. */ | |
c1878f87 | 1235 | |
b638ca91 | 1236 | if (prev && (!best || prev->pc > best->pc)) |
bd5635a1 | 1237 | { |
c1878f87 | 1238 | best = prev; |
bd5635a1 | 1239 | best_symtab = s; |
cba0d141 JG |
1240 | /* If another line is in the linetable, and its PC is closer |
1241 | than the best_end we currently have, take it as best_end. */ | |
b638ca91 SG |
1242 | if (i < len && (best_end == 0 || best_end > item->pc)) |
1243 | best_end = item->pc; | |
bd5635a1 RP |
1244 | } |
1245 | } | |
c1878f87 SG |
1246 | |
1247 | if (!best_symtab) | |
bd5635a1 | 1248 | { |
c1878f87 SG |
1249 | if (!alt_symtab) |
1250 | { /* If we didn't find any line # info, just | |
1251 | return zeros. */ | |
1252 | val.symtab = 0; | |
1253 | val.line = 0; | |
1254 | val.pc = pc; | |
1255 | val.end = 0; | |
1256 | } | |
1257 | else | |
1258 | { | |
1259 | val.symtab = alt_symtab; | |
b638ca91 | 1260 | val.line = alt->line - 1; |
2b576293 C |
1261 | |
1262 | /* Don't return line 0, that means that we didn't find the line. */ | |
1263 | if (val.line == 0) ++val.line; | |
1264 | ||
c1878f87 | 1265 | val.pc = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)); |
b638ca91 | 1266 | val.end = alt->pc; |
c1878f87 | 1267 | } |
bd5635a1 RP |
1268 | } |
1269 | else | |
1270 | { | |
1271 | val.symtab = best_symtab; | |
b638ca91 SG |
1272 | val.line = best->line; |
1273 | val.pc = best->pc; | |
1274 | if (best_end && (!alt || best_end < alt->pc)) | |
cba0d141 | 1275 | val.end = best_end; |
a8a69e63 | 1276 | else if (alt) |
b638ca91 | 1277 | val.end = alt->pc; |
cba0d141 JG |
1278 | else |
1279 | val.end = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)); | |
bd5635a1 RP |
1280 | } |
1281 | return val; | |
1282 | } | |
1283 | \f | |
018ab14f PS |
1284 | static int find_line_symtab PARAMS ((struct symtab *, int, struct linetable **, |
1285 | int *, int *)); | |
1286 | ||
1287 | /* Find line number LINE in any symtab whose name is the same as | |
1288 | SYMTAB. | |
1289 | ||
1290 | If found, return 1, set *LINETABLE to the linetable in which it was | |
1291 | found, set *INDEX to the index in the linetable of the best entry | |
1292 | found, and set *EXACT_MATCH nonzero if the value returned is an | |
1293 | exact match. | |
1294 | ||
1295 | If not found, return 0. */ | |
1296 | ||
1297 | static int | |
1298 | find_line_symtab (symtab, line, linetable, index, exact_match) | |
1299 | struct symtab *symtab; | |
1300 | int line; | |
1301 | struct linetable **linetable; | |
1302 | int *index; | |
1303 | int *exact_match; | |
1304 | { | |
1305 | int exact; | |
1306 | ||
1307 | /* BEST_INDEX and BEST_LINETABLE identify the smallest linenumber > LINE | |
1308 | so far seen. */ | |
1309 | ||
1310 | int best_index; | |
1311 | struct linetable *best_linetable; | |
1312 | ||
1313 | /* First try looking it up in the given symtab. */ | |
1314 | best_linetable = LINETABLE (symtab); | |
1315 | best_index = find_line_common (best_linetable, line, &exact); | |
1316 | if (best_index < 0 || !exact) | |
1317 | { | |
1318 | /* Didn't find an exact match. So we better keep looking for | |
1319 | another symtab with the same name. In the case of xcoff, | |
1320 | multiple csects for one source file (produced by IBM's FORTRAN | |
1321 | compiler) produce multiple symtabs (this is unavoidable | |
1322 | assuming csects can be at arbitrary places in memory and that | |
1323 | the GLOBAL_BLOCK of a symtab has a begin and end address). */ | |
1324 | ||
1325 | /* BEST is the smallest linenumber > LINE so far seen, | |
1326 | or 0 if none has been seen so far. | |
1327 | BEST_INDEX and BEST_LINETABLE identify the item for it. */ | |
1328 | int best; | |
1329 | ||
1330 | struct objfile *objfile; | |
1331 | struct symtab *s; | |
1332 | ||
1333 | if (best_index >= 0) | |
1334 | best = best_linetable->item[best_index].line; | |
1335 | else | |
1336 | best = 0; | |
1337 | ||
1338 | ALL_SYMTABS (objfile, s) | |
1339 | { | |
1340 | struct linetable *l; | |
1341 | int ind; | |
1342 | ||
1343 | if (!STREQ (symtab->filename, s->filename)) | |
1344 | continue; | |
1345 | l = LINETABLE (s); | |
1346 | ind = find_line_common (l, line, &exact); | |
1347 | if (ind >= 0) | |
1348 | { | |
1349 | if (exact) | |
1350 | { | |
1351 | best_index = ind; | |
1352 | best_linetable = l; | |
1353 | goto done; | |
1354 | } | |
1355 | if (best == 0 || l->item[ind].line < best) | |
1356 | { | |
1357 | best = l->item[ind].line; | |
1358 | best_index = ind; | |
1359 | best_linetable = l; | |
1360 | } | |
1361 | } | |
1362 | } | |
1363 | } | |
1364 | done: | |
1365 | if (best_index < 0) | |
1366 | return 0; | |
1367 | ||
1368 | if (index) | |
1369 | *index = best_index; | |
1370 | if (linetable) | |
1371 | *linetable = best_linetable; | |
1372 | if (exact_match) | |
1373 | *exact_match = exact; | |
1374 | return 1; | |
1375 | } | |
1376 | \f | |
bd5635a1 RP |
1377 | /* Find the PC value for a given source file and line number. |
1378 | Returns zero for invalid line number. | |
1379 | The source file is specified with a struct symtab. */ | |
1380 | ||
1381 | CORE_ADDR | |
1382 | find_line_pc (symtab, line) | |
1383 | struct symtab *symtab; | |
1384 | int line; | |
1385 | { | |
018ab14f PS |
1386 | struct linetable *l; |
1387 | int ind; | |
bd5635a1 RP |
1388 | |
1389 | if (symtab == 0) | |
1390 | return 0; | |
018ab14f PS |
1391 | if (find_line_symtab (symtab, line, &l, &ind, NULL)) |
1392 | return l->item[ind].pc; | |
1393 | else | |
1394 | return 0; | |
bd5635a1 RP |
1395 | } |
1396 | ||
1397 | /* Find the range of pc values in a line. | |
1398 | Store the starting pc of the line into *STARTPTR | |
1399 | and the ending pc (start of next line) into *ENDPTR. | |
1400 | Returns 1 to indicate success. | |
1401 | Returns 0 if could not find the specified line. */ | |
1402 | ||
1403 | int | |
b86a1b3b JK |
1404 | find_line_pc_range (sal, startptr, endptr) |
1405 | struct symtab_and_line sal; | |
bd5635a1 RP |
1406 | CORE_ADDR *startptr, *endptr; |
1407 | { | |
b86a1b3b JK |
1408 | CORE_ADDR startaddr; |
1409 | struct symtab_and_line found_sal; | |
bd5635a1 | 1410 | |
b86a1b3b JK |
1411 | startaddr = sal.pc; |
1412 | if (startaddr == 0) | |
1413 | { | |
1414 | startaddr = find_line_pc (sal.symtab, sal.line); | |
1415 | } | |
1416 | if (startaddr == 0) | |
bd5635a1 RP |
1417 | return 0; |
1418 | ||
b86a1b3b JK |
1419 | /* This whole function is based on address. For example, if line 10 has |
1420 | two parts, one from 0x100 to 0x200 and one from 0x300 to 0x400, then | |
1421 | "info line *0x123" should say the line goes from 0x100 to 0x200 | |
1422 | and "info line *0x355" should say the line goes from 0x300 to 0x400. | |
1423 | This also insures that we never give a range like "starts at 0x134 | |
1424 | and ends at 0x12c". */ | |
1425 | ||
1426 | found_sal = find_pc_line (startaddr, 0); | |
1427 | if (found_sal.line != sal.line) | |
bd5635a1 | 1428 | { |
b86a1b3b JK |
1429 | /* The specified line (sal) has zero bytes. */ |
1430 | *startptr = found_sal.pc; | |
1431 | *endptr = found_sal.pc; | |
bd5635a1 | 1432 | } |
b86a1b3b JK |
1433 | else |
1434 | { | |
1435 | *startptr = found_sal.pc; | |
1436 | *endptr = found_sal.end; | |
1437 | } | |
1438 | return 1; | |
bd5635a1 RP |
1439 | } |
1440 | ||
1441 | /* Given a line table and a line number, return the index into the line | |
1442 | table for the pc of the nearest line whose number is >= the specified one. | |
b203fc18 | 1443 | Return -1 if none is found. The value is >= 0 if it is an index. |
bd5635a1 RP |
1444 | |
1445 | Set *EXACT_MATCH nonzero if the value returned is an exact match. */ | |
1446 | ||
1447 | static int | |
1448 | find_line_common (l, lineno, exact_match) | |
1449 | register struct linetable *l; | |
1450 | register int lineno; | |
1451 | int *exact_match; | |
1452 | { | |
1453 | register int i; | |
1454 | register int len; | |
1455 | ||
1456 | /* BEST is the smallest linenumber > LINENO so far seen, | |
1457 | or 0 if none has been seen so far. | |
1458 | BEST_INDEX identifies the item for it. */ | |
1459 | ||
b203fc18 | 1460 | int best_index = -1; |
bd5635a1 RP |
1461 | int best = 0; |
1462 | ||
1463 | if (lineno <= 0) | |
b203fc18 | 1464 | return -1; |
4137c5fc JG |
1465 | if (l == 0) |
1466 | return -1; | |
bd5635a1 RP |
1467 | |
1468 | len = l->nitems; | |
1469 | for (i = 0; i < len; i++) | |
1470 | { | |
1471 | register struct linetable_entry *item = &(l->item[i]); | |
1472 | ||
1473 | if (item->line == lineno) | |
1474 | { | |
d34d6f75 | 1475 | /* Return the first (lowest address) entry which matches. */ |
bd5635a1 RP |
1476 | *exact_match = 1; |
1477 | return i; | |
1478 | } | |
1479 | ||
1480 | if (item->line > lineno && (best == 0 || item->line < best)) | |
1481 | { | |
1482 | best = item->line; | |
1483 | best_index = i; | |
1484 | } | |
1485 | } | |
1486 | ||
1487 | /* If we got here, we didn't get an exact match. */ | |
1488 | ||
1489 | *exact_match = 0; | |
1490 | return best_index; | |
1491 | } | |
1492 | ||
1493 | int | |
1494 | find_pc_line_pc_range (pc, startptr, endptr) | |
1495 | CORE_ADDR pc; | |
1496 | CORE_ADDR *startptr, *endptr; | |
1497 | { | |
1498 | struct symtab_and_line sal; | |
1499 | sal = find_pc_line (pc, 0); | |
1500 | *startptr = sal.pc; | |
1501 | *endptr = sal.end; | |
1502 | return sal.symtab != 0; | |
1503 | } | |
76212295 PS |
1504 | |
1505 | /* Given a function symbol SYM, find the symtab and line for the start | |
1506 | of the function. | |
1507 | If the argument FUNFIRSTLINE is nonzero, we want the first line | |
1508 | of real code inside the function. */ | |
1509 | ||
1510 | static struct symtab_and_line | |
1511 | find_function_start_sal PARAMS ((struct symbol *sym, int)); | |
1512 | ||
1513 | static struct symtab_and_line | |
1514 | find_function_start_sal (sym, funfirstline) | |
1515 | struct symbol *sym; | |
1516 | int funfirstline; | |
1517 | { | |
1518 | CORE_ADDR pc; | |
1519 | struct symtab_and_line sal; | |
1520 | ||
1521 | pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)); | |
1522 | if (funfirstline) | |
1523 | { | |
1524 | pc += FUNCTION_START_OFFSET; | |
1525 | SKIP_PROLOGUE (pc); | |
1526 | } | |
1527 | sal = find_pc_line (pc, 0); | |
1528 | ||
1529 | #ifdef PROLOGUE_FIRSTLINE_OVERLAP | |
1530 | /* Convex: no need to suppress code on first line, if any */ | |
1531 | sal.pc = pc; | |
1532 | #else | |
1533 | /* Check if SKIP_PROLOGUE left us in mid-line, and the next | |
1534 | line is still part of the same function. */ | |
1535 | if (sal.pc != pc | |
1536 | && BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) <= sal.end | |
1537 | && sal.end < BLOCK_END (SYMBOL_BLOCK_VALUE (sym))) | |
1538 | { | |
1539 | /* First pc of next line */ | |
1540 | pc = sal.end; | |
1541 | /* Recalculate the line number (might not be N+1). */ | |
1542 | sal = find_pc_line (pc, 0); | |
1543 | } | |
1544 | sal.pc = pc; | |
1545 | #endif | |
1546 | ||
1547 | return sal; | |
1548 | } | |
bd5635a1 | 1549 | \f |
d96b54ea JK |
1550 | /* If P is of the form "operator[ \t]+..." where `...' is |
1551 | some legitimate operator text, return a pointer to the | |
1552 | beginning of the substring of the operator text. | |
1553 | Otherwise, return "". */ | |
1554 | static char * | |
1555 | operator_chars (p, end) | |
1556 | char *p; | |
1557 | char **end; | |
1558 | { | |
1559 | *end = ""; | |
1560 | if (strncmp (p, "operator", 8)) | |
1561 | return *end; | |
1562 | p += 8; | |
1563 | ||
1564 | /* Don't get faked out by `operator' being part of a longer | |
1565 | identifier. */ | |
2cd99985 | 1566 | if (isalpha(*p) || *p == '_' || *p == '$' || *p == '\0') |
d96b54ea JK |
1567 | return *end; |
1568 | ||
1569 | /* Allow some whitespace between `operator' and the operator symbol. */ | |
1570 | while (*p == ' ' || *p == '\t') | |
1571 | p++; | |
1572 | ||
2cd99985 PB |
1573 | /* Recognize 'operator TYPENAME'. */ |
1574 | ||
1575 | if (isalpha(*p) || *p == '_' || *p == '$') | |
1576 | { | |
1577 | register char *q = p+1; | |
1578 | while (isalnum(*q) || *q == '_' || *q == '$') | |
1579 | q++; | |
1580 | *end = q; | |
1581 | return p; | |
1582 | } | |
1583 | ||
d96b54ea JK |
1584 | switch (*p) |
1585 | { | |
1586 | case '!': | |
1587 | case '=': | |
1588 | case '*': | |
1589 | case '/': | |
1590 | case '%': | |
1591 | case '^': | |
1592 | if (p[1] == '=') | |
1593 | *end = p+2; | |
1594 | else | |
1595 | *end = p+1; | |
1596 | return p; | |
1597 | case '<': | |
1598 | case '>': | |
1599 | case '+': | |
1600 | case '-': | |
1601 | case '&': | |
1602 | case '|': | |
1603 | if (p[1] == '=' || p[1] == p[0]) | |
1604 | *end = p+2; | |
1605 | else | |
1606 | *end = p+1; | |
1607 | return p; | |
1608 | case '~': | |
1609 | case ',': | |
1610 | *end = p+1; | |
1611 | return p; | |
1612 | case '(': | |
1613 | if (p[1] != ')') | |
1614 | error ("`operator ()' must be specified without whitespace in `()'"); | |
1615 | *end = p+2; | |
1616 | return p; | |
1617 | case '?': | |
1618 | if (p[1] != ':') | |
1619 | error ("`operator ?:' must be specified without whitespace in `?:'"); | |
1620 | *end = p+2; | |
1621 | return p; | |
1622 | case '[': | |
1623 | if (p[1] != ']') | |
1624 | error ("`operator []' must be specified without whitespace in `[]'"); | |
1625 | *end = p+2; | |
1626 | return p; | |
1627 | default: | |
1628 | error ("`operator %s' not supported", p); | |
1629 | break; | |
1630 | } | |
1631 | *end = ""; | |
1632 | return *end; | |
1633 | } | |
1634 | ||
2b576293 C |
1635 | /* Return the number of methods described for TYPE, including the |
1636 | methods from types it derives from. This can't be done in the symbol | |
1637 | reader because the type of the baseclass might still be stubbed | |
1638 | when the definition of the derived class is parsed. */ | |
1639 | ||
1640 | static int total_number_of_methods PARAMS ((struct type *type)); | |
1641 | ||
1642 | static int | |
1643 | total_number_of_methods (type) | |
1644 | struct type *type; | |
1645 | { | |
1646 | int n; | |
1647 | int count; | |
1648 | ||
940d5967 | 1649 | CHECK_TYPEDEF (type); |
2b576293 C |
1650 | count = TYPE_NFN_FIELDS_TOTAL (type); |
1651 | ||
1652 | for (n = 0; n < TYPE_N_BASECLASSES (type); n++) | |
1653 | count += total_number_of_methods (TYPE_BASECLASS (type, n)); | |
1654 | ||
1655 | return count; | |
1656 | } | |
1657 | ||
bd5635a1 | 1658 | /* Recursive helper function for decode_line_1. |
2b576293 C |
1659 | Look for methods named NAME in type T. |
1660 | Return number of matches. | |
1661 | Put matches in SYM_ARR, which should have been allocated with | |
1662 | a size of total_number_of_methods (T) * sizeof (struct symbol *). | |
1663 | Note that this function is g++ specific. */ | |
bd5635a1 | 1664 | |
2cd99985 | 1665 | int |
2e4964ad | 1666 | find_methods (t, name, sym_arr) |
bd5635a1 RP |
1667 | struct type *t; |
1668 | char *name; | |
bd5635a1 RP |
1669 | struct symbol **sym_arr; |
1670 | { | |
1671 | int i1 = 0; | |
1672 | int ibase; | |
1673 | struct symbol *sym_class; | |
1674 | char *class_name = type_name_no_tag (t); | |
d34d6f75 JK |
1675 | /* Ignore this class if it doesn't have a name. This is ugly, but |
1676 | unless we figure out how to get the physname without the name of | |
1677 | the class, then the loop can't do any good. */ | |
bd5635a1 RP |
1678 | if (class_name |
1679 | && (sym_class = lookup_symbol (class_name, | |
1680 | (struct block *)NULL, | |
1681 | STRUCT_NAMESPACE, | |
1682 | (int *)NULL, | |
1683 | (struct symtab **)NULL))) | |
1684 | { | |
1685 | int method_counter; | |
940d5967 | 1686 | /* FIXME: Shouldn't this just be CHECK_TYPEDEF (t)? */ |
bd5635a1 RP |
1687 | t = SYMBOL_TYPE (sym_class); |
1688 | for (method_counter = TYPE_NFN_FIELDS (t) - 1; | |
1689 | method_counter >= 0; | |
1690 | --method_counter) | |
1691 | { | |
1692 | int field_counter; | |
1693 | struct fn_field *f = TYPE_FN_FIELDLIST1 (t, method_counter); | |
bd5635a1 | 1694 | char *method_name = TYPE_FN_FIELDLIST_NAME (t, method_counter); |
d0cde99c PS |
1695 | char dem_opname[64]; |
1696 | ||
1697 | if (strncmp(method_name, "__", 2)==0 || | |
1698 | strncmp(method_name, "op", 2)==0 || | |
1699 | strncmp(method_name, "type", 4)==0 ) | |
1700 | { | |
1701 | if (cplus_demangle_opname(method_name, dem_opname, DMGL_ANSI)) | |
1702 | method_name = dem_opname; | |
1703 | else if (cplus_demangle_opname(method_name, dem_opname, 0)) | |
1704 | method_name = dem_opname; | |
1705 | } | |
2e4964ad | 1706 | if (STREQ (name, method_name)) |
bd5635a1 RP |
1707 | /* Find all the fields with that name. */ |
1708 | for (field_counter = TYPE_FN_FIELDLIST_LENGTH (t, method_counter) - 1; | |
1709 | field_counter >= 0; | |
1710 | --field_counter) | |
1711 | { | |
1712 | char *phys_name; | |
7e258d18 | 1713 | if (TYPE_FN_FIELD_STUB (f, field_counter)) |
bd5635a1 RP |
1714 | check_stub_method (t, method_counter, field_counter); |
1715 | phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter); | |
ca6a826d PS |
1716 | /* Destructor is handled by caller, dont add it to the list */ |
1717 | if (DESTRUCTOR_PREFIX_P (phys_name)) | |
1718 | continue; | |
d34d6f75 JK |
1719 | |
1720 | /* FIXME: Why are we looking this up in the | |
1721 | SYMBOL_BLOCK_VALUE (sym_class)? It is intended as a hook | |
1722 | for nested types? If so, it should probably hook to the | |
1723 | type, not the symbol. mipsread.c is the only symbol | |
1724 | reader which sets the SYMBOL_BLOCK_VALUE for types, and | |
1725 | this is not documented in symtab.h. -26Aug93. */ | |
1726 | ||
bd5635a1 RP |
1727 | sym_arr[i1] = lookup_symbol (phys_name, |
1728 | SYMBOL_BLOCK_VALUE (sym_class), | |
1729 | VAR_NAMESPACE, | |
1730 | (int *) NULL, | |
1731 | (struct symtab **) NULL); | |
1732 | if (sym_arr[i1]) i1++; | |
2cd99985 PB |
1733 | else |
1734 | { | |
199b2450 TL |
1735 | fputs_filtered("(Cannot find method ", gdb_stdout); |
1736 | fprintf_symbol_filtered (gdb_stdout, phys_name, | |
d0cde99c PS |
1737 | language_cplus, |
1738 | DMGL_PARAMS | DMGL_ANSI); | |
199b2450 | 1739 | fputs_filtered(" - possibly inlined.)\n", gdb_stdout); |
2cd99985 | 1740 | } |
bd5635a1 RP |
1741 | } |
1742 | } | |
1743 | } | |
d34d6f75 JK |
1744 | |
1745 | /* Only search baseclasses if there is no match yet, since names in | |
1746 | derived classes override those in baseclasses. | |
1747 | ||
1748 | FIXME: The above is not true; it is only true of member functions | |
1749 | if they have the same number of arguments (??? - section 13.1 of the | |
1750 | ARM says the function members are not in the same scope but doesn't | |
1751 | really spell out the rules in a way I understand. In any case, if | |
1752 | the number of arguments differ this is a case in which we can overload | |
1753 | rather than hiding without any problem, and gcc 2.4.5 does overload | |
1754 | rather than hiding in this case). */ | |
1755 | ||
bd5635a1 RP |
1756 | if (i1) |
1757 | return i1; | |
1758 | for (ibase = 0; ibase < TYPE_N_BASECLASSES (t); ibase++) | |
1759 | i1 += find_methods(TYPE_BASECLASS(t, ibase), name, | |
2e4964ad | 1760 | sym_arr + i1); |
bd5635a1 RP |
1761 | return i1; |
1762 | } | |
1763 | ||
6f87ec4a PS |
1764 | /* Helper function for decode_line_1. |
1765 | Build a canonical line spec in CANONICAL if it is non-NULL and if | |
1766 | the SAL has a symtab. | |
1767 | If SYMNAME is non-NULL the canonical line spec is `filename:symname'. | |
1768 | If SYMNAME is NULL the line number from SAL is used and the canonical | |
1769 | line spec is `filename:linenum'. */ | |
1770 | ||
1771 | static void | |
1772 | build_canonical_line_spec (sal, symname, canonical) | |
1773 | struct symtab_and_line *sal; | |
1774 | char *symname; | |
1775 | char ***canonical; | |
1776 | { | |
1777 | char **canonical_arr; | |
1778 | char *canonical_name; | |
1779 | char *filename; | |
1780 | struct symtab *s = sal->symtab; | |
1781 | ||
1782 | if (s == (struct symtab *)NULL | |
1783 | || s->filename == (char *)NULL | |
1784 | || canonical == (char ***)NULL) | |
1785 | return; | |
1786 | ||
1787 | canonical_arr = (char **) xmalloc (sizeof (char *)); | |
1788 | *canonical = canonical_arr; | |
1789 | ||
1790 | filename = s->filename; | |
1791 | if (symname != NULL) | |
1792 | { | |
1793 | canonical_name = xmalloc (strlen (filename) + strlen (symname) + 2); | |
1794 | sprintf (canonical_name, "%s:%s", filename, symname); | |
1795 | } | |
1796 | else | |
1797 | { | |
1798 | canonical_name = xmalloc (strlen (filename) + 30); | |
1799 | sprintf (canonical_name, "%s:%d", filename, sal->line); | |
1800 | } | |
1801 | canonical_arr[0] = canonical_name; | |
1802 | } | |
1803 | ||
bd5635a1 RP |
1804 | /* Parse a string that specifies a line number. |
1805 | Pass the address of a char * variable; that variable will be | |
1806 | advanced over the characters actually parsed. | |
1807 | ||
1808 | The string can be: | |
1809 | ||
1810 | LINENUM -- that line number in current file. PC returned is 0. | |
1811 | FILE:LINENUM -- that line in that file. PC returned is 0. | |
1812 | FUNCTION -- line number of openbrace of that function. | |
1813 | PC returned is the start of the function. | |
1814 | VARIABLE -- line number of definition of that variable. | |
1815 | PC returned is 0. | |
1816 | FILE:FUNCTION -- likewise, but prefer functions in that file. | |
1817 | *EXPR -- line in which address EXPR appears. | |
1818 | ||
cba0d141 | 1819 | FUNCTION may be an undebuggable function found in minimal symbol table. |
bd5635a1 RP |
1820 | |
1821 | If the argument FUNFIRSTLINE is nonzero, we want the first line | |
76212295 PS |
1822 | of real code inside a function when a function is specified, and it is |
1823 | not OK to specify a variable or type to get its line number. | |
bd5635a1 RP |
1824 | |
1825 | DEFAULT_SYMTAB specifies the file to use if none is specified. | |
1826 | It defaults to current_source_symtab. | |
1827 | DEFAULT_LINE specifies the line number to use for relative | |
1828 | line numbers (that start with signs). Defaults to current_source_line. | |
6f87ec4a PS |
1829 | If CANONICAL is non-NULL, store an array of strings containing the canonical |
1830 | line specs there if necessary. Currently overloaded member functions and | |
1831 | line numbers or static functions without a filename yield a canonical | |
1832 | line spec. The array and the line spec strings are allocated on the heap, | |
1833 | it is the callers responsibility to free them. | |
bd5635a1 RP |
1834 | |
1835 | Note that it is possible to return zero for the symtab | |
1836 | if no file is validly specified. Callers must check that. | |
1837 | Also, the line number returned may be invalid. */ | |
1838 | ||
dbdf5a2a JK |
1839 | /* We allow single quotes in various places. This is a hideous |
1840 | kludge, which exists because the completer can't yet deal with the | |
1841 | lack of single quotes. FIXME: write a linespec_completer which we | |
1842 | can use as appropriate instead of make_symbol_completion_list. */ | |
1843 | ||
bd5635a1 | 1844 | struct symtabs_and_lines |
6f87ec4a | 1845 | decode_line_1 (argptr, funfirstline, default_symtab, default_line, canonical) |
bd5635a1 RP |
1846 | char **argptr; |
1847 | int funfirstline; | |
1848 | struct symtab *default_symtab; | |
1849 | int default_line; | |
6f87ec4a | 1850 | char ***canonical; |
bd5635a1 | 1851 | { |
bd5635a1 | 1852 | struct symtabs_and_lines values; |
c1878f87 SG |
1853 | #ifdef HPPA_COMPILER_BUG |
1854 | /* FIXME: The native HP 9000/700 compiler has a bug which appears | |
1855 | when optimizing this file with target i960-vxworks. I haven't | |
1856 | been able to construct a simple test case. The problem is that | |
1857 | in the second call to SKIP_PROLOGUE below, the compiler somehow | |
1858 | does not realize that the statement val = find_pc_line (...) will | |
1859 | change the values of the fields of val. It extracts the elements | |
1860 | into registers at the top of the block, and does not update the | |
1861 | registers after the call to find_pc_line. You can check this by | |
1862 | inserting a printf at the end of find_pc_line to show what values | |
1863 | it is returning for val.pc and val.end and another printf after | |
1864 | the call to see what values the function actually got (remember, | |
1865 | this is compiling with cc -O, with this patch removed). You can | |
1866 | also examine the assembly listing: search for the second call to | |
1867 | skip_prologue; the LDO statement before the next call to | |
1868 | find_pc_line loads the address of the structure which | |
1869 | find_pc_line will return; if there is a LDW just before the LDO, | |
1870 | which fetches an element of the structure, then the compiler | |
1871 | still has the bug. | |
1872 | ||
1873 | Setting val to volatile avoids the problem. We must undef | |
1874 | volatile, because the HPPA native compiler does not define | |
1875 | __STDC__, although it does understand volatile, and so volatile | |
1876 | will have been defined away in defs.h. */ | |
1877 | #undef volatile | |
1878 | volatile struct symtab_and_line val; | |
1879 | #define volatile /*nothing*/ | |
1880 | #else | |
bd5635a1 | 1881 | struct symtab_and_line val; |
c1878f87 | 1882 | #endif |
bd5635a1 | 1883 | register char *p, *p1; |
1c95d7ab JK |
1884 | char *q, *pp; |
1885 | #if 0 | |
1886 | char *q1; | |
1887 | #endif | |
bd5635a1 RP |
1888 | register struct symtab *s; |
1889 | ||
1890 | register struct symbol *sym; | |
1891 | /* The symtab that SYM was found in. */ | |
1892 | struct symtab *sym_symtab; | |
1893 | ||
1894 | register CORE_ADDR pc; | |
cba0d141 | 1895 | register struct minimal_symbol *msymbol; |
bd5635a1 RP |
1896 | char *copy; |
1897 | struct symbol *sym_class; | |
1898 | int i1; | |
7e6deb7a | 1899 | int is_quoted, has_parens; |
bd5635a1 RP |
1900 | struct symbol **sym_arr; |
1901 | struct type *t; | |
f70be3e4 JG |
1902 | char *saved_arg = *argptr; |
1903 | extern char *gdb_completer_quote_characters; | |
bd5635a1 RP |
1904 | |
1905 | /* Defaults have defaults. */ | |
1906 | ||
1907 | if (default_symtab == 0) | |
1908 | { | |
1909 | default_symtab = current_source_symtab; | |
1910 | default_line = current_source_line; | |
1911 | } | |
1912 | ||
8050a57b | 1913 | /* See if arg is *PC */ |
bd5635a1 | 1914 | |
8050a57b | 1915 | if (**argptr == '*') |
f70be3e4 | 1916 | { |
76212295 | 1917 | (*argptr)++; |
bd5635a1 RP |
1918 | pc = parse_and_eval_address_1 (argptr); |
1919 | values.sals = (struct symtab_and_line *) | |
1920 | xmalloc (sizeof (struct symtab_and_line)); | |
1921 | values.nelts = 1; | |
1922 | values.sals[0] = find_pc_line (pc, 0); | |
1923 | values.sals[0].pc = pc; | |
1924 | return values; | |
1925 | } | |
1926 | ||
1927 | /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */ | |
1928 | ||
8050a57b | 1929 | s = NULL; |
9b041f69 PS |
1930 | is_quoted = (**argptr |
1931 | && strchr (gdb_completer_quote_characters, **argptr) != NULL); | |
1932 | has_parens = ((pp = strchr (*argptr, '(')) != NULL | |
1933 | && (pp = strchr (pp, ')')) != NULL); | |
bd5635a1 RP |
1934 | |
1935 | for (p = *argptr; *p; p++) | |
1936 | { | |
7e6deb7a KH |
1937 | if (p[0] == '<') |
1938 | { | |
76212295 | 1939 | while(++p && *p != '>'); |
7e6deb7a KH |
1940 | if (!p) |
1941 | { | |
a0cf4681 | 1942 | error ("non-matching '<' and '>' in command"); |
7e6deb7a KH |
1943 | } |
1944 | } | |
bd5635a1 RP |
1945 | if (p[0] == ':' || p[0] == ' ' || p[0] == '\t') |
1946 | break; | |
1947 | } | |
1948 | while (p[0] == ' ' || p[0] == '\t') p++; | |
1949 | ||
7e6deb7a | 1950 | if ((p[0] == ':') && !has_parens) |
bd5635a1 RP |
1951 | { |
1952 | ||
1953 | /* C++ */ | |
7e6deb7a | 1954 | if (is_quoted) *argptr = *argptr+1; |
bd5635a1 RP |
1955 | if (p[1] ==':') |
1956 | { | |
1957 | /* Extract the class name. */ | |
1958 | p1 = p; | |
1959 | while (p != *argptr && p[-1] == ' ') --p; | |
1960 | copy = (char *) alloca (p - *argptr + 1); | |
4ed3a9ea | 1961 | memcpy (copy, *argptr, p - *argptr); |
bd5635a1 RP |
1962 | copy[p - *argptr] = 0; |
1963 | ||
1964 | /* Discard the class name from the arg. */ | |
1965 | p = p1 + 2; | |
1966 | while (*p == ' ' || *p == '\t') p++; | |
1967 | *argptr = p; | |
1968 | ||
1969 | sym_class = lookup_symbol (copy, 0, STRUCT_NAMESPACE, 0, | |
1970 | (struct symtab **)NULL); | |
1971 | ||
1972 | if (sym_class && | |
940d5967 PB |
1973 | (t = check_typedef (SYMBOL_TYPE (sym_class)), |
1974 | (TYPE_CODE (t) == TYPE_CODE_STRUCT | |
1975 | || TYPE_CODE (t) == TYPE_CODE_UNION))) | |
bd5635a1 RP |
1976 | { |
1977 | /* Arg token is not digits => try it as a function name | |
d0cde99c | 1978 | Find the next token(everything up to end or next blank). */ |
9b041f69 PS |
1979 | if (**argptr |
1980 | && strchr (gdb_completer_quote_characters, **argptr) != NULL) | |
d0cde99c PS |
1981 | { |
1982 | p = skip_quoted(*argptr); | |
1983 | *argptr = *argptr + 1; | |
1984 | } | |
1985 | else | |
1986 | { | |
1987 | p = *argptr; | |
1988 | while (*p && *p!=' ' && *p!='\t' && *p!=',' && *p!=':') p++; | |
1989 | } | |
1990 | /* | |
d96b54ea | 1991 | q = operator_chars (*argptr, &q1); |
d96b54ea JK |
1992 | if (q1 - q) |
1993 | { | |
2cd99985 PB |
1994 | char *opname; |
1995 | char *tmp = alloca (q1 - q + 1); | |
1996 | memcpy (tmp, q, q1 - q); | |
1997 | tmp[q1 - q] = '\0'; | |
8050a57b | 1998 | opname = cplus_mangle_opname (tmp, DMGL_ANSI); |
2cd99985 | 1999 | if (opname == NULL) |
f70be3e4 | 2000 | { |
a0cf4681 | 2001 | error_begin (); |
1c95d7ab | 2002 | printf_filtered ("no mangling for \"%s\"\n", tmp); |
f70be3e4 | 2003 | cplusplus_hint (saved_arg); |
f1ed4330 | 2004 | return_to_top_level (RETURN_ERROR); |
f70be3e4 | 2005 | } |
2cd99985 PB |
2006 | copy = (char*) alloca (3 + strlen(opname)); |
2007 | sprintf (copy, "__%s", opname); | |
d96b54ea JK |
2008 | p = q1; |
2009 | } | |
2010 | else | |
d0cde99c | 2011 | */ |
d96b54ea | 2012 | { |
d0cde99c | 2013 | copy = (char *) alloca (p - *argptr + 1 ); |
4ed3a9ea | 2014 | memcpy (copy, *argptr, p - *argptr); |
d96b54ea | 2015 | copy[p - *argptr] = '\0'; |
9b041f69 PS |
2016 | if (p != *argptr |
2017 | && copy[p - *argptr - 1] | |
2018 | && strchr (gdb_completer_quote_characters, | |
2019 | copy[p - *argptr - 1]) != NULL) | |
2020 | copy[p - *argptr - 1] = '\0'; | |
d96b54ea | 2021 | } |
bd5635a1 RP |
2022 | |
2023 | /* no line number may be specified */ | |
2024 | while (*p == ' ' || *p == '\t') p++; | |
2025 | *argptr = p; | |
2026 | ||
2027 | sym = 0; | |
2028 | i1 = 0; /* counter for the symbol array */ | |
2b576293 C |
2029 | sym_arr = (struct symbol **) alloca(total_number_of_methods (t) |
2030 | * sizeof(struct symbol *)); | |
bd5635a1 | 2031 | |
018ab14f PS |
2032 | /* Cfront objects don't have fieldlists. */ |
2033 | if (destructor_name_p (copy, t) && TYPE_FN_FIELDLISTS (t) != NULL) | |
bd5635a1 RP |
2034 | { |
2035 | /* destructors are a special case. */ | |
2036 | struct fn_field *f = TYPE_FN_FIELDLIST1 (t, 0); | |
2037 | int len = TYPE_FN_FIELDLIST_LENGTH (t, 0) - 1; | |
ca6a826d PS |
2038 | /* gcc 1.x puts destructor in last field, |
2039 | gcc 2.x puts destructor in first field. */ | |
bd5635a1 | 2040 | char *phys_name = TYPE_FN_FIELD_PHYSNAME (f, len); |
ca6a826d PS |
2041 | if (!DESTRUCTOR_PREFIX_P (phys_name)) |
2042 | { | |
2043 | phys_name = TYPE_FN_FIELD_PHYSNAME (f, 0); | |
2044 | if (!DESTRUCTOR_PREFIX_P (phys_name)) | |
2045 | phys_name = ""; | |
2046 | } | |
bd5635a1 RP |
2047 | sym_arr[i1] = |
2048 | lookup_symbol (phys_name, SYMBOL_BLOCK_VALUE (sym_class), | |
2049 | VAR_NAMESPACE, 0, (struct symtab **)NULL); | |
2050 | if (sym_arr[i1]) i1++; | |
2051 | } | |
2052 | else | |
2e4964ad | 2053 | i1 = find_methods (t, copy, sym_arr); |
bd5635a1 RP |
2054 | if (i1 == 1) |
2055 | { | |
2056 | /* There is exactly one field with that name. */ | |
2057 | sym = sym_arr[0]; | |
2058 | ||
2059 | if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK) | |
2060 | { | |
bd5635a1 RP |
2061 | values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line)); |
2062 | values.nelts = 1; | |
76212295 PS |
2063 | values.sals[0] = find_function_start_sal (sym, |
2064 | funfirstline); | |
bd5635a1 RP |
2065 | } |
2066 | else | |
2067 | { | |
2068 | values.nelts = 0; | |
2069 | } | |
2070 | return values; | |
2071 | } | |
2072 | if (i1 > 0) | |
2073 | { | |
2074 | /* There is more than one field with that name | |
2075 | (overloaded). Ask the user which one to use. */ | |
6f87ec4a | 2076 | return decode_line_2 (sym_arr, i1, funfirstline, canonical); |
bd5635a1 RP |
2077 | } |
2078 | else | |
d96b54ea JK |
2079 | { |
2080 | char *tmp; | |
2081 | ||
2082 | if (OPNAME_PREFIX_P (copy)) | |
2083 | { | |
2084 | tmp = (char *)alloca (strlen (copy+3) + 9); | |
2085 | strcpy (tmp, "operator "); | |
2086 | strcat (tmp, copy+3); | |
2087 | } | |
2088 | else | |
2089 | tmp = copy; | |
a0cf4681 | 2090 | error_begin (); |
0e2a896c | 2091 | if (tmp[0] == '~') |
1c95d7ab | 2092 | printf_filtered |
a0cf4681 JK |
2093 | ("the class `%s' does not have destructor defined\n", |
2094 | SYMBOL_SOURCE_NAME(sym_class)); | |
0e2a896c | 2095 | else |
1c95d7ab | 2096 | printf_filtered |
a0cf4681 JK |
2097 | ("the class %s does not have any method named %s\n", |
2098 | SYMBOL_SOURCE_NAME(sym_class), tmp); | |
f70be3e4 | 2099 | cplusplus_hint (saved_arg); |
f1ed4330 | 2100 | return_to_top_level (RETURN_ERROR); |
d96b54ea | 2101 | } |
bd5635a1 RP |
2102 | } |
2103 | else | |
f70be3e4 | 2104 | { |
a0cf4681 | 2105 | error_begin (); |
f70be3e4 | 2106 | /* The quotes are important if copy is empty. */ |
1c95d7ab | 2107 | printf_filtered |
a0cf4681 | 2108 | ("can't find class, struct, or union named \"%s\"\n", copy); |
f70be3e4 | 2109 | cplusplus_hint (saved_arg); |
f1ed4330 | 2110 | return_to_top_level (RETURN_ERROR); |
f70be3e4 | 2111 | } |
bd5635a1 RP |
2112 | } |
2113 | /* end of C++ */ | |
2114 | ||
2115 | ||
2116 | /* Extract the file name. */ | |
2117 | p1 = p; | |
2118 | while (p != *argptr && p[-1] == ' ') --p; | |
58050209 | 2119 | copy = (char *) alloca (p - *argptr + 1); |
4ed3a9ea | 2120 | memcpy (copy, *argptr, p - *argptr); |
58050209 | 2121 | copy[p - *argptr] = 0; |
bd5635a1 RP |
2122 | |
2123 | /* Find that file's data. */ | |
2124 | s = lookup_symtab (copy); | |
2125 | if (s == 0) | |
2126 | { | |
cba0d141 | 2127 | if (!have_full_symbols () && !have_partial_symbols ()) |
bd5635a1 RP |
2128 | error (no_symtab_msg); |
2129 | error ("No source file named %s.", copy); | |
2130 | } | |
2131 | ||
2132 | /* Discard the file name from the arg. */ | |
2133 | p = p1 + 1; | |
2134 | while (*p == ' ' || *p == '\t') p++; | |
2135 | *argptr = p; | |
2136 | } | |
2137 | ||
2138 | /* S is specified file's symtab, or 0 if no file specified. | |
2139 | arg no longer contains the file name. */ | |
2140 | ||
2141 | /* Check whether arg is all digits (and sign) */ | |
2142 | ||
d0cde99c PS |
2143 | q = *argptr; |
2144 | if (*q == '-' || *q == '+') q++; | |
2145 | while (*q >= '0' && *q <= '9') | |
2146 | q++; | |
bd5635a1 | 2147 | |
d0cde99c | 2148 | if (q != *argptr && (*q == 0 || *q == ' ' || *q == '\t' || *q == ',')) |
bd5635a1 RP |
2149 | { |
2150 | /* We found a token consisting of all digits -- at least one digit. */ | |
2151 | enum sign {none, plus, minus} sign = none; | |
2152 | ||
6f87ec4a PS |
2153 | /* We might need a canonical line spec if no file was specified. */ |
2154 | int need_canonical = (s == 0) ? 1 : 0; | |
2155 | ||
bd5635a1 RP |
2156 | /* This is where we need to make sure that we have good defaults. |
2157 | We must guarantee that this section of code is never executed | |
2158 | when we are called with just a function name, since | |
2159 | select_source_symtab calls us with such an argument */ | |
2160 | ||
2161 | if (s == 0 && default_symtab == 0) | |
2162 | { | |
bd5635a1 RP |
2163 | select_source_symtab (0); |
2164 | default_symtab = current_source_symtab; | |
2165 | default_line = current_source_line; | |
2166 | } | |
2167 | ||
2168 | if (**argptr == '+') | |
2169 | sign = plus, (*argptr)++; | |
2170 | else if (**argptr == '-') | |
2171 | sign = minus, (*argptr)++; | |
2172 | val.line = atoi (*argptr); | |
2173 | switch (sign) | |
2174 | { | |
2175 | case plus: | |
d0cde99c | 2176 | if (q == *argptr) |
bd5635a1 RP |
2177 | val.line = 5; |
2178 | if (s == 0) | |
2179 | val.line = default_line + val.line; | |
2180 | break; | |
2181 | case minus: | |
d0cde99c | 2182 | if (q == *argptr) |
bd5635a1 RP |
2183 | val.line = 15; |
2184 | if (s == 0) | |
2185 | val.line = default_line - val.line; | |
2186 | else | |
2187 | val.line = 1; | |
2188 | break; | |
2189 | case none: | |
2190 | break; /* No need to adjust val.line. */ | |
2191 | } | |
2192 | ||
d0cde99c PS |
2193 | while (*q == ' ' || *q == '\t') q++; |
2194 | *argptr = q; | |
bd5635a1 RP |
2195 | if (s == 0) |
2196 | s = default_symtab; | |
2197 | val.symtab = s; | |
2198 | val.pc = 0; | |
2199 | values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line)); | |
2200 | values.sals[0] = val; | |
2201 | values.nelts = 1; | |
6f87ec4a PS |
2202 | if (need_canonical) |
2203 | build_canonical_line_spec (values.sals, NULL, canonical); | |
bd5635a1 RP |
2204 | return values; |
2205 | } | |
2206 | ||
2207 | /* Arg token is not digits => try it as a variable name | |
2208 | Find the next token (everything up to end or next whitespace). */ | |
2cd99985 | 2209 | |
2b576293 C |
2210 | if (**argptr == '$') /* Convenience variable */ |
2211 | p = skip_quoted (*argptr + 1); | |
2212 | else if (is_quoted) | |
7e6deb7a KH |
2213 | { |
2214 | p = skip_quoted (*argptr); | |
2215 | if (p[-1] != '\'') | |
2216 | error ("Unmatched single quote."); | |
2217 | } | |
2218 | else if (has_parens) | |
2219 | { | |
2220 | p = pp+1; | |
2221 | } | |
d0cde99c PS |
2222 | else |
2223 | { | |
2224 | p = skip_quoted(*argptr); | |
2225 | } | |
2226 | ||
bd5635a1 | 2227 | copy = (char *) alloca (p - *argptr + 1); |
4ed3a9ea | 2228 | memcpy (copy, *argptr, p - *argptr); |
f70be3e4 | 2229 | copy[p - *argptr] = '\0'; |
e3d6ec4a | 2230 | if (p != *argptr |
9b041f69 PS |
2231 | && copy[0] |
2232 | && copy[0] == copy [p - *argptr - 1] | |
f70be3e4 JG |
2233 | && strchr (gdb_completer_quote_characters, copy[0]) != NULL) |
2234 | { | |
f70be3e4 JG |
2235 | copy [p - *argptr - 1] = '\0'; |
2236 | copy++; | |
f70be3e4 | 2237 | } |
bd5635a1 RP |
2238 | while (*p == ' ' || *p == '\t') p++; |
2239 | *argptr = p; | |
2240 | ||
2b576293 C |
2241 | /* See if it's a convenience variable */ |
2242 | ||
2243 | if (*copy == '$') | |
2244 | { | |
2245 | value_ptr valx; | |
2246 | int need_canonical = (s == 0) ? 1 : 0; | |
2247 | ||
2248 | valx = value_of_internalvar (lookup_internalvar (copy + 1)); | |
2249 | if (TYPE_CODE (VALUE_TYPE (valx)) != TYPE_CODE_INT) | |
2250 | error ("Convenience variables used in line specs must have integer values."); | |
2251 | ||
2252 | val.symtab = s ? s : default_symtab; | |
2253 | val.line = value_as_long (valx); | |
2254 | val.pc = 0; | |
2255 | ||
2256 | values.sals = (struct symtab_and_line *)xmalloc (sizeof val); | |
2257 | values.sals[0] = val; | |
2258 | values.nelts = 1; | |
2259 | ||
2260 | if (need_canonical) | |
2261 | build_canonical_line_spec (values.sals, NULL, canonical); | |
2262 | ||
2263 | return values; | |
2264 | } | |
2265 | ||
2266 | ||
bd5635a1 RP |
2267 | /* Look up that token as a variable. |
2268 | If file specified, use that file's per-file block to start with. */ | |
2269 | ||
2270 | sym = lookup_symbol (copy, | |
3ba6a043 | 2271 | (s ? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK) |
bd5635a1 RP |
2272 | : get_selected_block ()), |
2273 | VAR_NAMESPACE, 0, &sym_symtab); | |
2274 | ||
2275 | if (sym != NULL) | |
2276 | { | |
2277 | if (SYMBOL_CLASS (sym) == LOC_BLOCK) | |
2278 | { | |
2279 | /* Arg is the name of a function */ | |
bd5635a1 | 2280 | values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line)); |
76212295 | 2281 | values.sals[0] = find_function_start_sal (sym, funfirstline); |
bd5635a1 | 2282 | values.nelts = 1; |
ad0a2521 JK |
2283 | |
2284 | /* Don't use the SYMBOL_LINE; if used at all it points to | |
2285 | the line containing the parameters or thereabouts, not | |
2286 | the first line of code. */ | |
2287 | ||
2288 | /* We might need a canonical line spec if it is a static | |
2289 | function. */ | |
6f87ec4a PS |
2290 | if (s == 0) |
2291 | { | |
2292 | struct blockvector *bv = BLOCKVECTOR (sym_symtab); | |
2293 | struct block *b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
2294 | if (lookup_block_symbol (b, copy, VAR_NAMESPACE) != NULL) | |
2295 | build_canonical_line_spec (values.sals, copy, canonical); | |
2296 | } | |
bd5635a1 RP |
2297 | return values; |
2298 | } | |
76212295 | 2299 | else |
bd5635a1 | 2300 | { |
76212295 PS |
2301 | if (funfirstline) |
2302 | error ("\"%s\" is not a function", copy); | |
2303 | else if (SYMBOL_LINE (sym) != 0) | |
2304 | { | |
2305 | /* We know its line number. */ | |
2306 | values.sals = (struct symtab_and_line *) | |
2307 | xmalloc (sizeof (struct symtab_and_line)); | |
2308 | values.nelts = 1; | |
2309 | memset (&values.sals[0], 0, sizeof (values.sals[0])); | |
2310 | values.sals[0].symtab = sym_symtab; | |
2311 | values.sals[0].line = SYMBOL_LINE (sym); | |
2312 | return values; | |
2313 | } | |
2314 | else | |
2315 | /* This can happen if it is compiled with a compiler which doesn't | |
2316 | put out line numbers for variables. */ | |
2317 | /* FIXME: Shouldn't we just set .line and .symtab to zero | |
2318 | and return? For example, "info line foo" could print | |
2319 | the address. */ | |
2320 | error ("Line number not known for symbol \"%s\"", copy); | |
bd5635a1 | 2321 | } |
bd5635a1 RP |
2322 | } |
2323 | ||
2b576293 | 2324 | msymbol = lookup_minimal_symbol (copy, NULL, NULL); |
cba0d141 | 2325 | if (msymbol != NULL) |
bd5635a1 RP |
2326 | { |
2327 | val.symtab = 0; | |
2328 | val.line = 0; | |
2cacd1e3 | 2329 | val.pc = SYMBOL_VALUE_ADDRESS (msymbol); |
bd5635a1 | 2330 | if (funfirstline) |
2cacd1e3 PS |
2331 | { |
2332 | val.pc += FUNCTION_START_OFFSET; | |
2333 | SKIP_PROLOGUE (val.pc); | |
2334 | } | |
bd5635a1 RP |
2335 | values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line)); |
2336 | values.sals[0] = val; | |
2337 | values.nelts = 1; | |
2338 | return values; | |
2339 | } | |
2340 | ||
cba0d141 JG |
2341 | if (!have_full_symbols () && |
2342 | !have_partial_symbols () && !have_minimal_symbols ()) | |
997a978c JG |
2343 | error (no_symtab_msg); |
2344 | ||
f70be3e4 | 2345 | error ("Function \"%s\" not defined.", copy); |
bd5635a1 RP |
2346 | return values; /* for lint */ |
2347 | } | |
2348 | ||
2349 | struct symtabs_and_lines | |
2350 | decode_line_spec (string, funfirstline) | |
2351 | char *string; | |
2352 | int funfirstline; | |
2353 | { | |
2354 | struct symtabs_and_lines sals; | |
2355 | if (string == 0) | |
2356 | error ("Empty line specification."); | |
2357 | sals = decode_line_1 (&string, funfirstline, | |
6f87ec4a PS |
2358 | current_source_symtab, current_source_line, |
2359 | (char ***)NULL); | |
bd5635a1 RP |
2360 | if (*string) |
2361 | error ("Junk at end of line specification: %s", string); | |
2362 | return sals; | |
2363 | } | |
2364 | ||
6f87ec4a PS |
2365 | /* Given a list of NELTS symbols in SYM_ARR, return a list of lines to |
2366 | operate on (ask user if necessary). | |
2367 | If CANONICAL is non-NULL return a corresponding array of mangled names | |
2368 | as canonical line specs there. */ | |
2e4964ad | 2369 | |
cba0d141 | 2370 | static struct symtabs_and_lines |
6f87ec4a | 2371 | decode_line_2 (sym_arr, nelts, funfirstline, canonical) |
bd5635a1 RP |
2372 | struct symbol *sym_arr[]; |
2373 | int nelts; | |
2374 | int funfirstline; | |
6f87ec4a | 2375 | char ***canonical; |
bd5635a1 | 2376 | { |
bd5635a1 | 2377 | struct symtabs_and_lines values, return_values; |
cba0d141 | 2378 | char *args, *arg1; |
bd5635a1 RP |
2379 | int i; |
2380 | char *prompt; | |
2e4964ad | 2381 | char *symname; |
6f87ec4a PS |
2382 | struct cleanup *old_chain; |
2383 | char **canonical_arr = (char **)NULL; | |
bd5635a1 RP |
2384 | |
2385 | values.sals = (struct symtab_and_line *) alloca (nelts * sizeof(struct symtab_and_line)); | |
2386 | return_values.sals = (struct symtab_and_line *) xmalloc (nelts * sizeof(struct symtab_and_line)); | |
6f87ec4a PS |
2387 | old_chain = make_cleanup (free, return_values.sals); |
2388 | ||
2389 | if (canonical) | |
2390 | { | |
2391 | canonical_arr = (char **) xmalloc (nelts * sizeof (char *)); | |
2392 | make_cleanup (free, canonical_arr); | |
2393 | memset (canonical_arr, 0, nelts * sizeof (char *)); | |
2394 | *canonical = canonical_arr; | |
2395 | } | |
bd5635a1 RP |
2396 | |
2397 | i = 0; | |
199b2450 | 2398 | printf_unfiltered("[0] cancel\n[1] all\n"); |
bd5635a1 RP |
2399 | while (i < nelts) |
2400 | { | |
2401 | if (sym_arr[i] && SYMBOL_CLASS (sym_arr[i]) == LOC_BLOCK) | |
2402 | { | |
76212295 PS |
2403 | values.sals[i] = find_function_start_sal (sym_arr[i], funfirstline); |
2404 | printf_unfiltered ("[%d] %s at %s:%d\n", | |
2405 | (i+2), | |
2406 | SYMBOL_SOURCE_NAME (sym_arr[i]), | |
2407 | values.sals[i].symtab->filename, | |
2408 | values.sals[i].line); | |
bd5635a1 | 2409 | } |
76212295 PS |
2410 | else |
2411 | printf_unfiltered ("?HERE\n"); | |
bd5635a1 RP |
2412 | i++; |
2413 | } | |
2414 | ||
2415 | if ((prompt = getenv ("PS2")) == NULL) | |
2416 | { | |
2417 | prompt = ">"; | |
2418 | } | |
199b2450 TL |
2419 | printf_unfiltered("%s ",prompt); |
2420 | gdb_flush(gdb_stdout); | |
bd5635a1 | 2421 | |
a0cf4681 | 2422 | args = command_line_input ((char *) NULL, 0, "overload-choice"); |
bd5635a1 | 2423 | |
6f87ec4a | 2424 | if (args == 0 || *args == 0) |
bd5635a1 RP |
2425 | error_no_arg ("one or more choice numbers"); |
2426 | ||
2427 | i = 0; | |
2428 | while (*args) | |
2429 | { | |
2430 | int num; | |
2431 | ||
2432 | arg1 = args; | |
2433 | while (*arg1 >= '0' && *arg1 <= '9') arg1++; | |
2434 | if (*arg1 && *arg1 != ' ' && *arg1 != '\t') | |
2435 | error ("Arguments must be choice numbers."); | |
2436 | ||
2437 | num = atoi (args); | |
2438 | ||
2439 | if (num == 0) | |
2440 | error ("cancelled"); | |
2441 | else if (num == 1) | |
2442 | { | |
6f87ec4a PS |
2443 | if (canonical_arr) |
2444 | { | |
2445 | for (i = 0; i < nelts; i++) | |
2446 | { | |
2447 | if (canonical_arr[i] == NULL) | |
2448 | { | |
2449 | symname = SYMBOL_NAME (sym_arr[i]); | |
2450 | canonical_arr[i] = savestring (symname, strlen (symname)); | |
2451 | } | |
2452 | } | |
2453 | } | |
4ed3a9ea FF |
2454 | memcpy (return_values.sals, values.sals, |
2455 | (nelts * sizeof(struct symtab_and_line))); | |
bd5635a1 | 2456 | return_values.nelts = nelts; |
6f87ec4a | 2457 | discard_cleanups (old_chain); |
bd5635a1 RP |
2458 | return return_values; |
2459 | } | |
2460 | ||
2461 | if (num > nelts + 2) | |
2462 | { | |
199b2450 | 2463 | printf_unfiltered ("No choice number %d.\n", num); |
bd5635a1 RP |
2464 | } |
2465 | else | |
2466 | { | |
2467 | num -= 2; | |
2468 | if (values.sals[num].pc) | |
2469 | { | |
6f87ec4a PS |
2470 | if (canonical_arr) |
2471 | { | |
2472 | symname = SYMBOL_NAME (sym_arr[num]); | |
2473 | make_cleanup (free, symname); | |
2474 | canonical_arr[i] = savestring (symname, strlen (symname)); | |
2475 | } | |
bd5635a1 RP |
2476 | return_values.sals[i++] = values.sals[num]; |
2477 | values.sals[num].pc = 0; | |
2478 | } | |
2479 | else | |
2480 | { | |
199b2450 | 2481 | printf_unfiltered ("duplicate request for %d ignored.\n", num); |
bd5635a1 RP |
2482 | } |
2483 | } | |
2484 | ||
2485 | args = arg1; | |
2486 | while (*args == ' ' || *args == '\t') args++; | |
2487 | } | |
2488 | return_values.nelts = i; | |
6f87ec4a | 2489 | discard_cleanups (old_chain); |
bd5635a1 RP |
2490 | return return_values; |
2491 | } | |
2492 | ||
bd5635a1 RP |
2493 | \f |
2494 | /* Slave routine for sources_info. Force line breaks at ,'s. | |
2495 | NAME is the name to print and *FIRST is nonzero if this is the first | |
2496 | name printed. Set *FIRST to zero. */ | |
2497 | static void | |
2498 | output_source_filename (name, first) | |
2499 | char *name; | |
2500 | int *first; | |
2501 | { | |
bd5635a1 RP |
2502 | /* Table of files printed so far. Since a single source file can |
2503 | result in several partial symbol tables, we need to avoid printing | |
2504 | it more than once. Note: if some of the psymtabs are read in and | |
2505 | some are not, it gets printed both under "Source files for which | |
2506 | symbols have been read" and "Source files for which symbols will | |
2507 | be read in on demand". I consider this a reasonable way to deal | |
2508 | with the situation. I'm not sure whether this can also happen for | |
2509 | symtabs; it doesn't hurt to check. */ | |
2510 | static char **tab = NULL; | |
2511 | /* Allocated size of tab in elements. | |
2512 | Start with one 256-byte block (when using GNU malloc.c). | |
2513 | 24 is the malloc overhead when range checking is in effect. */ | |
2514 | static int tab_alloc_size = (256 - 24) / sizeof (char *); | |
2515 | /* Current size of tab in elements. */ | |
2516 | static int tab_cur_size; | |
2517 | ||
2518 | char **p; | |
2519 | ||
2520 | if (*first) | |
2521 | { | |
2522 | if (tab == NULL) | |
2523 | tab = (char **) xmalloc (tab_alloc_size * sizeof (*tab)); | |
2524 | tab_cur_size = 0; | |
2525 | } | |
2526 | ||
2527 | /* Is NAME in tab? */ | |
2528 | for (p = tab; p < tab + tab_cur_size; p++) | |
2e4964ad | 2529 | if (STREQ (*p, name)) |
bd5635a1 RP |
2530 | /* Yes; don't print it again. */ |
2531 | return; | |
2532 | /* No; add it to tab. */ | |
2533 | if (tab_cur_size == tab_alloc_size) | |
2534 | { | |
2535 | tab_alloc_size *= 2; | |
cba0d141 | 2536 | tab = (char **) xrealloc ((char *) tab, tab_alloc_size * sizeof (*tab)); |
bd5635a1 RP |
2537 | } |
2538 | tab[tab_cur_size++] = name; | |
2539 | ||
2540 | if (*first) | |
2541 | { | |
bd5635a1 RP |
2542 | *first = 0; |
2543 | } | |
2544 | else | |
2545 | { | |
f70be3e4 | 2546 | printf_filtered (", "); |
bd5635a1 RP |
2547 | } |
2548 | ||
f70be3e4 | 2549 | wrap_here (""); |
199b2450 | 2550 | fputs_filtered (name, gdb_stdout); |
bd5635a1 RP |
2551 | } |
2552 | ||
2553 | static void | |
35a25840 SG |
2554 | sources_info (ignore, from_tty) |
2555 | char *ignore; | |
2556 | int from_tty; | |
bd5635a1 RP |
2557 | { |
2558 | register struct symtab *s; | |
2559 | register struct partial_symtab *ps; | |
cba0d141 | 2560 | register struct objfile *objfile; |
bd5635a1 RP |
2561 | int first; |
2562 | ||
cba0d141 | 2563 | if (!have_full_symbols () && !have_partial_symbols ()) |
bd5635a1 | 2564 | { |
3053b9f2 | 2565 | error (no_symtab_msg); |
bd5635a1 RP |
2566 | } |
2567 | ||
2568 | printf_filtered ("Source files for which symbols have been read in:\n\n"); | |
2569 | ||
2570 | first = 1; | |
35a25840 | 2571 | ALL_SYMTABS (objfile, s) |
cba0d141 | 2572 | { |
35a25840 | 2573 | output_source_filename (s -> filename, &first); |
cba0d141 | 2574 | } |
bd5635a1 RP |
2575 | printf_filtered ("\n\n"); |
2576 | ||
2577 | printf_filtered ("Source files for which symbols will be read in on demand:\n\n"); | |
2578 | ||
2579 | first = 1; | |
35a25840 | 2580 | ALL_PSYMTABS (objfile, ps) |
cba0d141 | 2581 | { |
35a25840 | 2582 | if (!ps->readin) |
cba0d141 | 2583 | { |
35a25840 | 2584 | output_source_filename (ps -> filename, &first); |
cba0d141 JG |
2585 | } |
2586 | } | |
bd5635a1 RP |
2587 | printf_filtered ("\n"); |
2588 | } | |
2589 | ||
2e4964ad | 2590 | /* List all symbols (if REGEXP is NULL) or all symbols matching REGEXP. |
3a16d640 JG |
2591 | If CLASS is zero, list all symbols except functions, type names, and |
2592 | constants (enums). | |
bd5635a1 RP |
2593 | If CLASS is 1, list only functions. |
2594 | If CLASS is 2, list only type names. | |
997a978c | 2595 | If CLASS is 3, list only method names. |
bd5635a1 RP |
2596 | |
2597 | BPT is non-zero if we should set a breakpoint at the functions | |
2598 | we find. */ | |
2599 | ||
2600 | static void | |
ae6d035d | 2601 | list_symbols (regexp, class, bpt, from_tty) |
bd5635a1 RP |
2602 | char *regexp; |
2603 | int class; | |
2604 | int bpt; | |
ae6d035d | 2605 | int from_tty; |
bd5635a1 RP |
2606 | { |
2607 | register struct symtab *s; | |
2608 | register struct partial_symtab *ps; | |
2609 | register struct blockvector *bv; | |
2610 | struct blockvector *prev_bv = 0; | |
2611 | register struct block *b; | |
2612 | register int i, j; | |
2613 | register struct symbol *sym; | |
b607efe7 | 2614 | struct partial_symbol **psym; |
cba0d141 JG |
2615 | struct objfile *objfile; |
2616 | struct minimal_symbol *msymbol; | |
35a25840 | 2617 | char *val; |
bd5635a1 RP |
2618 | static char *classnames[] |
2619 | = {"variable", "function", "type", "method"}; | |
2620 | int found_in_file = 0; | |
997a978c | 2621 | int found_misc = 0; |
cba0d141 JG |
2622 | static enum minimal_symbol_type types[] |
2623 | = {mst_data, mst_text, mst_abs, mst_unknown}; | |
2624 | static enum minimal_symbol_type types2[] | |
ae6d035d PS |
2625 | = {mst_bss, mst_file_text, mst_abs, mst_unknown}; |
2626 | static enum minimal_symbol_type types3[] | |
2627 | = {mst_file_data, mst_solib_trampoline, mst_abs, mst_unknown}; | |
2628 | static enum minimal_symbol_type types4[] | |
2629 | = {mst_file_bss, mst_text, mst_abs, mst_unknown}; | |
cba0d141 JG |
2630 | enum minimal_symbol_type ourtype = types[class]; |
2631 | enum minimal_symbol_type ourtype2 = types2[class]; | |
ae6d035d PS |
2632 | enum minimal_symbol_type ourtype3 = types3[class]; |
2633 | enum minimal_symbol_type ourtype4 = types4[class]; | |
bd5635a1 | 2634 | |
2e4964ad | 2635 | if (regexp != NULL) |
2cd99985 PB |
2636 | { |
2637 | /* Make sure spacing is right for C++ operators. | |
2638 | This is just a courtesy to make the matching less sensitive | |
2639 | to how many spaces the user leaves between 'operator' | |
2640 | and <TYPENAME> or <OPERATOR>. */ | |
2641 | char *opend; | |
2642 | char *opname = operator_chars (regexp, &opend); | |
2643 | if (*opname) | |
2644 | { | |
2645 | int fix = -1; /* -1 means ok; otherwise number of spaces needed. */ | |
2646 | if (isalpha(*opname) || *opname == '_' || *opname == '$') | |
2647 | { | |
2648 | /* There should 1 space between 'operator' and 'TYPENAME'. */ | |
2649 | if (opname[-1] != ' ' || opname[-2] == ' ') | |
2650 | fix = 1; | |
2651 | } | |
2652 | else | |
2653 | { | |
2654 | /* There should 0 spaces between 'operator' and 'OPERATOR'. */ | |
2655 | if (opname[-1] == ' ') | |
2656 | fix = 0; | |
2657 | } | |
2658 | /* If wrong number of spaces, fix it. */ | |
2659 | if (fix >= 0) | |
2660 | { | |
2661 | char *tmp = (char*) alloca(opend-opname+10); | |
2662 | sprintf(tmp, "operator%.*s%s", fix, " ", opname); | |
2663 | regexp = tmp; | |
2664 | } | |
2665 | } | |
2666 | ||
2667 | if (0 != (val = re_comp (regexp))) | |
2668 | error ("Invalid regexp (%s): %s", val, regexp); | |
2669 | } | |
bd5635a1 | 2670 | |
cba0d141 | 2671 | /* Search through the partial symtabs *first* for all symbols |
bd5635a1 RP |
2672 | matching the regexp. That way we don't have to reproduce all of |
2673 | the machinery below. */ | |
bd5635a1 | 2674 | |
35a25840 | 2675 | ALL_PSYMTABS (objfile, ps) |
cba0d141 | 2676 | { |
b607efe7 | 2677 | struct partial_symbol **bound, **gbound, **sbound; |
35a25840 SG |
2678 | int keep_going = 1; |
2679 | ||
2680 | if (ps->readin) continue; | |
2681 | ||
2682 | gbound = objfile->global_psymbols.list + ps->globals_offset + ps->n_global_syms; | |
2683 | sbound = objfile->static_psymbols.list + ps->statics_offset + ps->n_static_syms; | |
2684 | bound = gbound; | |
2685 | ||
2686 | /* Go through all of the symbols stored in a partial | |
2687 | symtab in one loop. */ | |
2688 | psym = objfile->global_psymbols.list + ps->globals_offset; | |
2689 | while (keep_going) | |
bd5635a1 | 2690 | { |
35a25840 | 2691 | if (psym >= bound) |
bd5635a1 | 2692 | { |
35a25840 | 2693 | if (bound == gbound && ps->n_static_syms != 0) |
bd5635a1 | 2694 | { |
35a25840 SG |
2695 | psym = objfile->static_psymbols.list + ps->statics_offset; |
2696 | bound = sbound; | |
bd5635a1 RP |
2697 | } |
2698 | else | |
35a25840 SG |
2699 | keep_going = 0; |
2700 | continue; | |
2701 | } | |
2702 | else | |
2703 | { | |
2704 | QUIT; | |
2705 | ||
2706 | /* If it would match (logic taken from loop below) | |
2707 | load the file and go on to the next one */ | |
b607efe7 FF |
2708 | if ((regexp == NULL || SYMBOL_MATCHES_REGEXP (*psym)) |
2709 | && ((class == 0 && SYMBOL_CLASS (*psym) != LOC_TYPEDEF | |
2710 | && SYMBOL_CLASS (*psym) != LOC_BLOCK) | |
2711 | || (class == 1 && SYMBOL_CLASS (*psym) == LOC_BLOCK) | |
2712 | || (class == 2 && SYMBOL_CLASS (*psym) == LOC_TYPEDEF) | |
2713 | || (class == 3 && SYMBOL_CLASS (*psym) == LOC_BLOCK))) | |
bd5635a1 | 2714 | { |
4ed3a9ea | 2715 | PSYMTAB_TO_SYMTAB(ps); |
35a25840 | 2716 | keep_going = 0; |
bd5635a1 RP |
2717 | } |
2718 | } | |
35a25840 | 2719 | psym++; |
bd5635a1 RP |
2720 | } |
2721 | } | |
2722 | ||
76212295 PS |
2723 | /* Here, we search through the minimal symbol tables for functions |
2724 | and variables that match, and force their symbols to be read. | |
2725 | This is in particular necessary for demangled variable names, | |
2726 | which are no longer put into the partial symbol tables. | |
2727 | The symbol will then be found during the scan of symtabs below. | |
2728 | ||
2729 | For functions, find_pc_symtab should succeed if we have debug info | |
2730 | for the function, for variables we have to call lookup_symbol | |
2731 | to determine if the variable has debug info. | |
2732 | If the lookup fails, set found_misc so that we will rescan to print | |
2733 | any matching symbols without debug info. | |
2734 | */ | |
997a978c | 2735 | |
76212295 | 2736 | if (class == 0 || class == 1) |
cba0d141 | 2737 | { |
35a25840 | 2738 | ALL_MSYMBOLS (objfile, msymbol) |
cba0d141 | 2739 | { |
2e4964ad | 2740 | if (MSYMBOL_TYPE (msymbol) == ourtype || |
ae6d035d PS |
2741 | MSYMBOL_TYPE (msymbol) == ourtype2 || |
2742 | MSYMBOL_TYPE (msymbol) == ourtype3 || | |
2743 | MSYMBOL_TYPE (msymbol) == ourtype4) | |
cba0d141 | 2744 | { |
2e4964ad | 2745 | if (regexp == NULL || SYMBOL_MATCHES_REGEXP (msymbol)) |
cba0d141 | 2746 | { |
2e4964ad | 2747 | if (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol))) |
cba0d141 | 2748 | { |
76212295 PS |
2749 | if (class == 1 |
2750 | || lookup_symbol (SYMBOL_NAME (msymbol), | |
2751 | (struct block *) NULL, | |
2752 | VAR_NAMESPACE, | |
2753 | 0, (struct symtab **) NULL) == NULL) | |
2754 | found_misc = 1; | |
cba0d141 JG |
2755 | } |
2756 | } | |
2757 | } | |
2758 | } | |
bd5635a1 RP |
2759 | } |
2760 | ||
2761 | /* Printout here so as to get after the "Reading in symbols" | |
2762 | messages which will be generated above. */ | |
2763 | if (!bpt) | |
2764 | printf_filtered (regexp | |
2765 | ? "All %ss matching regular expression \"%s\":\n" | |
2766 | : "All defined %ss:\n", | |
2767 | classnames[class], | |
2768 | regexp); | |
2769 | ||
35a25840 | 2770 | ALL_SYMTABS (objfile, s) |
bd5635a1 | 2771 | { |
35a25840 SG |
2772 | found_in_file = 0; |
2773 | bv = BLOCKVECTOR (s); | |
2774 | /* Often many files share a blockvector. | |
2775 | Scan each blockvector only once so that | |
2776 | we don't get every symbol many times. | |
2777 | It happens that the first symtab in the list | |
2778 | for any given blockvector is the main file. */ | |
2779 | if (bv != prev_bv) | |
2780 | for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++) | |
2781 | { | |
2782 | b = BLOCKVECTOR_BLOCK (bv, i); | |
2783 | /* Skip the sort if this block is always sorted. */ | |
2784 | if (!BLOCK_SHOULD_SORT (b)) | |
2785 | sort_block_syms (b); | |
2786 | for (j = 0; j < BLOCK_NSYMS (b); j++) | |
bd5635a1 | 2787 | { |
35a25840 SG |
2788 | QUIT; |
2789 | sym = BLOCK_SYM (b, j); | |
2e4964ad | 2790 | if ((regexp == NULL || SYMBOL_MATCHES_REGEXP (sym)) |
35a25840 | 2791 | && ((class == 0 && SYMBOL_CLASS (sym) != LOC_TYPEDEF |
3a16d640 JG |
2792 | && SYMBOL_CLASS (sym) != LOC_BLOCK |
2793 | && SYMBOL_CLASS (sym) != LOC_CONST) | |
35a25840 SG |
2794 | || (class == 1 && SYMBOL_CLASS (sym) == LOC_BLOCK) |
2795 | || (class == 2 && SYMBOL_CLASS (sym) == LOC_TYPEDEF) | |
2796 | || (class == 3 && SYMBOL_CLASS (sym) == LOC_BLOCK))) | |
bd5635a1 | 2797 | { |
35a25840 | 2798 | if (bpt) |
bd5635a1 | 2799 | { |
35a25840 SG |
2800 | /* Set a breakpoint here, if it's a function */ |
2801 | if (class == 1) | |
ca6a826d PS |
2802 | { |
2803 | /* There may be more than one function with the | |
2804 | same name but in different files. In order to | |
2805 | set breakpoints on all of them, we must give | |
2806 | both the file name and the function name to | |
76212295 PS |
2807 | break_command. |
2808 | Quoting the symbol name gets rid of problems | |
2809 | with mangled symbol names that contain | |
2810 | CPLUS_MARKER characters. */ | |
ca6a826d PS |
2811 | char *string = |
2812 | (char *) alloca (strlen (s->filename) | |
2813 | + strlen (SYMBOL_NAME(sym)) | |
76212295 | 2814 | + 4); |
ca6a826d | 2815 | strcpy (string, s->filename); |
76212295 | 2816 | strcat (string, ":'"); |
ca6a826d | 2817 | strcat (string, SYMBOL_NAME(sym)); |
76212295 | 2818 | strcat (string, "'"); |
ae6d035d | 2819 | break_command (string, from_tty); |
ca6a826d | 2820 | } |
35a25840 SG |
2821 | } |
2822 | else if (!found_in_file) | |
2823 | { | |
199b2450 TL |
2824 | fputs_filtered ("\nFile ", gdb_stdout); |
2825 | fputs_filtered (s->filename, gdb_stdout); | |
2826 | fputs_filtered (":\n", gdb_stdout); | |
35a25840 SG |
2827 | } |
2828 | found_in_file = 1; | |
2829 | ||
2830 | if (class != 2 && i == STATIC_BLOCK) | |
2831 | printf_filtered ("static "); | |
2832 | ||
2833 | /* Typedef that is not a C++ class */ | |
2834 | if (class == 2 | |
2835 | && SYMBOL_NAMESPACE (sym) != STRUCT_NAMESPACE) | |
199b2450 | 2836 | c_typedef_print (SYMBOL_TYPE(sym), sym, gdb_stdout); |
35a25840 SG |
2837 | /* variable, func, or typedef-that-is-c++-class */ |
2838 | else if (class < 2 || | |
2839 | (class == 2 && | |
2840 | SYMBOL_NAMESPACE(sym) == STRUCT_NAMESPACE)) | |
2841 | { | |
2842 | type_print (SYMBOL_TYPE (sym), | |
2843 | (SYMBOL_CLASS (sym) == LOC_TYPEDEF | |
2e4964ad | 2844 | ? "" : SYMBOL_SOURCE_NAME (sym)), |
199b2450 | 2845 | gdb_stdout, 0); |
cba0d141 | 2846 | |
35a25840 SG |
2847 | printf_filtered (";\n"); |
2848 | } | |
2849 | else | |
2850 | { | |
a8a69e63 | 2851 | # if 0 /* FIXME, why is this zapped out? */ |
35a25840 | 2852 | char buf[1024]; |
a8a69e63 | 2853 | c_type_print_base (TYPE_FN_FIELD_TYPE(t, i), |
199b2450 | 2854 | gdb_stdout, 0, 0); |
a8a69e63 | 2855 | c_type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t, i), |
199b2450 | 2856 | gdb_stdout, 0); |
35a25840 | 2857 | sprintf (buf, " %s::", type_name_no_tag (t)); |
a8a69e63 | 2858 | cp_type_print_method_args (TYPE_FN_FIELD_ARGS (t, i), |
199b2450 | 2859 | buf, name, gdb_stdout); |
bd5635a1 RP |
2860 | # endif |
2861 | } | |
2862 | } | |
2863 | } | |
35a25840 SG |
2864 | } |
2865 | prev_bv = bv; | |
bd5635a1 | 2866 | } |
997a978c | 2867 | |
997a978c | 2868 | /* If there are no eyes, avoid all contact. I mean, if there are |
cba0d141 JG |
2869 | no debug symbols, then print directly from the msymbol_vector. */ |
2870 | ||
2871 | if (found_misc || class != 1) | |
2872 | { | |
2873 | found_in_file = 0; | |
35a25840 | 2874 | ALL_MSYMBOLS (objfile, msymbol) |
cba0d141 | 2875 | { |
2e4964ad | 2876 | if (MSYMBOL_TYPE (msymbol) == ourtype || |
ae6d035d PS |
2877 | MSYMBOL_TYPE (msymbol) == ourtype2 || |
2878 | MSYMBOL_TYPE (msymbol) == ourtype3 || | |
2879 | MSYMBOL_TYPE (msymbol) == ourtype4) | |
cba0d141 | 2880 | { |
2e4964ad | 2881 | if (regexp == NULL || SYMBOL_MATCHES_REGEXP (msymbol)) |
cba0d141 | 2882 | { |
35a25840 | 2883 | /* Functions: Look up by address. */ |
f70be3e4 | 2884 | if (class != 1 || |
2e4964ad | 2885 | (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol)))) |
cba0d141 | 2886 | { |
35a25840 | 2887 | /* Variables/Absolutes: Look up by name */ |
2e4964ad FF |
2888 | if (lookup_symbol (SYMBOL_NAME (msymbol), |
2889 | (struct block *) NULL, VAR_NAMESPACE, | |
2890 | 0, (struct symtab **) NULL) == NULL) | |
cba0d141 | 2891 | { |
f21c9aec KH |
2892 | if (bpt) |
2893 | { | |
2894 | break_command (SYMBOL_NAME (msymbol), from_tty); | |
3f687c78 | 2895 | printf_filtered ("<function, no debug info> %s;\n", |
f21c9aec KH |
2896 | SYMBOL_SOURCE_NAME (msymbol)); |
2897 | continue; | |
2898 | } | |
35a25840 | 2899 | if (!found_in_file) |
cba0d141 | 2900 | { |
35a25840 SG |
2901 | printf_filtered ("\nNon-debugging symbols:\n"); |
2902 | found_in_file = 1; | |
cba0d141 | 2903 | } |
5573d7d4 JK |
2904 | printf_filtered (" %08lx %s\n", |
2905 | (unsigned long) SYMBOL_VALUE_ADDRESS (msymbol), | |
2e4964ad | 2906 | SYMBOL_SOURCE_NAME (msymbol)); |
cba0d141 JG |
2907 | } |
2908 | } | |
2909 | } | |
2910 | } | |
997a978c | 2911 | } |
997a978c | 2912 | } |
bd5635a1 RP |
2913 | } |
2914 | ||
2915 | static void | |
35a25840 | 2916 | variables_info (regexp, from_tty) |
bd5635a1 | 2917 | char *regexp; |
35a25840 | 2918 | int from_tty; |
bd5635a1 | 2919 | { |
ae6d035d | 2920 | list_symbols (regexp, 0, 0, from_tty); |
bd5635a1 RP |
2921 | } |
2922 | ||
2923 | static void | |
35a25840 | 2924 | functions_info (regexp, from_tty) |
bd5635a1 | 2925 | char *regexp; |
35a25840 | 2926 | int from_tty; |
bd5635a1 | 2927 | { |
ae6d035d | 2928 | list_symbols (regexp, 1, 0, from_tty); |
bd5635a1 RP |
2929 | } |
2930 | ||
bd5635a1 | 2931 | static void |
35a25840 | 2932 | types_info (regexp, from_tty) |
bd5635a1 | 2933 | char *regexp; |
35a25840 | 2934 | int from_tty; |
bd5635a1 | 2935 | { |
ae6d035d | 2936 | list_symbols (regexp, 2, 0, from_tty); |
bd5635a1 | 2937 | } |
bd5635a1 RP |
2938 | |
2939 | #if 0 | |
2940 | /* Tiemann says: "info methods was never implemented." */ | |
2941 | static void | |
2942 | methods_info (regexp) | |
2943 | char *regexp; | |
2944 | { | |
ae6d035d | 2945 | list_symbols (regexp, 3, 0, from_tty); |
bd5635a1 RP |
2946 | } |
2947 | #endif /* 0 */ | |
2948 | ||
2949 | /* Breakpoint all functions matching regular expression. */ | |
2950 | static void | |
35a25840 | 2951 | rbreak_command (regexp, from_tty) |
bd5635a1 | 2952 | char *regexp; |
35a25840 | 2953 | int from_tty; |
bd5635a1 | 2954 | { |
ae6d035d | 2955 | list_symbols (regexp, 1, 1, from_tty); |
bd5635a1 RP |
2956 | } |
2957 | \f | |
bd5635a1 RP |
2958 | |
2959 | /* Return Nonzero if block a is lexically nested within block b, | |
2960 | or if a and b have the same pc range. | |
2961 | Return zero otherwise. */ | |
2962 | int | |
2963 | contained_in (a, b) | |
2964 | struct block *a, *b; | |
2965 | { | |
2966 | if (!a || !b) | |
2967 | return 0; | |
2968 | return BLOCK_START (a) >= BLOCK_START (b) | |
2969 | && BLOCK_END (a) <= BLOCK_END (b); | |
2970 | } | |
2971 | ||
2972 | \f | |
2973 | /* Helper routine for make_symbol_completion_list. */ | |
2974 | ||
f70be3e4 JG |
2975 | static int return_val_size; |
2976 | static int return_val_index; | |
2977 | static char **return_val; | |
2978 | ||
f1ed4330 | 2979 | #define COMPLETION_LIST_ADD_SYMBOL(symbol, sym_text, len, text, word) \ |
2e4964ad | 2980 | do { \ |
f1ed4330 | 2981 | if (SYMBOL_DEMANGLED_NAME (symbol) != NULL) \ |
67a64bec JK |
2982 | /* Put only the mangled name on the list. */ \ |
2983 | /* Advantage: "b foo<TAB>" completes to "b foo(int, int)" */ \ | |
2984 | /* Disadvantage: "b foo__i<TAB>" doesn't complete. */ \ | |
f1ed4330 JK |
2985 | completion_list_add_name \ |
2986 | (SYMBOL_DEMANGLED_NAME (symbol), (sym_text), (len), (text), (word)); \ | |
67a64bec JK |
2987 | else \ |
2988 | completion_list_add_name \ | |
2989 | (SYMBOL_NAME (symbol), (sym_text), (len), (text), (word)); \ | |
2e4964ad FF |
2990 | } while (0) |
2991 | ||
2992 | /* Test to see if the symbol specified by SYMNAME (which is already | |
f1ed4330 | 2993 | demangled for C++ symbols) matches SYM_TEXT in the first SYM_TEXT_LEN |
2e4964ad | 2994 | characters. If so, add it to the current completion list. */ |
bd5635a1 | 2995 | |
cba0d141 | 2996 | static void |
f1ed4330 | 2997 | completion_list_add_name (symname, sym_text, sym_text_len, text, word) |
bd5635a1 | 2998 | char *symname; |
f1ed4330 JK |
2999 | char *sym_text; |
3000 | int sym_text_len; | |
f70be3e4 | 3001 | char *text; |
f1ed4330 | 3002 | char *word; |
bd5635a1 | 3003 | { |
f70be3e4 | 3004 | int newsize; |
8005788c RP |
3005 | int i; |
3006 | ||
3007 | /* clip symbols that cannot match */ | |
3008 | ||
f1ed4330 | 3009 | if (strncmp (symname, sym_text, sym_text_len) != 0) |
2e4964ad | 3010 | { |
8005788c RP |
3011 | return; |
3012 | } | |
f70be3e4 | 3013 | |
2e4964ad FF |
3014 | /* Clip any symbol names that we've already considered. (This is a |
3015 | time optimization) */ | |
8005788c | 3016 | |
2e4964ad FF |
3017 | for (i = 0; i < return_val_index; ++i) |
3018 | { | |
3019 | if (STREQ (symname, return_val[i])) | |
3020 | { | |
3021 | return; | |
3022 | } | |
f70be3e4 | 3023 | } |
2e4964ad FF |
3024 | |
3025 | /* We have a match for a completion, so add SYMNAME to the current list | |
3026 | of matches. Note that the name is moved to freshly malloc'd space. */ | |
f70be3e4 | 3027 | |
f1ed4330 JK |
3028 | { |
3029 | char *new; | |
3030 | if (word == sym_text) | |
3031 | { | |
3032 | new = xmalloc (strlen (symname) + 5); | |
3033 | strcpy (new, symname); | |
3034 | } | |
3035 | else if (word > sym_text) | |
3036 | { | |
3037 | /* Return some portion of symname. */ | |
3038 | new = xmalloc (strlen (symname) + 5); | |
3039 | strcpy (new, symname + (word - sym_text)); | |
3040 | } | |
3041 | else | |
3042 | { | |
3043 | /* Return some of SYM_TEXT plus symname. */ | |
3044 | new = xmalloc (strlen (symname) + (sym_text - word) + 5); | |
3045 | strncpy (new, word, sym_text - word); | |
3046 | new[sym_text - word] = '\0'; | |
3047 | strcat (new, symname); | |
3048 | } | |
3049 | ||
2b576293 C |
3050 | /* Recheck for duplicates if we intend to add a modified symbol. */ |
3051 | if (word != sym_text) | |
3052 | { | |
3053 | for (i = 0; i < return_val_index; ++i) | |
3054 | { | |
3055 | if (STREQ (new, return_val[i])) | |
3056 | { | |
3057 | free (new); | |
3058 | return; | |
3059 | } | |
3060 | } | |
3061 | } | |
3062 | ||
f1ed4330 JK |
3063 | if (return_val_index + 3 > return_val_size) |
3064 | { | |
3065 | newsize = (return_val_size *= 2) * sizeof (char *); | |
3066 | return_val = (char **) xrealloc ((char *) return_val, newsize); | |
3067 | } | |
3068 | return_val[return_val_index++] = new; | |
3069 | return_val[return_val_index] = NULL; | |
3070 | } | |
bd5635a1 RP |
3071 | } |
3072 | ||
3073 | /* Return a NULL terminated array of all symbols (regardless of class) which | |
3074 | begin by matching TEXT. If the answer is no symbols, then the return value | |
3075 | is an array which contains only a NULL pointer. | |
3076 | ||
f70be3e4 JG |
3077 | Problem: All of the symbols have to be copied because readline frees them. |
3078 | I'm not going to worry about this; hopefully there won't be that many. */ | |
bd5635a1 RP |
3079 | |
3080 | char ** | |
f1ed4330 JK |
3081 | make_symbol_completion_list (text, word) |
3082 | char *text; | |
3083 | char *word; | |
bd5635a1 | 3084 | { |
f70be3e4 | 3085 | register struct symbol *sym; |
bd5635a1 RP |
3086 | register struct symtab *s; |
3087 | register struct partial_symtab *ps; | |
cba0d141 JG |
3088 | register struct minimal_symbol *msymbol; |
3089 | register struct objfile *objfile; | |
bd5635a1 | 3090 | register struct block *b, *surrounding_static_block = 0; |
bd5635a1 | 3091 | register int i, j; |
b607efe7 | 3092 | struct partial_symbol **psym; |
f1ed4330 JK |
3093 | /* The symbol we are completing on. Points in same buffer as text. */ |
3094 | char *sym_text; | |
3095 | /* Length of sym_text. */ | |
3096 | int sym_text_len; | |
3097 | ||
3098 | /* Now look for the symbol we are supposed to complete on. | |
3099 | FIXME: This should be language-specific. */ | |
3100 | { | |
3101 | char *p; | |
3102 | char quote_found; | |
01d3fdba | 3103 | char *quote_pos = NULL; |
f1ed4330 JK |
3104 | |
3105 | /* First see if this is a quoted string. */ | |
3106 | quote_found = '\0'; | |
3107 | for (p = text; *p != '\0'; ++p) | |
3108 | { | |
3109 | if (quote_found != '\0') | |
3110 | { | |
3111 | if (*p == quote_found) | |
3112 | /* Found close quote. */ | |
3113 | quote_found = '\0'; | |
3114 | else if (*p == '\\' && p[1] == quote_found) | |
3115 | /* A backslash followed by the quote character | |
3116 | doesn't end the string. */ | |
3117 | ++p; | |
3118 | } | |
3119 | else if (*p == '\'' || *p == '"') | |
3120 | { | |
3121 | quote_found = *p; | |
3122 | quote_pos = p; | |
3123 | } | |
3124 | } | |
3125 | if (quote_found == '\'') | |
3126 | /* A string within single quotes can be a symbol, so complete on it. */ | |
3127 | sym_text = quote_pos + 1; | |
3128 | else if (quote_found == '"') | |
3129 | /* A double-quoted string is never a symbol, nor does it make sense | |
3130 | to complete it any other way. */ | |
3131 | return NULL; | |
3132 | else | |
3133 | { | |
3134 | /* It is not a quoted string. Break it based on the characters | |
3135 | which are in symbols. */ | |
3136 | while (p > text) | |
3137 | { | |
3138 | if (isalnum (p[-1]) || p[-1] == '_' || p[-1] == '\0') | |
3139 | --p; | |
3140 | else | |
3141 | break; | |
3142 | } | |
3143 | sym_text = p; | |
3144 | } | |
3145 | } | |
3146 | ||
3147 | sym_text_len = strlen (sym_text); | |
bd5635a1 | 3148 | |
bd5635a1 RP |
3149 | return_val_size = 100; |
3150 | return_val_index = 0; | |
f70be3e4 JG |
3151 | return_val = (char **) xmalloc ((return_val_size + 1) * sizeof (char *)); |
3152 | return_val[0] = NULL; | |
bd5635a1 RP |
3153 | |
3154 | /* Look through the partial symtabs for all symbols which begin | |
f1ed4330 | 3155 | by matching SYM_TEXT. Add each one that you find to the list. */ |
bd5635a1 | 3156 | |
35a25840 | 3157 | ALL_PSYMTABS (objfile, ps) |
bd5635a1 | 3158 | { |
35a25840 SG |
3159 | /* If the psymtab's been read in we'll get it when we search |
3160 | through the blockvector. */ | |
3161 | if (ps->readin) continue; | |
3162 | ||
3163 | for (psym = objfile->global_psymbols.list + ps->globals_offset; | |
3164 | psym < (objfile->global_psymbols.list + ps->globals_offset | |
3165 | + ps->n_global_syms); | |
3166 | psym++) | |
bd5635a1 | 3167 | { |
f70be3e4 JG |
3168 | /* If interrupted, then quit. */ |
3169 | QUIT; | |
b607efe7 | 3170 | COMPLETION_LIST_ADD_SYMBOL (*psym, sym_text, sym_text_len, text, word); |
35a25840 SG |
3171 | } |
3172 | ||
3173 | for (psym = objfile->static_psymbols.list + ps->statics_offset; | |
3174 | psym < (objfile->static_psymbols.list + ps->statics_offset | |
3175 | + ps->n_static_syms); | |
3176 | psym++) | |
3177 | { | |
3178 | QUIT; | |
b607efe7 | 3179 | COMPLETION_LIST_ADD_SYMBOL (*psym, sym_text, sym_text_len, text, word); |
bd5635a1 RP |
3180 | } |
3181 | } | |
3182 | ||
cba0d141 | 3183 | /* At this point scan through the misc symbol vectors and add each |
bd5635a1 RP |
3184 | symbol you find to the list. Eventually we want to ignore |
3185 | anything that isn't a text symbol (everything else will be | |
3186 | handled by the psymtab code above). */ | |
3187 | ||
35a25840 | 3188 | ALL_MSYMBOLS (objfile, msymbol) |
cba0d141 | 3189 | { |
f70be3e4 | 3190 | QUIT; |
f1ed4330 | 3191 | COMPLETION_LIST_ADD_SYMBOL (msymbol, sym_text, sym_text_len, text, word); |
cba0d141 | 3192 | } |
bd5635a1 RP |
3193 | |
3194 | /* Search upwards from currently selected frame (so that we can | |
3195 | complete on local vars. */ | |
f70be3e4 JG |
3196 | |
3197 | for (b = get_selected_block (); b != NULL; b = BLOCK_SUPERBLOCK (b)) | |
3198 | { | |
3199 | if (!BLOCK_SUPERBLOCK (b)) | |
3200 | { | |
3201 | surrounding_static_block = b; /* For elmin of dups */ | |
3202 | } | |
3203 | ||
3204 | /* Also catch fields of types defined in this places which match our | |
3205 | text string. Only complete on types visible from current context. */ | |
3206 | ||
3207 | for (i = 0; i < BLOCK_NSYMS (b); i++) | |
3208 | { | |
3209 | sym = BLOCK_SYM (b, i); | |
f1ed4330 | 3210 | COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word); |
f70be3e4 JG |
3211 | if (SYMBOL_CLASS (sym) == LOC_TYPEDEF) |
3212 | { | |
3213 | struct type *t = SYMBOL_TYPE (sym); | |
3214 | enum type_code c = TYPE_CODE (t); | |
3215 | ||
3216 | if (c == TYPE_CODE_UNION || c == TYPE_CODE_STRUCT) | |
3217 | { | |
3218 | for (j = TYPE_N_BASECLASSES (t); j < TYPE_NFIELDS (t); j++) | |
3219 | { | |
3220 | if (TYPE_FIELD_NAME (t, j)) | |
3221 | { | |
2e4964ad | 3222 | completion_list_add_name (TYPE_FIELD_NAME (t, j), |
f1ed4330 | 3223 | sym_text, sym_text_len, text, word); |
f70be3e4 JG |
3224 | } |
3225 | } | |
3226 | } | |
3227 | } | |
3228 | } | |
3229 | } | |
3230 | ||
3231 | /* Go through the symtabs and check the externs and statics for | |
3232 | symbols which match. */ | |
3233 | ||
3234 | ALL_SYMTABS (objfile, s) | |
3235 | { | |
3236 | QUIT; | |
3237 | b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK); | |
3238 | for (i = 0; i < BLOCK_NSYMS (b); i++) | |
3239 | { | |
3240 | sym = BLOCK_SYM (b, i); | |
f1ed4330 | 3241 | COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word); |
f70be3e4 JG |
3242 | } |
3243 | } | |
3244 | ||
3245 | ALL_SYMTABS (objfile, s) | |
3246 | { | |
3247 | QUIT; | |
3248 | b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK); | |
3249 | /* Don't do this block twice. */ | |
3250 | if (b == surrounding_static_block) continue; | |
3251 | for (i = 0; i < BLOCK_NSYMS (b); i++) | |
3252 | { | |
3253 | sym = BLOCK_SYM (b, i); | |
f1ed4330 | 3254 | COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word); |
f70be3e4 JG |
3255 | } |
3256 | } | |
3257 | ||
3258 | return (return_val); | |
3259 | } | |
3260 | ||
3f687c78 SG |
3261 | /* Determine if PC is in the prologue of a function. The prologue is the area |
3262 | between the first instruction of a function, and the first executable line. | |
3263 | Returns 1 if PC *might* be in prologue, 0 if definately *not* in prologue. | |
9b041f69 PS |
3264 | |
3265 | If non-zero, func_start is where we thing the prologue starts, possibly | |
3266 | by previous examination of symbol table information. | |
3f687c78 SG |
3267 | */ |
3268 | ||
3269 | int | |
3270 | in_prologue (pc, func_start) | |
3271 | CORE_ADDR pc; | |
3272 | CORE_ADDR func_start; | |
3273 | { | |
3274 | struct symtab_and_line sal; | |
3275 | CORE_ADDR func_addr, func_end; | |
3276 | ||
3277 | if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end)) | |
3278 | goto nosyms; /* Might be in prologue */ | |
3279 | ||
3280 | sal = find_pc_line (func_addr, 0); | |
3281 | ||
3282 | if (sal.line == 0) | |
3283 | goto nosyms; | |
3284 | ||
3285 | if (sal.end > func_addr | |
3286 | && sal.end <= func_end) /* Is prologue in function? */ | |
3287 | return pc < sal.end; /* Yes, is pc in prologue? */ | |
3288 | ||
3289 | /* The line after the prologue seems to be outside the function. In this | |
3290 | case, tell the caller to find the prologue the hard way. */ | |
3291 | ||
3292 | return 1; | |
3293 | ||
3294 | /* Come here when symtabs don't contain line # info. In this case, it is | |
3295 | likely that the user has stepped into a library function w/o symbols, or | |
3296 | is doing a stepi/nexti through code without symbols. */ | |
3297 | ||
3298 | nosyms: | |
3299 | ||
9b041f69 PS |
3300 | /* If func_start is zero (meaning unknown) then we don't know whether pc is |
3301 | in the prologue or not. I.E. it might be. */ | |
3302 | ||
3303 | if (!func_start) return 1; | |
3304 | ||
3f687c78 SG |
3305 | /* We need to call the target-specific prologue skipping functions with the |
3306 | function's start address because PC may be pointing at an instruction that | |
3307 | could be mistakenly considered part of the prologue. */ | |
3308 | ||
3309 | SKIP_PROLOGUE (func_start); | |
3310 | ||
3311 | return pc < func_start; | |
3312 | } | |
3313 | ||
997a978c | 3314 | \f |
bd5635a1 RP |
3315 | void |
3316 | _initialize_symtab () | |
3317 | { | |
3318 | add_info ("variables", variables_info, | |
3319 | "All global and static variable names, or those matching REGEXP."); | |
3320 | add_info ("functions", functions_info, | |
3321 | "All function names, or those matching REGEXP."); | |
3ba6a043 JG |
3322 | |
3323 | /* FIXME: This command has at least the following problems: | |
bd5635a1 RP |
3324 | 1. It prints builtin types (in a very strange and confusing fashion). |
3325 | 2. It doesn't print right, e.g. with | |
3326 | typedef struct foo *FOO | |
3327 | type_print prints "FOO" when we want to make it (in this situation) | |
3328 | print "struct foo *". | |
3329 | I also think "ptype" or "whatis" is more likely to be useful (but if | |
3330 | there is much disagreement "info types" can be fixed). */ | |
3331 | add_info ("types", types_info, | |
a0a6174a | 3332 | "All type names, or those matching REGEXP."); |
3ba6a043 | 3333 | |
bd5635a1 RP |
3334 | #if 0 |
3335 | add_info ("methods", methods_info, | |
3336 | "All method names, or those matching REGEXP::REGEXP.\n\ | |
50e0dc41 | 3337 | If the class qualifier is omitted, it is assumed to be the current scope.\n\ |
cba0d141 | 3338 | If the first REGEXP is omitted, then all methods matching the second REGEXP\n\ |
bd5635a1 RP |
3339 | are listed."); |
3340 | #endif | |
3341 | add_info ("sources", sources_info, | |
3342 | "Source files in the program."); | |
3343 | ||
3344 | add_com ("rbreak", no_class, rbreak_command, | |
3345 | "Set a breakpoint for all functions matching REGEXP."); | |
3346 | ||
997a978c | 3347 | /* Initialize the one built-in type that isn't language dependent... */ |
cba0d141 JG |
3348 | builtin_type_error = init_type (TYPE_CODE_ERROR, 0, 0, |
3349 | "<unknown type>", (struct objfile *) NULL); | |
bd5635a1 | 3350 | } |