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