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 | |
3 | Free Software Foundation, Inc. | |
4 | ||
5 | This file is part of GDB. | |
6 | ||
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. | |
11 | ||
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. | |
16 | ||
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, Boston, MA 02111-1307, USA. */ | |
20 | ||
21 | #include "defs.h" | |
22 | #include "symtab.h" | |
23 | #include "gdbtypes.h" | |
24 | #include "gdbcore.h" | |
25 | #include "frame.h" | |
26 | #include "target.h" | |
27 | #include "value.h" | |
28 | #include "symfile.h" | |
29 | #include "objfiles.h" | |
30 | #include "gdbcmd.h" | |
31 | #include "call-cmds.h" | |
32 | #include "gnu-regex.h" | |
33 | #include "expression.h" | |
34 | #include "language.h" | |
35 | #include "demangle.h" | |
36 | #include "inferior.h" | |
37 | ||
38 | #include "obstack.h" | |
39 | ||
40 | #include <sys/types.h> | |
41 | #include <fcntl.h> | |
42 | #include "gdb_string.h" | |
43 | #include "gdb_stat.h" | |
44 | #include <ctype.h> | |
45 | ||
46 | /* Prototype for one function in parser-defs.h, | |
47 | instead of including that entire file. */ | |
48 | ||
49 | extern char * find_template_name_end PARAMS ((char *)); | |
50 | ||
51 | /* Prototypes for local functions */ | |
52 | ||
53 | static int find_methods PARAMS ((struct type *, char *, struct symbol **)); | |
54 | ||
55 | static void completion_list_add_name PARAMS ((char *, char *, int, char *, | |
56 | char *)); | |
57 | ||
58 | static void build_canonical_line_spec PARAMS ((struct symtab_and_line *, | |
59 | char *, char ***)); | |
60 | ||
61 | static struct symtabs_and_lines decode_line_2 PARAMS ((struct symbol *[], | |
62 | int, int, char ***)); | |
63 | ||
64 | static void rbreak_command PARAMS ((char *, int)); | |
65 | ||
66 | static void types_info PARAMS ((char *, int)); | |
67 | ||
68 | static void functions_info PARAMS ((char *, int)); | |
69 | ||
70 | static void variables_info PARAMS ((char *, int)); | |
71 | ||
72 | static void sources_info PARAMS ((char *, int)); | |
73 | ||
74 | static void output_source_filename PARAMS ((char *, int *)); | |
75 | ||
76 | char *operator_chars PARAMS ((char *, char **)); | |
77 | ||
78 | static int find_line_common PARAMS ((struct linetable *, int, int *)); | |
79 | ||
80 | static struct partial_symbol *lookup_partial_symbol PARAMS | |
81 | ((struct partial_symtab *, const char *, | |
82 | int, namespace_enum)); | |
83 | ||
84 | static struct partial_symbol *fixup_psymbol_section PARAMS ((struct | |
85 | partial_symbol *, struct objfile *)); | |
86 | ||
87 | static struct symtab *lookup_symtab_1 PARAMS ((char *)); | |
88 | ||
89 | static void cplusplus_hint PARAMS ((char *)); | |
90 | ||
91 | static struct symbol *find_active_alias PARAMS ((struct symbol *sym, | |
92 | CORE_ADDR addr)); | |
93 | ||
94 | /* This flag is used in hppa-tdep.c, and set in hp-symtab-read.c */ | |
95 | /* Signals the presence of objects compiled by HP compilers */ | |
96 | int hp_som_som_object_present = 0; | |
97 | ||
98 | static void fixup_section PARAMS ((struct general_symbol_info *, | |
99 | struct objfile *)); | |
100 | ||
101 | static int file_matches PARAMS ((char *, char **, int)); | |
102 | ||
103 | static void print_symbol_info PARAMS ((namespace_enum, | |
104 | struct symtab *, struct symbol *, | |
105 | int, char *)); | |
106 | ||
107 | static void print_msymbol_info PARAMS ((struct minimal_symbol *)); | |
108 | ||
109 | static void symtab_symbol_info PARAMS ((char *, namespace_enum, int)); | |
110 | ||
111 | void _initialize_symtab PARAMS ((void)); | |
112 | ||
113 | /* */ | |
114 | ||
115 | /* The single non-language-specific builtin type */ | |
116 | struct type *builtin_type_error; | |
117 | ||
118 | /* Block in which the most recently searched-for symbol was found. | |
119 | Might be better to make this a parameter to lookup_symbol and | |
120 | value_of_this. */ | |
121 | ||
122 | const struct block *block_found; | |
123 | ||
124 | char no_symtab_msg[] = "No symbol table is loaded. Use the \"file\" command."; | |
125 | ||
126 | /* While the C++ support is still in flux, issue a possibly helpful hint on | |
127 | using the new command completion feature on single quoted demangled C++ | |
128 | symbols. Remove when loose ends are cleaned up. FIXME -fnf */ | |
129 | ||
130 | static void | |
131 | cplusplus_hint (name) | |
132 | char *name; | |
133 | { | |
134 | while (*name == '\'') | |
135 | name++; | |
136 | printf_filtered ("Hint: try '%s<TAB> or '%s<ESC-?>\n", name, name); | |
137 | printf_filtered ("(Note leading single quote.)\n"); | |
138 | } | |
139 | ||
140 | /* Check for a symtab of a specific name; first in symtabs, then in | |
141 | psymtabs. *If* there is no '/' in the name, a match after a '/' | |
142 | in the symtab filename will also work. */ | |
143 | ||
144 | static struct symtab * | |
145 | lookup_symtab_1 (name) | |
146 | char *name; | |
147 | { | |
148 | register struct symtab *s; | |
149 | register struct partial_symtab *ps; | |
150 | register char *slash; | |
151 | register struct objfile *objfile; | |
152 | ||
153 | got_symtab: | |
154 | ||
155 | /* First, search for an exact match */ | |
156 | ||
157 | ALL_SYMTABS (objfile, s) | |
158 | if (STREQ (name, s->filename)) | |
159 | return s; | |
160 | ||
161 | slash = strchr (name, '/'); | |
162 | ||
163 | /* Now, search for a matching tail (only if name doesn't have any dirs) */ | |
164 | ||
165 | if (!slash) | |
166 | ALL_SYMTABS (objfile, s) | |
167 | { | |
168 | char *p = s -> filename; | |
169 | char *tail = strrchr (p, '/'); | |
170 | ||
171 | if (tail) | |
172 | p = tail + 1; | |
173 | ||
174 | if (STREQ (p, name)) | |
175 | return s; | |
176 | } | |
177 | ||
178 | /* Same search rules as above apply here, but now we look thru the | |
179 | psymtabs. */ | |
180 | ||
181 | ps = lookup_partial_symtab (name); | |
182 | if (!ps) | |
183 | return (NULL); | |
184 | ||
185 | if (ps -> readin) | |
186 | error ("Internal: readin %s pst for `%s' found when no symtab found.", | |
187 | ps -> filename, name); | |
188 | ||
189 | s = PSYMTAB_TO_SYMTAB (ps); | |
190 | ||
191 | if (s) | |
192 | return s; | |
193 | ||
194 | /* At this point, we have located the psymtab for this file, but | |
195 | the conversion to a symtab has failed. This usually happens | |
196 | when we are looking up an include file. In this case, | |
197 | PSYMTAB_TO_SYMTAB doesn't return a symtab, even though one has | |
198 | been created. So, we need to run through the symtabs again in | |
199 | order to find the file. | |
200 | XXX - This is a crock, and should be fixed inside of the the | |
201 | symbol parsing routines. */ | |
202 | goto got_symtab; | |
203 | } | |
204 | ||
205 | /* Lookup the symbol table of a source file named NAME. Try a couple | |
206 | of variations if the first lookup doesn't work. */ | |
207 | ||
208 | struct symtab * | |
209 | lookup_symtab (name) | |
210 | char *name; | |
211 | { | |
212 | register struct symtab *s; | |
213 | #if 0 | |
214 | register char *copy; | |
215 | #endif | |
216 | ||
217 | s = lookup_symtab_1 (name); | |
218 | if (s) return s; | |
219 | ||
220 | #if 0 | |
221 | /* This screws c-exp.y:yylex if there is both a type "tree" and a symtab | |
222 | "tree.c". */ | |
223 | ||
224 | /* If name not found as specified, see if adding ".c" helps. */ | |
225 | /* Why is this? Is it just a user convenience? (If so, it's pretty | |
226 | questionable in the presence of C++, FORTRAN, etc.). It's not in | |
227 | the GDB manual. */ | |
228 | ||
229 | copy = (char *) alloca (strlen (name) + 3); | |
230 | strcpy (copy, name); | |
231 | strcat (copy, ".c"); | |
232 | s = lookup_symtab_1 (copy); | |
233 | if (s) return s; | |
234 | #endif /* 0 */ | |
235 | ||
236 | /* We didn't find anything; die. */ | |
237 | return 0; | |
238 | } | |
239 | ||
240 | /* Lookup the partial symbol table of a source file named NAME. | |
241 | *If* there is no '/' in the name, a match after a '/' | |
242 | in the psymtab filename will also work. */ | |
243 | ||
244 | struct partial_symtab * | |
245 | lookup_partial_symtab (name) | |
246 | char *name; | |
247 | { | |
248 | register struct partial_symtab *pst; | |
249 | register struct objfile *objfile; | |
250 | ||
251 | ALL_PSYMTABS (objfile, pst) | |
252 | { | |
253 | if (STREQ (name, pst -> filename)) | |
254 | { | |
255 | return (pst); | |
256 | } | |
257 | } | |
258 | ||
259 | /* Now, search for a matching tail (only if name doesn't have any dirs) */ | |
260 | ||
261 | if (!strchr (name, '/')) | |
262 | ALL_PSYMTABS (objfile, pst) | |
263 | { | |
264 | char *p = pst -> filename; | |
265 | char *tail = strrchr (p, '/'); | |
266 | ||
267 | if (tail) | |
268 | p = tail + 1; | |
269 | ||
270 | if (STREQ (p, name)) | |
271 | return (pst); | |
272 | } | |
273 | ||
274 | return (NULL); | |
275 | } | |
276 | \f | |
277 | /* Mangle a GDB method stub type. This actually reassembles the pieces of the | |
278 | full method name, which consist of the class name (from T), the unadorned | |
279 | method name from METHOD_ID, and the signature for the specific overload, | |
280 | specified by SIGNATURE_ID. Note that this function is g++ specific. */ | |
281 | ||
282 | char * | |
283 | gdb_mangle_name (type, method_id, signature_id) | |
284 | struct type *type; | |
285 | int method_id, signature_id; | |
286 | { | |
287 | int mangled_name_len; | |
288 | char *mangled_name; | |
289 | struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id); | |
290 | struct fn_field *method = &f[signature_id]; | |
291 | char *field_name = TYPE_FN_FIELDLIST_NAME (type, method_id); | |
292 | char *physname = TYPE_FN_FIELD_PHYSNAME (f, signature_id); | |
293 | char *newname = type_name_no_tag (type); | |
294 | ||
295 | /* Does the form of physname indicate that it is the full mangled name | |
296 | of a constructor (not just the args)? */ | |
297 | int is_full_physname_constructor; | |
298 | ||
299 | int is_constructor; | |
300 | int is_destructor = DESTRUCTOR_PREFIX_P (physname); | |
301 | /* Need a new type prefix. */ | |
302 | char *const_prefix = method->is_const ? "C" : ""; | |
303 | char *volatile_prefix = method->is_volatile ? "V" : ""; | |
304 | char buf[20]; | |
305 | int len = (newname == NULL ? 0 : strlen (newname)); | |
306 | ||
307 | is_full_physname_constructor = | |
308 | ((physname[0]=='_' && physname[1]=='_' && | |
309 | (isdigit(physname[2]) || physname[2]=='Q' || physname[2]=='t')) | |
310 | || (strncmp(physname, "__ct", 4) == 0)); | |
311 | ||
312 | is_constructor = | |
313 | is_full_physname_constructor || (newname && STREQ(field_name, newname)); | |
314 | ||
315 | if (!is_destructor) | |
316 | is_destructor = (strncmp(physname, "__dt", 4) == 0); | |
317 | ||
318 | if (is_destructor || is_full_physname_constructor) | |
319 | { | |
320 | mangled_name = (char*) xmalloc(strlen(physname)+1); | |
321 | strcpy(mangled_name, physname); | |
322 | return mangled_name; | |
323 | } | |
324 | ||
325 | if (len == 0) | |
326 | { | |
327 | sprintf (buf, "__%s%s", const_prefix, volatile_prefix); | |
328 | } | |
329 | else if (physname[0] == 't' || physname[0] == 'Q') | |
330 | { | |
331 | /* The physname for template and qualified methods already includes | |
332 | the class name. */ | |
333 | sprintf (buf, "__%s%s", const_prefix, volatile_prefix); | |
334 | newname = NULL; | |
335 | len = 0; | |
336 | } | |
337 | else | |
338 | { | |
339 | sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len); | |
340 | } | |
341 | mangled_name_len = ((is_constructor ? 0 : strlen (field_name)) | |
342 | + strlen (buf) + len | |
343 | + strlen (physname) | |
344 | + 1); | |
345 | ||
346 | /* Only needed for GNU-mangled names. ANSI-mangled names | |
347 | work with the normal mechanisms. */ | |
348 | if (OPNAME_PREFIX_P (field_name)) | |
349 | { | |
350 | const char *opname = cplus_mangle_opname (field_name + 3, 0); | |
351 | if (opname == NULL) | |
352 | error ("No mangling for \"%s\"", field_name); | |
353 | mangled_name_len += strlen (opname); | |
354 | mangled_name = (char *)xmalloc (mangled_name_len); | |
355 | ||
356 | strncpy (mangled_name, field_name, 3); | |
357 | mangled_name[3] = '\0'; | |
358 | strcat (mangled_name, opname); | |
359 | } | |
360 | else | |
361 | { | |
362 | mangled_name = (char *)xmalloc (mangled_name_len); | |
363 | if (is_constructor) | |
364 | mangled_name[0] = '\0'; | |
365 | else | |
366 | strcpy (mangled_name, field_name); | |
367 | } | |
368 | strcat (mangled_name, buf); | |
369 | /* If the class doesn't have a name, i.e. newname NULL, then we just | |
370 | mangle it using 0 for the length of the class. Thus it gets mangled | |
371 | as something starting with `::' rather than `classname::'. */ | |
372 | if (newname != NULL) | |
373 | strcat (mangled_name, newname); | |
374 | ||
375 | strcat (mangled_name, physname); | |
376 | return (mangled_name); | |
377 | } | |
378 | ||
379 | \f | |
380 | ||
381 | /* Find which partial symtab on contains PC and SECTION. Return 0 if none. */ | |
382 | ||
383 | struct partial_symtab * | |
384 | find_pc_sect_psymtab (pc, section) | |
385 | CORE_ADDR pc; | |
386 | asection *section; | |
387 | { | |
388 | register struct partial_symtab *pst; | |
389 | register struct objfile *objfile; | |
390 | ||
391 | ALL_PSYMTABS (objfile, pst) | |
392 | { | |
393 | #if defined(HPUXHPPA) | |
394 | if (pc >= pst->textlow && pc <= pst->texthigh) | |
395 | #else | |
396 | if (pc >= pst->textlow && pc < pst->texthigh) | |
397 | #endif | |
398 | { | |
399 | struct minimal_symbol *msymbol; | |
400 | struct partial_symtab *tpst; | |
401 | ||
402 | /* An objfile that has its functions reordered might have | |
403 | many partial symbol tables containing the PC, but | |
404 | we want the partial symbol table that contains the | |
405 | function containing the PC. */ | |
406 | if (!(objfile->flags & OBJF_REORDERED) && | |
407 | section == 0) /* can't validate section this way */ | |
408 | return (pst); | |
409 | ||
410 | msymbol = lookup_minimal_symbol_by_pc_section (pc, section); | |
411 | if (msymbol == NULL) | |
412 | return (pst); | |
413 | ||
414 | for (tpst = pst; tpst != NULL; tpst = tpst->next) | |
415 | { | |
416 | #if defined(HPUXHPPA) | |
417 | if (pc >= tpst->textlow && pc <= tpst->texthigh) | |
418 | #else | |
419 | if (pc >= tpst->textlow && pc < tpst->texthigh) | |
420 | #endif | |
421 | { | |
422 | struct partial_symbol *p; | |
423 | ||
424 | p = find_pc_sect_psymbol (tpst, pc, section); | |
425 | if (p != NULL | |
426 | && SYMBOL_VALUE_ADDRESS(p) | |
427 | == SYMBOL_VALUE_ADDRESS (msymbol)) | |
428 | return (tpst); | |
429 | } | |
430 | } | |
431 | return (pst); | |
432 | } | |
433 | } | |
434 | return (NULL); | |
435 | } | |
436 | ||
437 | /* Find which partial symtab contains PC. Return 0 if none. | |
438 | Backward compatibility, no section */ | |
439 | ||
440 | struct partial_symtab * | |
441 | find_pc_psymtab (pc) | |
442 | CORE_ADDR pc; | |
443 | { | |
444 | return find_pc_sect_psymtab (pc, find_pc_mapped_section (pc)); | |
445 | } | |
446 | ||
447 | /* Find which partial symbol within a psymtab matches PC and SECTION. | |
448 | Return 0 if none. Check all psymtabs if PSYMTAB is 0. */ | |
449 | ||
450 | struct partial_symbol * | |
451 | find_pc_sect_psymbol (psymtab, pc, section) | |
452 | struct partial_symtab *psymtab; | |
453 | CORE_ADDR pc; | |
454 | asection *section; | |
455 | { | |
456 | struct partial_symbol *best = NULL, *p, **pp; | |
457 | CORE_ADDR best_pc; | |
458 | ||
459 | if (!psymtab) | |
460 | psymtab = find_pc_sect_psymtab (pc, section); | |
461 | if (!psymtab) | |
462 | return 0; | |
463 | ||
464 | /* Cope with programs that start at address 0 */ | |
465 | best_pc = (psymtab->textlow != 0) ? psymtab->textlow - 1 : 0; | |
466 | ||
467 | /* Search the global symbols as well as the static symbols, so that | |
468 | find_pc_partial_function doesn't use a minimal symbol and thus | |
469 | cache a bad endaddr. */ | |
470 | for (pp = psymtab->objfile->global_psymbols.list + psymtab->globals_offset; | |
471 | (pp - (psymtab->objfile->global_psymbols.list + psymtab->globals_offset) | |
472 | < psymtab->n_global_syms); | |
473 | pp++) | |
474 | { | |
475 | p = *pp; | |
476 | if (SYMBOL_NAMESPACE (p) == VAR_NAMESPACE | |
477 | && SYMBOL_CLASS (p) == LOC_BLOCK | |
478 | && pc >= SYMBOL_VALUE_ADDRESS (p) | |
479 | && (SYMBOL_VALUE_ADDRESS (p) > best_pc | |
480 | || (psymtab->textlow == 0 | |
481 | && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0))) | |
482 | { | |
483 | if (section) /* match on a specific section */ | |
484 | { | |
485 | fixup_psymbol_section (p, psymtab->objfile); | |
486 | if (SYMBOL_BFD_SECTION (p) != section) | |
487 | continue; | |
488 | } | |
489 | best_pc = SYMBOL_VALUE_ADDRESS (p); | |
490 | best = p; | |
491 | } | |
492 | } | |
493 | ||
494 | for (pp = psymtab->objfile->static_psymbols.list + psymtab->statics_offset; | |
495 | (pp - (psymtab->objfile->static_psymbols.list + psymtab->statics_offset) | |
496 | < psymtab->n_static_syms); | |
497 | pp++) | |
498 | { | |
499 | p = *pp; | |
500 | if (SYMBOL_NAMESPACE (p) == VAR_NAMESPACE | |
501 | && SYMBOL_CLASS (p) == LOC_BLOCK | |
502 | && pc >= SYMBOL_VALUE_ADDRESS (p) | |
503 | && (SYMBOL_VALUE_ADDRESS (p) > best_pc | |
504 | || (psymtab->textlow == 0 | |
505 | && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0))) | |
506 | { | |
507 | if (section) /* match on a specific section */ | |
508 | { | |
509 | fixup_psymbol_section (p, psymtab->objfile); | |
510 | if (SYMBOL_BFD_SECTION (p) != section) | |
511 | continue; | |
512 | } | |
513 | best_pc = SYMBOL_VALUE_ADDRESS (p); | |
514 | best = p; | |
515 | } | |
516 | } | |
517 | ||
518 | return best; | |
519 | } | |
520 | ||
521 | /* Find which partial symbol within a psymtab matches PC. Return 0 if none. | |
522 | Check all psymtabs if PSYMTAB is 0. Backwards compatibility, no section. */ | |
523 | ||
524 | struct partial_symbol * | |
525 | find_pc_psymbol (psymtab, pc) | |
526 | struct partial_symtab *psymtab; | |
527 | CORE_ADDR pc; | |
528 | { | |
529 | return find_pc_sect_psymbol (psymtab, pc, find_pc_mapped_section (pc)); | |
530 | } | |
531 | \f | |
532 | /* Debug symbols usually don't have section information. We need to dig that | |
533 | out of the minimal symbols and stash that in the debug symbol. */ | |
534 | ||
535 | static void | |
536 | fixup_section (ginfo, objfile) | |
537 | struct general_symbol_info *ginfo; | |
538 | struct objfile *objfile; | |
539 | { | |
540 | struct minimal_symbol *msym; | |
541 | msym = lookup_minimal_symbol (ginfo->name, NULL, objfile); | |
542 | ||
543 | if (msym) | |
544 | ginfo->bfd_section = SYMBOL_BFD_SECTION (msym); | |
545 | } | |
546 | ||
547 | struct symbol * | |
548 | fixup_symbol_section (sym, objfile) | |
549 | struct symbol *sym; | |
550 | struct objfile *objfile; | |
551 | { | |
552 | if (!sym) | |
553 | return NULL; | |
554 | ||
555 | if (SYMBOL_BFD_SECTION (sym)) | |
556 | return sym; | |
557 | ||
558 | fixup_section (&sym->ginfo, objfile); | |
559 | ||
560 | return sym; | |
561 | } | |
562 | ||
563 | static struct partial_symbol * | |
564 | fixup_psymbol_section (psym, objfile) | |
565 | struct partial_symbol *psym; | |
566 | struct objfile *objfile; | |
567 | { | |
568 | if (!psym) | |
569 | return NULL; | |
570 | ||
571 | if (SYMBOL_BFD_SECTION (psym)) | |
572 | return psym; | |
573 | ||
574 | fixup_section (&psym->ginfo, objfile); | |
575 | ||
576 | return psym; | |
577 | } | |
578 | ||
579 | /* Find the definition for a specified symbol name NAME | |
580 | in namespace NAMESPACE, visible from lexical block BLOCK. | |
581 | Returns the struct symbol pointer, or zero if no symbol is found. | |
582 | If SYMTAB is non-NULL, store the symbol table in which the | |
583 | symbol was found there, or NULL if not found. | |
584 | C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if | |
585 | NAME is a field of the current implied argument `this'. If so set | |
586 | *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero. | |
587 | BLOCK_FOUND is set to the block in which NAME is found (in the case of | |
588 | a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */ | |
589 | ||
590 | /* This function has a bunch of loops in it and it would seem to be | |
591 | attractive to put in some QUIT's (though I'm not really sure | |
592 | whether it can run long enough to be really important). But there | |
593 | are a few calls for which it would appear to be bad news to quit | |
594 | out of here: find_proc_desc in alpha-tdep.c and mips-tdep.c, and | |
595 | nindy_frame_chain_valid in nindy-tdep.c. (Note that there is C++ | |
596 | code below which can error(), but that probably doesn't affect | |
597 | these calls since they are looking for a known variable and thus | |
598 | can probably assume it will never hit the C++ code). */ | |
599 | ||
600 | struct symbol * | |
601 | lookup_symbol (name, block, namespace, is_a_field_of_this, symtab) | |
602 | const char *name; | |
603 | register const struct block *block; | |
604 | const namespace_enum namespace; | |
605 | int *is_a_field_of_this; | |
606 | struct symtab **symtab; | |
607 | { | |
608 | register struct symbol *sym; | |
609 | register struct symtab *s = NULL; | |
610 | register struct partial_symtab *ps; | |
611 | struct blockvector *bv; | |
612 | register struct objfile *objfile = NULL; | |
613 | register struct block *b; | |
614 | register struct minimal_symbol *msymbol; | |
615 | ||
616 | /* Search specified block and its superiors. */ | |
617 | ||
618 | while (block != 0) | |
619 | { | |
620 | sym = lookup_block_symbol (block, name, namespace); | |
621 | if (sym) | |
622 | { | |
623 | block_found = block; | |
624 | if (symtab != NULL) | |
625 | { | |
626 | /* Search the list of symtabs for one which contains the | |
627 | address of the start of this block. */ | |
628 | ALL_SYMTABS (objfile, s) | |
629 | { | |
630 | bv = BLOCKVECTOR (s); | |
631 | b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
632 | if (BLOCK_START (b) <= BLOCK_START (block) | |
633 | && BLOCK_END (b) > BLOCK_START (block)) | |
634 | goto found; | |
635 | } | |
636 | found: | |
637 | *symtab = s; | |
638 | } | |
639 | ||
640 | return fixup_symbol_section (sym, objfile); | |
641 | } | |
642 | block = BLOCK_SUPERBLOCK (block); | |
643 | } | |
644 | ||
645 | /* FIXME: this code is never executed--block is always NULL at this | |
646 | point. What is it trying to do, anyway? We already should have | |
647 | checked the STATIC_BLOCK above (it is the superblock of top-level | |
648 | blocks). Why is VAR_NAMESPACE special-cased? */ | |
649 | /* Don't need to mess with the psymtabs; if we have a block, | |
650 | that file is read in. If we don't, then we deal later with | |
651 | all the psymtab stuff that needs checking. */ | |
652 | /* Note (RT): The following never-executed code looks unnecessary to me also. | |
653 | * If we change the code to use the original (passed-in) | |
654 | * value of 'block', we could cause it to execute, but then what | |
655 | * would it do? The STATIC_BLOCK of the symtab containing the passed-in | |
656 | * 'block' was already searched by the above code. And the STATIC_BLOCK's | |
657 | * of *other* symtabs (those files not containing 'block' lexically) | |
658 | * should not contain 'block' address-wise. So we wouldn't expect this | |
659 | * code to find any 'sym''s that were not found above. I vote for | |
660 | * deleting the following paragraph of code. | |
661 | */ | |
662 | if (namespace == VAR_NAMESPACE && block != NULL) | |
663 | { | |
664 | struct block *b; | |
665 | /* Find the right symtab. */ | |
666 | ALL_SYMTABS (objfile, s) | |
667 | { | |
668 | bv = BLOCKVECTOR (s); | |
669 | b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
670 | if (BLOCK_START (b) <= BLOCK_START (block) | |
671 | && BLOCK_END (b) > BLOCK_START (block)) | |
672 | { | |
673 | sym = lookup_block_symbol (b, name, VAR_NAMESPACE); | |
674 | if (sym) | |
675 | { | |
676 | block_found = b; | |
677 | if (symtab != NULL) | |
678 | *symtab = s; | |
679 | return fixup_symbol_section (sym, objfile); | |
680 | } | |
681 | } | |
682 | } | |
683 | } | |
684 | ||
685 | ||
686 | /* C++: If requested to do so by the caller, | |
687 | check to see if NAME is a field of `this'. */ | |
688 | if (is_a_field_of_this) | |
689 | { | |
690 | struct value *v = value_of_this (0); | |
691 | ||
692 | *is_a_field_of_this = 0; | |
693 | if (v && check_field (v, name)) | |
694 | { | |
695 | *is_a_field_of_this = 1; | |
696 | if (symtab != NULL) | |
697 | *symtab = NULL; | |
698 | return NULL; | |
699 | } | |
700 | } | |
701 | ||
702 | /* Now search all global blocks. Do the symtab's first, then | |
703 | check the psymtab's. If a psymtab indicates the existence | |
704 | of the desired name as a global, then do psymtab-to-symtab | |
705 | conversion on the fly and return the found symbol. */ | |
706 | ||
707 | ALL_SYMTABS (objfile, s) | |
708 | { | |
709 | bv = BLOCKVECTOR (s); | |
710 | block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
711 | sym = lookup_block_symbol (block, name, namespace); | |
712 | if (sym) | |
713 | { | |
714 | block_found = block; | |
715 | if (symtab != NULL) | |
716 | *symtab = s; | |
717 | return fixup_symbol_section (sym, objfile); | |
718 | } | |
719 | } | |
720 | ||
721 | #ifndef HPUXHPPA | |
722 | ||
723 | /* Check for the possibility of the symbol being a function or | |
724 | a mangled variable that is stored in one of the minimal symbol tables. | |
725 | Eventually, all global symbols might be resolved in this way. */ | |
726 | ||
727 | if (namespace == VAR_NAMESPACE) | |
728 | { | |
729 | msymbol = lookup_minimal_symbol (name, NULL, NULL); | |
730 | if (msymbol != NULL) | |
731 | { | |
732 | s = find_pc_sect_symtab (SYMBOL_VALUE_ADDRESS (msymbol), | |
733 | SYMBOL_BFD_SECTION (msymbol)); | |
734 | if (s != NULL) | |
735 | { | |
736 | /* This is a function which has a symtab for its address. */ | |
737 | bv = BLOCKVECTOR (s); | |
738 | block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
739 | sym = lookup_block_symbol (block, SYMBOL_NAME (msymbol), | |
740 | namespace); | |
741 | /* We kept static functions in minimal symbol table as well as | |
742 | in static scope. We want to find them in the symbol table. */ | |
743 | if (!sym) { | |
744 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
745 | sym = lookup_block_symbol (block, SYMBOL_NAME (msymbol), | |
746 | namespace); | |
747 | } | |
748 | ||
749 | /* sym == 0 if symbol was found in the minimal symbol table | |
750 | but not in the symtab. | |
751 | Return 0 to use the msymbol definition of "foo_". | |
752 | ||
753 | This happens for Fortran "foo_" symbols, | |
754 | which are "foo" in the symtab. | |
755 | ||
756 | This can also happen if "asm" is used to make a | |
757 | regular symbol but not a debugging symbol, e.g. | |
758 | asm(".globl _main"); | |
759 | asm("_main:"); | |
760 | */ | |
761 | ||
762 | if (symtab != NULL) | |
763 | *symtab = s; | |
764 | return fixup_symbol_section (sym, objfile); | |
765 | } | |
766 | else if (MSYMBOL_TYPE (msymbol) != mst_text | |
767 | && MSYMBOL_TYPE (msymbol) != mst_file_text | |
768 | && !STREQ (name, SYMBOL_NAME (msymbol))) | |
769 | { | |
770 | /* This is a mangled variable, look it up by its | |
771 | mangled name. */ | |
772 | return lookup_symbol (SYMBOL_NAME (msymbol), block, | |
773 | namespace, is_a_field_of_this, symtab); | |
774 | } | |
775 | /* There are no debug symbols for this file, or we are looking | |
776 | for an unmangled variable. | |
777 | Try to find a matching static symbol below. */ | |
778 | } | |
779 | } | |
780 | ||
781 | #endif | |
782 | ||
783 | ALL_PSYMTABS (objfile, ps) | |
784 | { | |
785 | if (!ps->readin && lookup_partial_symbol (ps, name, 1, namespace)) | |
786 | { | |
787 | s = PSYMTAB_TO_SYMTAB(ps); | |
788 | bv = BLOCKVECTOR (s); | |
789 | block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
790 | sym = lookup_block_symbol (block, name, namespace); | |
791 | if (!sym) | |
792 | { | |
793 | /* This shouldn't be necessary, but as a last resort | |
794 | * try looking in the statics even though the psymtab | |
795 | * claimed the symbol was global. It's possible that | |
796 | * the psymtab gets it wrong in some cases. | |
797 | */ | |
798 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
799 | sym = lookup_block_symbol (block, name, namespace); | |
800 | if (!sym) | |
801 | error ("Internal: global symbol `%s' found in %s psymtab but not in symtab.\n\ | |
802 | %s may be an inlined function, or may be a template function\n\ | |
803 | (if a template, try specifying an instantiation: %s<type>).", | |
804 | name, ps->filename, name, name); | |
805 | } | |
806 | if (symtab != NULL) | |
807 | *symtab = s; | |
808 | return fixup_symbol_section (sym, objfile); | |
809 | } | |
810 | } | |
811 | ||
812 | /* Now search all static file-level symbols. | |
813 | Not strictly correct, but more useful than an error. | |
814 | Do the symtabs first, then check the psymtabs. | |
815 | If a psymtab indicates the existence | |
816 | of the desired name as a file-level static, then do psymtab-to-symtab | |
817 | conversion on the fly and return the found symbol. */ | |
818 | ||
819 | ALL_SYMTABS (objfile, s) | |
820 | { | |
821 | bv = BLOCKVECTOR (s); | |
822 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
823 | sym = lookup_block_symbol (block, name, namespace); | |
824 | if (sym) | |
825 | { | |
826 | block_found = block; | |
827 | if (symtab != NULL) | |
828 | *symtab = s; | |
829 | return fixup_symbol_section (sym, objfile); | |
830 | } | |
831 | } | |
832 | ||
833 | ALL_PSYMTABS (objfile, ps) | |
834 | { | |
835 | if (!ps->readin && lookup_partial_symbol (ps, name, 0, namespace)) | |
836 | { | |
837 | s = PSYMTAB_TO_SYMTAB(ps); | |
838 | bv = BLOCKVECTOR (s); | |
839 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
840 | sym = lookup_block_symbol (block, name, namespace); | |
841 | if (!sym) | |
842 | { | |
843 | /* This shouldn't be necessary, but as a last resort | |
844 | * try looking in the globals even though the psymtab | |
845 | * claimed the symbol was static. It's possible that | |
846 | * the psymtab gets it wrong in some cases. | |
847 | */ | |
848 | block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
849 | sym = lookup_block_symbol (block, name, namespace); | |
850 | if (!sym) | |
851 | error ("Internal: static symbol `%s' found in %s psymtab but not in symtab.\n\ | |
852 | %s may be an inlined function, or may be a template function\n\ | |
853 | (if a template, try specifying an instantiation: %s<type>).", | |
854 | name, ps->filename, name, name); | |
855 | } | |
856 | if (symtab != NULL) | |
857 | *symtab = s; | |
858 | return fixup_symbol_section (sym, objfile); | |
859 | } | |
860 | } | |
861 | ||
862 | #ifdef HPUXHPPA | |
863 | ||
864 | /* Check for the possibility of the symbol being a function or | |
865 | a global variable that is stored in one of the minimal symbol tables. | |
866 | The "minimal symbol table" is built from linker-supplied info. | |
867 | ||
868 | RT: I moved this check to last, after the complete search of | |
869 | the global (p)symtab's and static (p)symtab's. For HP-generated | |
870 | symbol tables, this check was causing a premature exit from | |
871 | lookup_symbol with NULL return, and thus messing up symbol lookups | |
872 | of things like "c::f". It seems to me a check of the minimal | |
873 | symbol table ought to be a last resort in any case. I'm vaguely | |
874 | worried about the comment below which talks about FORTRAN routines "foo_" | |
875 | though... is it saying we need to do the "minsym" check before | |
876 | the static check in this case? | |
877 | */ | |
878 | ||
879 | if (namespace == VAR_NAMESPACE) | |
880 | { | |
881 | msymbol = lookup_minimal_symbol (name, NULL, NULL); | |
882 | if (msymbol != NULL) | |
883 | { | |
884 | /* OK, we found a minimal symbol in spite of not | |
885 | * finding any symbol. There are various possible | |
886 | * explanations for this. One possibility is the symbol | |
887 | * exists in code not compiled -g. Another possibility | |
888 | * is that the 'psymtab' isn't doing its job. | |
889 | * A third possibility, related to #2, is that we were confused | |
890 | * by name-mangling. For instance, maybe the psymtab isn't | |
891 | * doing its job because it only know about demangled | |
892 | * names, but we were given a mangled name... | |
893 | */ | |
894 | ||
895 | /* We first use the address in the msymbol to try to | |
896 | * locate the appropriate symtab. Note that find_pc_symtab() | |
897 | * has a side-effect of doing psymtab-to-symtab expansion, | |
898 | * for the found symtab. | |
899 | */ | |
900 | s = find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol)); | |
901 | if (s != NULL) | |
902 | { | |
903 | bv = BLOCKVECTOR (s); | |
904 | block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
905 | sym = lookup_block_symbol (block, SYMBOL_NAME (msymbol), | |
906 | namespace); | |
907 | /* We kept static functions in minimal symbol table as well as | |
908 | in static scope. We want to find them in the symbol table. */ | |
909 | if (!sym) | |
910 | { | |
911 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
912 | sym = lookup_block_symbol (block, SYMBOL_NAME (msymbol), | |
913 | namespace); | |
914 | } | |
915 | /* If we found one, return it */ | |
916 | if (sym) { | |
917 | if (symtab != NULL) | |
918 | *symtab = s; | |
919 | return sym; | |
920 | } | |
921 | ||
922 | /* If we get here with sym == 0, the symbol was | |
923 | found in the minimal symbol table | |
924 | but not in the symtab. | |
925 | Fall through and return 0 to use the msymbol | |
926 | definition of "foo_". | |
927 | (Note that outer code generally follows up a call | |
928 | to this routine with a call to lookup_minimal_symbol(), | |
929 | so a 0 return means we'll just flow into that other routine). | |
930 | ||
931 | This happens for Fortran "foo_" symbols, | |
932 | which are "foo" in the symtab. | |
933 | ||
934 | This can also happen if "asm" is used to make a | |
935 | regular symbol but not a debugging symbol, e.g. | |
936 | asm(".globl _main"); | |
937 | asm("_main:"); | |
938 | */ | |
939 | } | |
940 | ||
941 | /* If the lookup-by-address fails, try repeating the | |
942 | * entire lookup process with the symbol name from | |
943 | * the msymbol (if different from the original symbol name). | |
944 | */ | |
945 | else if (MSYMBOL_TYPE (msymbol) != mst_text | |
946 | && MSYMBOL_TYPE (msymbol) != mst_file_text | |
947 | && !STREQ (name, SYMBOL_NAME (msymbol))) | |
948 | { | |
949 | return lookup_symbol (SYMBOL_NAME (msymbol), block, | |
950 | namespace, is_a_field_of_this, symtab); | |
951 | } | |
952 | } | |
953 | } | |
954 | ||
955 | #endif | |
956 | ||
957 | if (symtab != NULL) | |
958 | *symtab = NULL; | |
959 | return 0; | |
960 | } | |
961 | ||
962 | /* Look, in partial_symtab PST, for symbol NAME. Check the global | |
963 | symbols if GLOBAL, the static symbols if not */ | |
964 | ||
965 | static struct partial_symbol * | |
966 | lookup_partial_symbol (pst, name, global, namespace) | |
967 | struct partial_symtab *pst; | |
968 | const char *name; | |
969 | int global; | |
970 | namespace_enum namespace; | |
971 | { | |
972 | struct partial_symbol **start, **psym; | |
973 | struct partial_symbol **top, **bottom, **center; | |
974 | int length = (global ? pst->n_global_syms : pst->n_static_syms); | |
975 | int do_linear_search = 1; | |
976 | ||
977 | if (length == 0) | |
978 | { | |
979 | return (NULL); | |
980 | } | |
981 | ||
982 | start = (global ? | |
983 | pst->objfile->global_psymbols.list + pst->globals_offset : | |
984 | pst->objfile->static_psymbols.list + pst->statics_offset ); | |
985 | ||
986 | if (global) /* This means we can use a binary search. */ | |
987 | { | |
988 | do_linear_search = 0; | |
989 | ||
990 | /* Binary search. This search is guaranteed to end with center | |
991 | pointing at the earliest partial symbol with the correct | |
992 | name. At that point *all* partial symbols with that name | |
993 | will be checked against the correct namespace. */ | |
994 | ||
995 | bottom = start; | |
996 | top = start + length - 1; | |
997 | while (top > bottom) | |
998 | { | |
999 | center = bottom + (top - bottom) / 2; | |
1000 | if (!(center < top)) | |
1001 | abort (); | |
1002 | if (!do_linear_search | |
1003 | && (SYMBOL_LANGUAGE (*center) == language_cplus | |
1004 | || SYMBOL_LANGUAGE (*center) == language_java | |
1005 | )) | |
1006 | { | |
1007 | do_linear_search = 1; | |
1008 | } | |
1009 | if (STRCMP (SYMBOL_NAME (*center), name) >= 0) | |
1010 | { | |
1011 | top = center; | |
1012 | } | |
1013 | else | |
1014 | { | |
1015 | bottom = center + 1; | |
1016 | } | |
1017 | } | |
1018 | if (!(top == bottom)) | |
1019 | abort (); | |
1020 | while (STREQ (SYMBOL_NAME (*top), name)) | |
1021 | { | |
1022 | if (SYMBOL_NAMESPACE (*top) == namespace) | |
1023 | { | |
1024 | return (*top); | |
1025 | } | |
1026 | top ++; | |
1027 | } | |
1028 | } | |
1029 | ||
1030 | /* Can't use a binary search or else we found during the binary search that | |
1031 | we should also do a linear search. */ | |
1032 | ||
1033 | if (do_linear_search) | |
1034 | { | |
1035 | for (psym = start; psym < start + length; psym++) | |
1036 | { | |
1037 | if (namespace == SYMBOL_NAMESPACE (*psym)) | |
1038 | { | |
1039 | if (SYMBOL_MATCHES_NAME (*psym, name)) | |
1040 | { | |
1041 | return (*psym); | |
1042 | } | |
1043 | } | |
1044 | } | |
1045 | } | |
1046 | ||
1047 | return (NULL); | |
1048 | } | |
1049 | ||
1050 | /* Look up a type named NAME in the struct_namespace. The type returned | |
1051 | must not be opaque -- i.e., must have at least one field defined | |
1052 | ||
1053 | This code was modelled on lookup_symbol -- the parts not relevant to looking | |
1054 | up types were just left out. In particular it's assumed here that types | |
1055 | are available in struct_namespace and only at file-static or global blocks. */ | |
1056 | ||
1057 | ||
1058 | struct type * | |
1059 | lookup_transparent_type (name) | |
1060 | const char *name; | |
1061 | { | |
1062 | register struct symbol *sym; | |
1063 | register struct symtab *s = NULL; | |
1064 | register struct partial_symtab *ps; | |
1065 | struct blockvector *bv; | |
1066 | register struct objfile *objfile; | |
1067 | register struct block *block; | |
1068 | register struct minimal_symbol *msymbol; | |
1069 | ||
1070 | /* Now search all the global symbols. Do the symtab's first, then | |
1071 | check the psymtab's. If a psymtab indicates the existence | |
1072 | of the desired name as a global, then do psymtab-to-symtab | |
1073 | conversion on the fly and return the found symbol. */ | |
1074 | ||
1075 | ALL_SYMTABS (objfile, s) | |
1076 | { | |
1077 | bv = BLOCKVECTOR (s); | |
1078 | block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
1079 | sym = lookup_block_symbol (block, name, STRUCT_NAMESPACE); | |
1080 | if (sym && !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym))) | |
1081 | { | |
1082 | return SYMBOL_TYPE (sym); | |
1083 | } | |
1084 | } | |
1085 | ||
1086 | ALL_PSYMTABS (objfile, ps) | |
1087 | { | |
1088 | if (!ps->readin && lookup_partial_symbol (ps, name, 1, STRUCT_NAMESPACE)) | |
1089 | { | |
1090 | s = PSYMTAB_TO_SYMTAB(ps); | |
1091 | bv = BLOCKVECTOR (s); | |
1092 | block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
1093 | sym = lookup_block_symbol (block, name, STRUCT_NAMESPACE); | |
1094 | if (!sym) | |
1095 | { | |
1096 | /* This shouldn't be necessary, but as a last resort | |
1097 | * try looking in the statics even though the psymtab | |
1098 | * claimed the symbol was global. It's possible that | |
1099 | * the psymtab gets it wrong in some cases. | |
1100 | */ | |
1101 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
1102 | sym = lookup_block_symbol (block, name, STRUCT_NAMESPACE); | |
1103 | if (!sym) | |
1104 | error ("Internal: global symbol `%s' found in %s psymtab but not in symtab.\n\ | |
1105 | %s may be an inlined function, or may be a template function\n\ | |
1106 | (if a template, try specifying an instantiation: %s<type>).", | |
1107 | name, ps->filename, name, name); | |
1108 | } | |
1109 | if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym))) | |
1110 | return SYMBOL_TYPE (sym); | |
1111 | } | |
1112 | } | |
1113 | ||
1114 | /* Now search the static file-level symbols. | |
1115 | Not strictly correct, but more useful than an error. | |
1116 | Do the symtab's first, then | |
1117 | check the psymtab's. If a psymtab indicates the existence | |
1118 | of the desired name as a file-level static, then do psymtab-to-symtab | |
1119 | conversion on the fly and return the found symbol. | |
1120 | */ | |
1121 | ||
1122 | ALL_SYMTABS (objfile, s) | |
1123 | { | |
1124 | bv = BLOCKVECTOR (s); | |
1125 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
1126 | sym = lookup_block_symbol (block, name, STRUCT_NAMESPACE); | |
1127 | if (sym && !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym))) | |
1128 | { | |
1129 | return SYMBOL_TYPE (sym); | |
1130 | } | |
1131 | } | |
1132 | ||
1133 | ALL_PSYMTABS (objfile, ps) | |
1134 | { | |
1135 | if (!ps->readin && lookup_partial_symbol (ps, name, 0, STRUCT_NAMESPACE)) | |
1136 | { | |
1137 | s = PSYMTAB_TO_SYMTAB(ps); | |
1138 | bv = BLOCKVECTOR (s); | |
1139 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
1140 | sym = lookup_block_symbol (block, name, STRUCT_NAMESPACE); | |
1141 | if (!sym) | |
1142 | { | |
1143 | /* This shouldn't be necessary, but as a last resort | |
1144 | * try looking in the globals even though the psymtab | |
1145 | * claimed the symbol was static. It's possible that | |
1146 | * the psymtab gets it wrong in some cases. | |
1147 | */ | |
1148 | block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
1149 | sym = lookup_block_symbol (block, name, STRUCT_NAMESPACE); | |
1150 | if (!sym) | |
1151 | error ("Internal: static symbol `%s' found in %s psymtab but not in symtab.\n\ | |
1152 | %s may be an inlined function, or may be a template function\n\ | |
1153 | (if a template, try specifying an instantiation: %s<type>).", | |
1154 | name, ps->filename, name, name); | |
1155 | } | |
1156 | if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym))) | |
1157 | return SYMBOL_TYPE (sym); | |
1158 | } | |
1159 | } | |
1160 | return (struct type *) 0; | |
1161 | } | |
1162 | ||
1163 | ||
1164 | /* Find the psymtab containing main(). */ | |
1165 | /* FIXME: What about languages without main() or specially linked | |
1166 | executables that have no main() ? */ | |
1167 | ||
1168 | struct partial_symtab * | |
1169 | find_main_psymtab () | |
1170 | { | |
1171 | register struct partial_symtab *pst; | |
1172 | register struct objfile *objfile; | |
1173 | ||
1174 | ALL_PSYMTABS (objfile, pst) | |
1175 | { | |
1176 | if (lookup_partial_symbol (pst, "main", 1, VAR_NAMESPACE)) | |
1177 | { | |
1178 | return (pst); | |
1179 | } | |
1180 | } | |
1181 | return (NULL); | |
1182 | } | |
1183 | ||
1184 | /* Search BLOCK for symbol NAME in NAMESPACE. | |
1185 | ||
1186 | Note that if NAME is the demangled form of a C++ symbol, we will fail | |
1187 | to find a match during the binary search of the non-encoded names, but | |
1188 | for now we don't worry about the slight inefficiency of looking for | |
1189 | a match we'll never find, since it will go pretty quick. Once the | |
1190 | binary search terminates, we drop through and do a straight linear | |
1191 | search on the symbols. Each symbol which is marked as being a C++ | |
1192 | symbol (language_cplus set) has both the encoded and non-encoded names | |
1193 | tested for a match. */ | |
1194 | ||
1195 | struct symbol * | |
1196 | lookup_block_symbol (block, name, namespace) | |
1197 | register const struct block *block; | |
1198 | const char *name; | |
1199 | const namespace_enum namespace; | |
1200 | { | |
1201 | register int bot, top, inc; | |
1202 | register struct symbol *sym; | |
1203 | register struct symbol *sym_found = NULL; | |
1204 | register int do_linear_search = 1; | |
1205 | ||
1206 | /* If the blocks's symbols were sorted, start with a binary search. */ | |
1207 | ||
1208 | if (BLOCK_SHOULD_SORT (block)) | |
1209 | { | |
1210 | /* Reset the linear search flag so if the binary search fails, we | |
1211 | won't do the linear search once unless we find some reason to | |
1212 | do so, such as finding a C++ symbol during the binary search. | |
1213 | Note that for C++ modules, ALL the symbols in a block should | |
1214 | end up marked as C++ symbols. */ | |
1215 | ||
1216 | do_linear_search = 0; | |
1217 | top = BLOCK_NSYMS (block); | |
1218 | bot = 0; | |
1219 | ||
1220 | /* Advance BOT to not far before the first symbol whose name is NAME. */ | |
1221 | ||
1222 | while (1) | |
1223 | { | |
1224 | inc = (top - bot + 1); | |
1225 | /* No need to keep binary searching for the last few bits worth. */ | |
1226 | if (inc < 4) | |
1227 | { | |
1228 | break; | |
1229 | } | |
1230 | inc = (inc >> 1) + bot; | |
1231 | sym = BLOCK_SYM (block, inc); | |
1232 | if (!do_linear_search | |
1233 | && (SYMBOL_LANGUAGE (sym) == language_cplus | |
1234 | || SYMBOL_LANGUAGE (sym) == language_java | |
1235 | )) | |
1236 | { | |
1237 | do_linear_search = 1; | |
1238 | } | |
1239 | if (SYMBOL_NAME (sym)[0] < name[0]) | |
1240 | { | |
1241 | bot = inc; | |
1242 | } | |
1243 | else if (SYMBOL_NAME (sym)[0] > name[0]) | |
1244 | { | |
1245 | top = inc; | |
1246 | } | |
1247 | else if (STRCMP (SYMBOL_NAME (sym), name) < 0) | |
1248 | { | |
1249 | bot = inc; | |
1250 | } | |
1251 | else | |
1252 | { | |
1253 | top = inc; | |
1254 | } | |
1255 | } | |
1256 | ||
1257 | /* Now scan forward until we run out of symbols, find one whose | |
1258 | name is greater than NAME, or find one we want. If there is | |
1259 | more than one symbol with the right name and namespace, we | |
1260 | return the first one; I believe it is now impossible for us | |
1261 | to encounter two symbols with the same name and namespace | |
1262 | here, because blocks containing argument symbols are no | |
1263 | longer sorted. */ | |
1264 | ||
1265 | top = BLOCK_NSYMS (block); | |
1266 | while (bot < top) | |
1267 | { | |
1268 | sym = BLOCK_SYM (block, bot); | |
1269 | inc = SYMBOL_NAME (sym)[0] - name[0]; | |
1270 | if (inc == 0) | |
1271 | { | |
1272 | inc = STRCMP (SYMBOL_NAME (sym), name); | |
1273 | } | |
1274 | if (inc == 0 && SYMBOL_NAMESPACE (sym) == namespace) | |
1275 | { | |
1276 | return (sym); | |
1277 | } | |
1278 | if (inc > 0) | |
1279 | { | |
1280 | break; | |
1281 | } | |
1282 | bot++; | |
1283 | } | |
1284 | } | |
1285 | ||
1286 | /* Here if block isn't sorted, or we fail to find a match during the | |
1287 | binary search above. If during the binary search above, we find a | |
1288 | symbol which is a C++ symbol, then we have re-enabled the linear | |
1289 | search flag which was reset when starting the binary search. | |
1290 | ||
1291 | This loop is equivalent to the loop above, but hacked greatly for speed. | |
1292 | ||
1293 | Note that parameter symbols do not always show up last in the | |
1294 | list; this loop makes sure to take anything else other than | |
1295 | parameter symbols first; it only uses parameter symbols as a | |
1296 | last resort. Note that this only takes up extra computation | |
1297 | time on a match. */ | |
1298 | ||
1299 | if (do_linear_search) | |
1300 | { | |
1301 | top = BLOCK_NSYMS (block); | |
1302 | bot = 0; | |
1303 | while (bot < top) | |
1304 | { | |
1305 | sym = BLOCK_SYM (block, bot); | |
1306 | if (SYMBOL_NAMESPACE (sym) == namespace && | |
1307 | SYMBOL_MATCHES_NAME (sym, name)) | |
1308 | { | |
1309 | /* If SYM has aliases, then use any alias that is active | |
1310 | at the current PC. If no alias is active at the current | |
1311 | PC, then use the main symbol. | |
1312 | ||
1313 | ?!? Is checking the current pc correct? Is this routine | |
1314 | ever called to look up a symbol from another context? */ | |
1315 | if (SYMBOL_ALIASES (sym)) | |
1316 | sym = find_active_alias (sym, read_pc ()); | |
1317 | ||
1318 | sym_found = sym; | |
1319 | if (SYMBOL_CLASS (sym) != LOC_ARG && | |
1320 | SYMBOL_CLASS (sym) != LOC_LOCAL_ARG && | |
1321 | SYMBOL_CLASS (sym) != LOC_REF_ARG && | |
1322 | SYMBOL_CLASS (sym) != LOC_REGPARM && | |
1323 | SYMBOL_CLASS (sym) != LOC_REGPARM_ADDR && | |
1324 | SYMBOL_CLASS (sym) != LOC_BASEREG_ARG) | |
1325 | { | |
1326 | break; | |
1327 | } | |
1328 | } | |
1329 | bot++; | |
1330 | } | |
1331 | } | |
1332 | return (sym_found); /* Will be NULL if not found. */ | |
1333 | } | |
1334 | ||
1335 | /* Given a main symbol SYM and ADDR, search through the alias | |
1336 | list to determine if an alias is active at ADDR and return | |
1337 | the active alias. | |
1338 | ||
1339 | If no alias is active, then return SYM. */ | |
1340 | ||
1341 | static struct symbol * | |
1342 | find_active_alias (sym, addr) | |
1343 | struct symbol *sym; | |
1344 | CORE_ADDR addr; | |
1345 | { | |
1346 | struct range_list *r; | |
1347 | struct alias_list *aliases; | |
1348 | ||
1349 | /* If we have aliases, check them first. */ | |
1350 | aliases = SYMBOL_ALIASES (sym); | |
1351 | ||
1352 | while (aliases) | |
1353 | { | |
1354 | if (!SYMBOL_RANGES (aliases->sym)) | |
1355 | return aliases->sym; | |
1356 | for (r = SYMBOL_RANGES (aliases->sym); r; r = r->next) | |
1357 | { | |
1358 | if (r->start <= addr && r->end > addr) | |
1359 | return aliases->sym; | |
1360 | } | |
1361 | aliases = aliases->next; | |
1362 | } | |
1363 | ||
1364 | /* Nothing found, return the main symbol. */ | |
1365 | return sym; | |
1366 | } | |
1367 | ||
1368 | \f | |
1369 | /* Return the symbol for the function which contains a specified | |
1370 | lexical block, described by a struct block BL. */ | |
1371 | ||
1372 | struct symbol * | |
1373 | block_function (bl) | |
1374 | struct block *bl; | |
1375 | { | |
1376 | while (BLOCK_FUNCTION (bl) == 0 && BLOCK_SUPERBLOCK (bl) != 0) | |
1377 | bl = BLOCK_SUPERBLOCK (bl); | |
1378 | ||
1379 | return BLOCK_FUNCTION (bl); | |
1380 | } | |
1381 | ||
1382 | /* Find the symtab associated with PC and SECTION. Look through the | |
1383 | psymtabs and read in another symtab if necessary. */ | |
1384 | ||
1385 | struct symtab * | |
1386 | find_pc_sect_symtab (pc, section) | |
1387 | CORE_ADDR pc; | |
1388 | asection *section; | |
1389 | { | |
1390 | register struct block *b; | |
1391 | struct blockvector *bv; | |
1392 | register struct symtab *s = NULL; | |
1393 | register struct symtab *best_s = NULL; | |
1394 | register struct partial_symtab *ps; | |
1395 | register struct objfile *objfile; | |
1396 | CORE_ADDR distance = 0; | |
1397 | ||
1398 | /* Search all symtabs for the one whose file contains our address, and which | |
1399 | is the smallest of all the ones containing the address. This is designed | |
1400 | to deal with a case like symtab a is at 0x1000-0x2000 and 0x3000-0x4000 | |
1401 | and symtab b is at 0x2000-0x3000. So the GLOBAL_BLOCK for a is from | |
1402 | 0x1000-0x4000, but for address 0x2345 we want to return symtab b. | |
1403 | ||
1404 | This happens for native ecoff format, where code from included files | |
1405 | gets its own symtab. The symtab for the included file should have | |
1406 | been read in already via the dependency mechanism. | |
1407 | It might be swifter to create several symtabs with the same name | |
1408 | like xcoff does (I'm not sure). | |
1409 | ||
1410 | It also happens for objfiles that have their functions reordered. | |
1411 | For these, the symtab we are looking for is not necessarily read in. */ | |
1412 | ||
1413 | ALL_SYMTABS (objfile, s) | |
1414 | { | |
1415 | bv = BLOCKVECTOR (s); | |
1416 | b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
1417 | ||
1418 | if (BLOCK_START (b) <= pc | |
1419 | #if defined(HPUXHPPA) | |
1420 | && BLOCK_END (b) >= pc | |
1421 | #else | |
1422 | && BLOCK_END (b) > pc | |
1423 | #endif | |
1424 | && (distance == 0 | |
1425 | || BLOCK_END (b) - BLOCK_START (b) < distance)) | |
1426 | { | |
1427 | /* For an objfile that has its functions reordered, | |
1428 | find_pc_psymtab will find the proper partial symbol table | |
1429 | and we simply return its corresponding symtab. */ | |
1430 | /* In order to better support objfiles that contain both | |
1431 | stabs and coff debugging info, we continue on if a psymtab | |
1432 | can't be found. */ | |
1433 | if ((objfile->flags & OBJF_REORDERED) && objfile->psymtabs) | |
1434 | { | |
1435 | ps = find_pc_sect_psymtab (pc, section); | |
1436 | if (ps) | |
1437 | return PSYMTAB_TO_SYMTAB (ps); | |
1438 | } | |
1439 | if (section != 0) | |
1440 | { | |
1441 | int i; | |
1442 | ||
1443 | for (i = 0; i < b->nsyms; i++) | |
1444 | { | |
1445 | fixup_symbol_section (b->sym[i], objfile); | |
1446 | if (section == SYMBOL_BFD_SECTION (b->sym[i])) | |
1447 | break; | |
1448 | } | |
1449 | if (i >= b->nsyms) | |
1450 | continue; /* no symbol in this symtab matches section */ | |
1451 | } | |
1452 | distance = BLOCK_END (b) - BLOCK_START (b); | |
1453 | best_s = s; | |
1454 | } | |
1455 | } | |
1456 | ||
1457 | if (best_s != NULL) | |
1458 | return(best_s); | |
1459 | ||
1460 | s = NULL; | |
1461 | ps = find_pc_sect_psymtab (pc, section); | |
1462 | if (ps) | |
1463 | { | |
1464 | if (ps->readin) | |
1465 | /* Might want to error() here (in case symtab is corrupt and | |
1466 | will cause a core dump), but maybe we can successfully | |
1467 | continue, so let's not. */ | |
1468 | /* FIXME-32x64: assumes pc fits in a long */ | |
1469 | warning ("\ | |
1470 | (Internal error: pc 0x%lx in read in psymtab, but not in symtab.)\n", | |
1471 | (unsigned long) pc); | |
1472 | s = PSYMTAB_TO_SYMTAB (ps); | |
1473 | } | |
1474 | return (s); | |
1475 | } | |
1476 | ||
1477 | /* Find the symtab associated with PC. Look through the psymtabs and | |
1478 | read in another symtab if necessary. Backward compatibility, no section */ | |
1479 | ||
1480 | struct symtab * | |
1481 | find_pc_symtab (pc) | |
1482 | CORE_ADDR pc; | |
1483 | { | |
1484 | return find_pc_sect_symtab (pc, find_pc_mapped_section (pc)); | |
1485 | } | |
1486 | ||
1487 | \f | |
1488 | #if 0 | |
1489 | ||
1490 | /* Find the closest symbol value (of any sort -- function or variable) | |
1491 | for a given address value. Slow but complete. (currently unused, | |
1492 | mainly because it is too slow. We could fix it if each symtab and | |
1493 | psymtab had contained in it the addresses ranges of each of its | |
1494 | sections, which also would be required to make things like "info | |
1495 | line *0x2345" cause psymtabs to be converted to symtabs). */ | |
1496 | ||
1497 | struct symbol * | |
1498 | find_addr_symbol (addr, symtabp, symaddrp) | |
1499 | CORE_ADDR addr; | |
1500 | struct symtab **symtabp; | |
1501 | CORE_ADDR *symaddrp; | |
1502 | { | |
1503 | struct symtab *symtab, *best_symtab; | |
1504 | struct objfile *objfile; | |
1505 | register int bot, top; | |
1506 | register struct symbol *sym; | |
1507 | register CORE_ADDR sym_addr; | |
1508 | struct block *block; | |
1509 | int blocknum; | |
1510 | ||
1511 | /* Info on best symbol seen so far */ | |
1512 | ||
1513 | register CORE_ADDR best_sym_addr = 0; | |
1514 | struct symbol *best_sym = 0; | |
1515 | ||
1516 | /* FIXME -- we should pull in all the psymtabs, too! */ | |
1517 | ALL_SYMTABS (objfile, symtab) | |
1518 | { | |
1519 | /* Search the global and static blocks in this symtab for | |
1520 | the closest symbol-address to the desired address. */ | |
1521 | ||
1522 | for (blocknum = GLOBAL_BLOCK; blocknum <= STATIC_BLOCK; blocknum++) | |
1523 | { | |
1524 | QUIT; | |
1525 | block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), blocknum); | |
1526 | top = BLOCK_NSYMS (block); | |
1527 | for (bot = 0; bot < top; bot++) | |
1528 | { | |
1529 | sym = BLOCK_SYM (block, bot); | |
1530 | switch (SYMBOL_CLASS (sym)) | |
1531 | { | |
1532 | case LOC_STATIC: | |
1533 | case LOC_LABEL: | |
1534 | sym_addr = SYMBOL_VALUE_ADDRESS (sym); | |
1535 | break; | |
1536 | ||
1537 | case LOC_INDIRECT: | |
1538 | sym_addr = SYMBOL_VALUE_ADDRESS (sym); | |
1539 | /* An indirect symbol really lives at *sym_addr, | |
1540 | * so an indirection needs to be done. | |
1541 | * However, I am leaving this commented out because it's | |
1542 | * expensive, and it's possible that symbolization | |
1543 | * could be done without an active process (in | |
1544 | * case this read_memory will fail). RT | |
1545 | sym_addr = read_memory_unsigned_integer | |
1546 | (sym_addr, TARGET_PTR_BIT / TARGET_CHAR_BIT); | |
1547 | */ | |
1548 | break; | |
1549 | ||
1550 | case LOC_BLOCK: | |
1551 | sym_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)); | |
1552 | break; | |
1553 | ||
1554 | default: | |
1555 | continue; | |
1556 | } | |
1557 | ||
1558 | if (sym_addr <= addr) | |
1559 | if (sym_addr > best_sym_addr) | |
1560 | { | |
1561 | /* Quit if we found an exact match. */ | |
1562 | best_sym = sym; | |
1563 | best_sym_addr = sym_addr; | |
1564 | best_symtab = symtab; | |
1565 | if (sym_addr == addr) | |
1566 | goto done; | |
1567 | } | |
1568 | } | |
1569 | } | |
1570 | } | |
1571 | ||
1572 | done: | |
1573 | if (symtabp) | |
1574 | *symtabp = best_symtab; | |
1575 | if (symaddrp) | |
1576 | *symaddrp = best_sym_addr; | |
1577 | return best_sym; | |
1578 | } | |
1579 | #endif /* 0 */ | |
1580 | ||
1581 | /* Find the source file and line number for a given PC value and section. | |
1582 | Return a structure containing a symtab pointer, a line number, | |
1583 | and a pc range for the entire source line. | |
1584 | The value's .pc field is NOT the specified pc. | |
1585 | NOTCURRENT nonzero means, if specified pc is on a line boundary, | |
1586 | use the line that ends there. Otherwise, in that case, the line | |
1587 | that begins there is used. */ | |
1588 | ||
1589 | /* The big complication here is that a line may start in one file, and end just | |
1590 | before the start of another file. This usually occurs when you #include | |
1591 | code in the middle of a subroutine. To properly find the end of a line's PC | |
1592 | range, we must search all symtabs associated with this compilation unit, and | |
1593 | find the one whose first PC is closer than that of the next line in this | |
1594 | symtab. */ | |
1595 | ||
1596 | /* If it's worth the effort, we could be using a binary search. */ | |
1597 | ||
1598 | struct symtab_and_line | |
1599 | find_pc_sect_line (pc, section, notcurrent) | |
1600 | CORE_ADDR pc; | |
1601 | struct sec *section; | |
1602 | int notcurrent; | |
1603 | { | |
1604 | struct symtab *s; | |
1605 | register struct linetable *l; | |
1606 | register int len; | |
1607 | register int i; | |
1608 | register struct linetable_entry *item; | |
1609 | struct symtab_and_line val; | |
1610 | struct blockvector *bv; | |
1611 | struct minimal_symbol *msymbol; | |
1612 | struct minimal_symbol *mfunsym; | |
1613 | ||
1614 | /* Info on best line seen so far, and where it starts, and its file. */ | |
1615 | ||
1616 | struct linetable_entry *best = NULL; | |
1617 | CORE_ADDR best_end = 0; | |
1618 | struct symtab *best_symtab = 0; | |
1619 | ||
1620 | /* Store here the first line number | |
1621 | of a file which contains the line at the smallest pc after PC. | |
1622 | If we don't find a line whose range contains PC, | |
1623 | we will use a line one less than this, | |
1624 | with a range from the start of that file to the first line's pc. */ | |
1625 | struct linetable_entry *alt = NULL; | |
1626 | struct symtab *alt_symtab = 0; | |
1627 | ||
1628 | /* Info on best line seen in this file. */ | |
1629 | ||
1630 | struct linetable_entry *prev; | |
1631 | ||
1632 | /* If this pc is not from the current frame, | |
1633 | it is the address of the end of a call instruction. | |
1634 | Quite likely that is the start of the following statement. | |
1635 | But what we want is the statement containing the instruction. | |
1636 | Fudge the pc to make sure we get that. */ | |
1637 | ||
1638 | INIT_SAL (&val); /* initialize to zeroes */ | |
1639 | ||
1640 | if (notcurrent) | |
1641 | pc -= 1; | |
1642 | ||
1643 | /* elz: added this because this function returned the wrong | |
1644 | information if the pc belongs to a stub (import/export) | |
1645 | to call a shlib function. This stub would be anywhere between | |
1646 | two functions in the target, and the line info was erroneously | |
1647 | taken to be the one of the line before the pc. | |
1648 | */ | |
1649 | /* RT: Further explanation: | |
1650 | * | |
1651 | * We have stubs (trampolines) inserted between procedures. | |
1652 | * | |
1653 | * Example: "shr1" exists in a shared library, and a "shr1" stub also | |
1654 | * exists in the main image. | |
1655 | * | |
1656 | * In the minimal symbol table, we have a bunch of symbols | |
1657 | * sorted by start address. The stubs are marked as "trampoline", | |
1658 | * the others appear as text. E.g.: | |
1659 | * | |
1660 | * Minimal symbol table for main image | |
1661 | * main: code for main (text symbol) | |
1662 | * shr1: stub (trampoline symbol) | |
1663 | * foo: code for foo (text symbol) | |
1664 | * ... | |
1665 | * Minimal symbol table for "shr1" image: | |
1666 | * ... | |
1667 | * shr1: code for shr1 (text symbol) | |
1668 | * ... | |
1669 | * | |
1670 | * So the code below is trying to detect if we are in the stub | |
1671 | * ("shr1" stub), and if so, find the real code ("shr1" trampoline), | |
1672 | * and if found, do the symbolization from the real-code address | |
1673 | * rather than the stub address. | |
1674 | * | |
1675 | * Assumptions being made about the minimal symbol table: | |
1676 | * 1. lookup_minimal_symbol_by_pc() will return a trampoline only | |
1677 | * if we're really in the trampoline. If we're beyond it (say | |
1678 | * we're in "foo" in the above example), it'll have a closer | |
1679 | * symbol (the "foo" text symbol for example) and will not | |
1680 | * return the trampoline. | |
1681 | * 2. lookup_minimal_symbol_text() will find a real text symbol | |
1682 | * corresponding to the trampoline, and whose address will | |
1683 | * be different than the trampoline address. I put in a sanity | |
1684 | * check for the address being the same, to avoid an | |
1685 | * infinite recursion. | |
1686 | */ | |
1687 | msymbol = lookup_minimal_symbol_by_pc(pc); | |
1688 | if (msymbol != NULL) | |
1689 | if (MSYMBOL_TYPE (msymbol) == mst_solib_trampoline) | |
1690 | { | |
1691 | mfunsym = lookup_minimal_symbol_text (SYMBOL_NAME (msymbol), NULL, NULL); | |
1692 | if (mfunsym == NULL) | |
1693 | /* I eliminated this warning since it is coming out | |
1694 | * in the following situation: | |
1695 | * gdb shmain // test program with shared libraries | |
1696 | * (gdb) break shr1 // function in shared lib | |
1697 | * Warning: In stub for ... | |
1698 | * In the above situation, the shared lib is not loaded yet, | |
1699 | * so of course we can't find the real func/line info, | |
1700 | * but the "break" still works, and the warning is annoying. | |
1701 | * So I commented out the warning. RT */ | |
1702 | /* warning ("In stub for %s; unable to find real function/line info", SYMBOL_NAME(msymbol)) */; | |
1703 | /* fall through */ | |
1704 | else if (SYMBOL_VALUE(mfunsym) == SYMBOL_VALUE(msymbol)) | |
1705 | /* Avoid infinite recursion */ | |
1706 | /* See above comment about why warning is commented out */ | |
1707 | /* warning ("In stub for %s; unable to find real function/line info", SYMBOL_NAME(msymbol)) */; | |
1708 | /* fall through */ | |
1709 | else | |
1710 | return find_pc_line( SYMBOL_VALUE (mfunsym), 0); | |
1711 | } | |
1712 | ||
1713 | ||
1714 | s = find_pc_sect_symtab (pc, section); | |
1715 | if (!s) | |
1716 | { | |
1717 | /* if no symbol information, return previous pc */ | |
1718 | if (notcurrent) | |
1719 | pc++; | |
1720 | val.pc = pc; | |
1721 | return val; | |
1722 | } | |
1723 | ||
1724 | bv = BLOCKVECTOR (s); | |
1725 | ||
1726 | /* Look at all the symtabs that share this blockvector. | |
1727 | They all have the same apriori range, that we found was right; | |
1728 | but they have different line tables. */ | |
1729 | ||
1730 | for (; s && BLOCKVECTOR (s) == bv; s = s->next) | |
1731 | { | |
1732 | /* Find the best line in this symtab. */ | |
1733 | l = LINETABLE (s); | |
1734 | if (!l) | |
1735 | continue; | |
1736 | len = l->nitems; | |
1737 | if (len <= 0) | |
1738 | { | |
1739 | /* I think len can be zero if the symtab lacks line numbers | |
1740 | (e.g. gcc -g1). (Either that or the LINETABLE is NULL; | |
1741 | I'm not sure which, and maybe it depends on the symbol | |
1742 | reader). */ | |
1743 | continue; | |
1744 | } | |
1745 | ||
1746 | prev = NULL; | |
1747 | item = l->item; /* Get first line info */ | |
1748 | ||
1749 | /* Is this file's first line closer than the first lines of other files? | |
1750 | If so, record this file, and its first line, as best alternate. */ | |
1751 | if (item->pc > pc && (!alt || item->pc < alt->pc)) | |
1752 | { | |
1753 | alt = item; | |
1754 | alt_symtab = s; | |
1755 | } | |
1756 | ||
1757 | for (i = 0; i < len; i++, item++) | |
1758 | { | |
1759 | /* Leave prev pointing to the linetable entry for the last line | |
1760 | that started at or before PC. */ | |
1761 | if (item->pc > pc) | |
1762 | break; | |
1763 | ||
1764 | prev = item; | |
1765 | } | |
1766 | ||
1767 | /* At this point, prev points at the line whose start addr is <= pc, and | |
1768 | item points at the next line. If we ran off the end of the linetable | |
1769 | (pc >= start of the last line), then prev == item. If pc < start of | |
1770 | the first line, prev will not be set. */ | |
1771 | ||
1772 | /* Is this file's best line closer than the best in the other files? | |
1773 | If so, record this file, and its best line, as best so far. */ | |
1774 | ||
1775 | if (prev && (!best || prev->pc > best->pc)) | |
1776 | { | |
1777 | best = prev; | |
1778 | best_symtab = s; | |
1779 | /* If another line is in the linetable, and its PC is closer | |
1780 | than the best_end we currently have, take it as best_end. */ | |
1781 | if (i < len && (best_end == 0 || best_end > item->pc)) | |
1782 | best_end = item->pc; | |
1783 | } | |
1784 | } | |
1785 | ||
1786 | if (!best_symtab) | |
1787 | { | |
1788 | if (!alt_symtab) | |
1789 | { /* If we didn't find any line # info, just | |
1790 | return zeros. */ | |
1791 | val.pc = pc; | |
1792 | } | |
1793 | else | |
1794 | { | |
1795 | val.symtab = alt_symtab; | |
1796 | val.line = alt->line - 1; | |
1797 | ||
1798 | /* Don't return line 0, that means that we didn't find the line. */ | |
1799 | if (val.line == 0) ++val.line; | |
1800 | ||
1801 | val.pc = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)); | |
1802 | val.end = alt->pc; | |
1803 | } | |
1804 | } | |
1805 | else | |
1806 | { | |
1807 | val.symtab = best_symtab; | |
1808 | val.line = best->line; | |
1809 | val.pc = best->pc; | |
1810 | if (best_end && (!alt || best_end < alt->pc)) | |
1811 | val.end = best_end; | |
1812 | else if (alt) | |
1813 | val.end = alt->pc; | |
1814 | else | |
1815 | val.end = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)); | |
1816 | } | |
1817 | val.section = section; | |
1818 | return val; | |
1819 | } | |
1820 | ||
1821 | /* Backward compatibility (no section) */ | |
1822 | ||
1823 | struct symtab_and_line | |
1824 | find_pc_line (pc, notcurrent) | |
1825 | CORE_ADDR pc; | |
1826 | int notcurrent; | |
1827 | { | |
1828 | asection *section; | |
1829 | ||
1830 | section = find_pc_overlay (pc); | |
1831 | if (pc_in_unmapped_range (pc, section)) | |
1832 | pc = overlay_mapped_address (pc, section); | |
1833 | return find_pc_sect_line (pc, section, notcurrent); | |
1834 | } | |
1835 | ||
1836 | \f | |
1837 | static struct symtab* find_line_symtab PARAMS ((struct symtab *, int, | |
1838 | int *, int *)); | |
1839 | ||
1840 | /* Find line number LINE in any symtab whose name is the same as | |
1841 | SYMTAB. | |
1842 | ||
1843 | If found, return the symtab that contains the linetable in which it was | |
1844 | found, set *INDEX to the index in the linetable of the best entry | |
1845 | found, and set *EXACT_MATCH nonzero if the value returned is an | |
1846 | exact match. | |
1847 | ||
1848 | If not found, return NULL. */ | |
1849 | ||
1850 | static struct symtab* | |
1851 | find_line_symtab (symtab, line, index, exact_match) | |
1852 | struct symtab *symtab; | |
1853 | int line; | |
1854 | int *index; | |
1855 | int *exact_match; | |
1856 | { | |
1857 | int exact; | |
1858 | ||
1859 | /* BEST_INDEX and BEST_LINETABLE identify the smallest linenumber > LINE | |
1860 | so far seen. */ | |
1861 | ||
1862 | int best_index; | |
1863 | struct linetable *best_linetable; | |
1864 | struct symtab *best_symtab; | |
1865 | ||
1866 | /* First try looking it up in the given symtab. */ | |
1867 | best_linetable = LINETABLE (symtab); | |
1868 | best_symtab = symtab; | |
1869 | best_index = find_line_common (best_linetable, line, &exact); | |
1870 | if (best_index < 0 || !exact) | |
1871 | { | |
1872 | /* Didn't find an exact match. So we better keep looking for | |
1873 | another symtab with the same name. In the case of xcoff, | |
1874 | multiple csects for one source file (produced by IBM's FORTRAN | |
1875 | compiler) produce multiple symtabs (this is unavoidable | |
1876 | assuming csects can be at arbitrary places in memory and that | |
1877 | the GLOBAL_BLOCK of a symtab has a begin and end address). */ | |
1878 | ||
1879 | /* BEST is the smallest linenumber > LINE so far seen, | |
1880 | or 0 if none has been seen so far. | |
1881 | BEST_INDEX and BEST_LINETABLE identify the item for it. */ | |
1882 | int best; | |
1883 | ||
1884 | struct objfile *objfile; | |
1885 | struct symtab *s; | |
1886 | ||
1887 | if (best_index >= 0) | |
1888 | best = best_linetable->item[best_index].line; | |
1889 | else | |
1890 | best = 0; | |
1891 | ||
1892 | ALL_SYMTABS (objfile, s) | |
1893 | { | |
1894 | struct linetable *l; | |
1895 | int ind; | |
1896 | ||
1897 | if (!STREQ (symtab->filename, s->filename)) | |
1898 | continue; | |
1899 | l = LINETABLE (s); | |
1900 | ind = find_line_common (l, line, &exact); | |
1901 | if (ind >= 0) | |
1902 | { | |
1903 | if (exact) | |
1904 | { | |
1905 | best_index = ind; | |
1906 | best_linetable = l; | |
1907 | best_symtab = s; | |
1908 | goto done; | |
1909 | } | |
1910 | if (best == 0 || l->item[ind].line < best) | |
1911 | { | |
1912 | best = l->item[ind].line; | |
1913 | best_index = ind; | |
1914 | best_linetable = l; | |
1915 | best_symtab = s; | |
1916 | } | |
1917 | } | |
1918 | } | |
1919 | } | |
1920 | done: | |
1921 | if (best_index < 0) | |
1922 | return NULL; | |
1923 | ||
1924 | if (index) | |
1925 | *index = best_index; | |
1926 | if (exact_match) | |
1927 | *exact_match = exact; | |
1928 | ||
1929 | return best_symtab; | |
1930 | } | |
1931 | \f | |
1932 | /* Set the PC value for a given source file and line number and return true. | |
1933 | Returns zero for invalid line number (and sets the PC to 0). | |
1934 | The source file is specified with a struct symtab. */ | |
1935 | ||
1936 | int | |
1937 | find_line_pc (symtab, line, pc) | |
1938 | struct symtab *symtab; | |
1939 | int line; | |
1940 | CORE_ADDR *pc; | |
1941 | { | |
1942 | struct linetable *l; | |
1943 | int ind; | |
1944 | ||
1945 | *pc = 0; | |
1946 | if (symtab == 0) | |
1947 | return 0; | |
1948 | ||
1949 | symtab = find_line_symtab (symtab, line, &ind, NULL); | |
1950 | if (symtab != NULL) | |
1951 | { | |
1952 | l = LINETABLE (symtab); | |
1953 | *pc = l->item[ind].pc; | |
1954 | return 1; | |
1955 | } | |
1956 | else | |
1957 | return 0; | |
1958 | } | |
1959 | ||
1960 | /* Find the range of pc values in a line. | |
1961 | Store the starting pc of the line into *STARTPTR | |
1962 | and the ending pc (start of next line) into *ENDPTR. | |
1963 | Returns 1 to indicate success. | |
1964 | Returns 0 if could not find the specified line. */ | |
1965 | ||
1966 | int | |
1967 | find_line_pc_range (sal, startptr, endptr) | |
1968 | struct symtab_and_line sal; | |
1969 | CORE_ADDR *startptr, *endptr; | |
1970 | { | |
1971 | CORE_ADDR startaddr; | |
1972 | struct symtab_and_line found_sal; | |
1973 | ||
1974 | startaddr = sal.pc; | |
1975 | if (startaddr==0 && !find_line_pc (sal.symtab, sal.line, &startaddr)) | |
1976 | return 0; | |
1977 | ||
1978 | /* This whole function is based on address. For example, if line 10 has | |
1979 | two parts, one from 0x100 to 0x200 and one from 0x300 to 0x400, then | |
1980 | "info line *0x123" should say the line goes from 0x100 to 0x200 | |
1981 | and "info line *0x355" should say the line goes from 0x300 to 0x400. | |
1982 | This also insures that we never give a range like "starts at 0x134 | |
1983 | and ends at 0x12c". */ | |
1984 | ||
1985 | found_sal = find_pc_sect_line (startaddr, sal.section, 0); | |
1986 | if (found_sal.line != sal.line) | |
1987 | { | |
1988 | /* The specified line (sal) has zero bytes. */ | |
1989 | *startptr = found_sal.pc; | |
1990 | *endptr = found_sal.pc; | |
1991 | } | |
1992 | else | |
1993 | { | |
1994 | *startptr = found_sal.pc; | |
1995 | *endptr = found_sal.end; | |
1996 | } | |
1997 | return 1; | |
1998 | } | |
1999 | ||
2000 | /* Given a line table and a line number, return the index into the line | |
2001 | table for the pc of the nearest line whose number is >= the specified one. | |
2002 | Return -1 if none is found. The value is >= 0 if it is an index. | |
2003 | ||
2004 | Set *EXACT_MATCH nonzero if the value returned is an exact match. */ | |
2005 | ||
2006 | static int | |
2007 | find_line_common (l, lineno, exact_match) | |
2008 | register struct linetable *l; | |
2009 | register int lineno; | |
2010 | int *exact_match; | |
2011 | { | |
2012 | register int i; | |
2013 | register int len; | |
2014 | ||
2015 | /* BEST is the smallest linenumber > LINENO so far seen, | |
2016 | or 0 if none has been seen so far. | |
2017 | BEST_INDEX identifies the item for it. */ | |
2018 | ||
2019 | int best_index = -1; | |
2020 | int best = 0; | |
2021 | ||
2022 | if (lineno <= 0) | |
2023 | return -1; | |
2024 | if (l == 0) | |
2025 | return -1; | |
2026 | ||
2027 | len = l->nitems; | |
2028 | for (i = 0; i < len; i++) | |
2029 | { | |
2030 | register struct linetable_entry *item = &(l->item[i]); | |
2031 | ||
2032 | if (item->line == lineno) | |
2033 | { | |
2034 | /* Return the first (lowest address) entry which matches. */ | |
2035 | *exact_match = 1; | |
2036 | return i; | |
2037 | } | |
2038 | ||
2039 | if (item->line > lineno && (best == 0 || item->line < best)) | |
2040 | { | |
2041 | best = item->line; | |
2042 | best_index = i; | |
2043 | } | |
2044 | } | |
2045 | ||
2046 | /* If we got here, we didn't get an exact match. */ | |
2047 | ||
2048 | *exact_match = 0; | |
2049 | return best_index; | |
2050 | } | |
2051 | ||
2052 | int | |
2053 | find_pc_line_pc_range (pc, startptr, endptr) | |
2054 | CORE_ADDR pc; | |
2055 | CORE_ADDR *startptr, *endptr; | |
2056 | { | |
2057 | struct symtab_and_line sal; | |
2058 | sal = find_pc_line (pc, 0); | |
2059 | *startptr = sal.pc; | |
2060 | *endptr = sal.end; | |
2061 | return sal.symtab != 0; | |
2062 | } | |
2063 | ||
2064 | /* Given a function symbol SYM, find the symtab and line for the start | |
2065 | of the function. | |
2066 | If the argument FUNFIRSTLINE is nonzero, we want the first line | |
2067 | of real code inside the function. */ | |
2068 | ||
2069 | static struct symtab_and_line | |
2070 | find_function_start_sal PARAMS ((struct symbol *sym, int)); | |
2071 | ||
2072 | static struct symtab_and_line | |
2073 | find_function_start_sal (sym, funfirstline) | |
2074 | struct symbol *sym; | |
2075 | int funfirstline; | |
2076 | { | |
2077 | CORE_ADDR pc; | |
2078 | struct symtab_and_line sal; | |
2079 | ||
2080 | pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)); | |
2081 | fixup_symbol_section (sym, NULL); | |
2082 | if (funfirstline) | |
2083 | { /* skip "first line" of function (which is actually its prologue) */ | |
2084 | asection *section = SYMBOL_BFD_SECTION (sym); | |
2085 | /* If function is in an unmapped overlay, use its unmapped LMA | |
2086 | address, so that SKIP_PROLOGUE has something unique to work on */ | |
2087 | if (section_is_overlay (section) && | |
2088 | !section_is_mapped (section)) | |
2089 | pc = overlay_unmapped_address (pc, section); | |
2090 | ||
2091 | pc += FUNCTION_START_OFFSET; | |
2092 | SKIP_PROLOGUE (pc); | |
2093 | ||
2094 | /* For overlays, map pc back into its mapped VMA range */ | |
2095 | pc = overlay_mapped_address (pc, section); | |
2096 | } | |
2097 | sal = find_pc_sect_line (pc, SYMBOL_BFD_SECTION (sym), 0); | |
2098 | ||
2099 | #ifdef PROLOGUE_FIRSTLINE_OVERLAP | |
2100 | /* Convex: no need to suppress code on first line, if any */ | |
2101 | sal.pc = pc; | |
2102 | #else | |
2103 | /* Check if SKIP_PROLOGUE left us in mid-line, and the next | |
2104 | line is still part of the same function. */ | |
2105 | if (sal.pc != pc | |
2106 | && BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) <= sal.end | |
2107 | && sal.end < BLOCK_END (SYMBOL_BLOCK_VALUE (sym))) | |
2108 | { | |
2109 | /* First pc of next line */ | |
2110 | pc = sal.end; | |
2111 | /* Recalculate the line number (might not be N+1). */ | |
2112 | sal = find_pc_sect_line (pc, SYMBOL_BFD_SECTION (sym), 0); | |
2113 | } | |
2114 | sal.pc = pc; | |
2115 | #endif | |
2116 | ||
2117 | return sal; | |
2118 | } | |
2119 | \f | |
2120 | /* If P is of the form "operator[ \t]+..." where `...' is | |
2121 | some legitimate operator text, return a pointer to the | |
2122 | beginning of the substring of the operator text. | |
2123 | Otherwise, return "". */ | |
2124 | char * | |
2125 | operator_chars (p, end) | |
2126 | char *p; | |
2127 | char **end; | |
2128 | { | |
2129 | *end = ""; | |
2130 | if (strncmp (p, "operator", 8)) | |
2131 | return *end; | |
2132 | p += 8; | |
2133 | ||
2134 | /* Don't get faked out by `operator' being part of a longer | |
2135 | identifier. */ | |
2136 | if (isalpha(*p) || *p == '_' || *p == '$' || *p == '\0') | |
2137 | return *end; | |
2138 | ||
2139 | /* Allow some whitespace between `operator' and the operator symbol. */ | |
2140 | while (*p == ' ' || *p == '\t') | |
2141 | p++; | |
2142 | ||
2143 | /* Recognize 'operator TYPENAME'. */ | |
2144 | ||
2145 | if (isalpha(*p) || *p == '_' || *p == '$') | |
2146 | { | |
2147 | register char *q = p+1; | |
2148 | while (isalnum(*q) || *q == '_' || *q == '$') | |
2149 | q++; | |
2150 | *end = q; | |
2151 | return p; | |
2152 | } | |
2153 | ||
2154 | switch (*p) | |
2155 | { | |
2156 | case '!': | |
2157 | case '=': | |
2158 | case '*': | |
2159 | case '/': | |
2160 | case '%': | |
2161 | case '^': | |
2162 | if (p[1] == '=') | |
2163 | *end = p+2; | |
2164 | else | |
2165 | *end = p+1; | |
2166 | return p; | |
2167 | case '<': | |
2168 | case '>': | |
2169 | case '+': | |
2170 | case '-': | |
2171 | case '&': | |
2172 | case '|': | |
2173 | if (p[1] == '=' || p[1] == p[0]) | |
2174 | *end = p+2; | |
2175 | else | |
2176 | *end = p+1; | |
2177 | return p; | |
2178 | case '~': | |
2179 | case ',': | |
2180 | *end = p+1; | |
2181 | return p; | |
2182 | case '(': | |
2183 | if (p[1] != ')') | |
2184 | error ("`operator ()' must be specified without whitespace in `()'"); | |
2185 | *end = p+2; | |
2186 | return p; | |
2187 | case '?': | |
2188 | if (p[1] != ':') | |
2189 | error ("`operator ?:' must be specified without whitespace in `?:'"); | |
2190 | *end = p+2; | |
2191 | return p; | |
2192 | case '[': | |
2193 | if (p[1] != ']') | |
2194 | error ("`operator []' must be specified without whitespace in `[]'"); | |
2195 | *end = p+2; | |
2196 | return p; | |
2197 | default: | |
2198 | error ("`operator %s' not supported", p); | |
2199 | break; | |
2200 | } | |
2201 | *end = ""; | |
2202 | return *end; | |
2203 | } | |
2204 | ||
2205 | /* Return the number of methods described for TYPE, including the | |
2206 | methods from types it derives from. This can't be done in the symbol | |
2207 | reader because the type of the baseclass might still be stubbed | |
2208 | when the definition of the derived class is parsed. */ | |
2209 | ||
2210 | static int total_number_of_methods PARAMS ((struct type *type)); | |
2211 | ||
2212 | static int | |
2213 | total_number_of_methods (type) | |
2214 | struct type *type; | |
2215 | { | |
2216 | int n; | |
2217 | int count; | |
2218 | ||
2219 | CHECK_TYPEDEF (type); | |
2220 | if (TYPE_CPLUS_SPECIFIC (type) == NULL) | |
2221 | return 0; | |
2222 | count = TYPE_NFN_FIELDS_TOTAL (type); | |
2223 | ||
2224 | for (n = 0; n < TYPE_N_BASECLASSES (type); n++) | |
2225 | count += total_number_of_methods (TYPE_BASECLASS (type, n)); | |
2226 | ||
2227 | return count; | |
2228 | } | |
2229 | ||
2230 | /* Recursive helper function for decode_line_1. | |
2231 | Look for methods named NAME in type T. | |
2232 | Return number of matches. | |
2233 | Put matches in SYM_ARR, which should have been allocated with | |
2234 | a size of total_number_of_methods (T) * sizeof (struct symbol *). | |
2235 | Note that this function is g++ specific. */ | |
2236 | ||
2237 | static int | |
2238 | find_methods (t, name, sym_arr) | |
2239 | struct type *t; | |
2240 | char *name; | |
2241 | struct symbol **sym_arr; | |
2242 | { | |
2243 | int i1 = 0; | |
2244 | int ibase; | |
2245 | struct symbol *sym_class; | |
2246 | char *class_name = type_name_no_tag (t); | |
2247 | ||
2248 | /* Ignore this class if it doesn't have a name. This is ugly, but | |
2249 | unless we figure out how to get the physname without the name of | |
2250 | the class, then the loop can't do any good. */ | |
2251 | if (class_name | |
2252 | && (sym_class = lookup_symbol (class_name, | |
2253 | (struct block *)NULL, | |
2254 | STRUCT_NAMESPACE, | |
2255 | (int *)NULL, | |
2256 | (struct symtab **)NULL))) | |
2257 | { | |
2258 | int method_counter; | |
2259 | ||
2260 | /* FIXME: Shouldn't this just be CHECK_TYPEDEF (t)? */ | |
2261 | t = SYMBOL_TYPE (sym_class); | |
2262 | ||
2263 | /* Loop over each method name. At this level, all overloads of a name | |
2264 | are counted as a single name. There is an inner loop which loops over | |
2265 | each overload. */ | |
2266 | ||
2267 | for (method_counter = TYPE_NFN_FIELDS (t) - 1; | |
2268 | method_counter >= 0; | |
2269 | --method_counter) | |
2270 | { | |
2271 | int field_counter; | |
2272 | char *method_name = TYPE_FN_FIELDLIST_NAME (t, method_counter); | |
2273 | char dem_opname[64]; | |
2274 | ||
2275 | if (strncmp (method_name, "__", 2) == 0 || | |
2276 | strncmp (method_name, "op", 2) == 0 || | |
2277 | strncmp (method_name, "type", 4) == 0) | |
2278 | { | |
2279 | if (cplus_demangle_opname (method_name, dem_opname, DMGL_ANSI)) | |
2280 | method_name = dem_opname; | |
2281 | else if (cplus_demangle_opname (method_name, dem_opname, 0)) | |
2282 | method_name = dem_opname; | |
2283 | } | |
2284 | ||
2285 | if (STREQ (name, method_name)) | |
2286 | /* Find all the overloaded methods with that name. */ | |
2287 | for (field_counter = TYPE_FN_FIELDLIST_LENGTH (t, method_counter) - 1; | |
2288 | field_counter >= 0; | |
2289 | --field_counter) | |
2290 | { | |
2291 | struct fn_field *f; | |
2292 | char *phys_name; | |
2293 | ||
2294 | f = TYPE_FN_FIELDLIST1 (t, method_counter); | |
2295 | ||
2296 | if (TYPE_FN_FIELD_STUB (f, field_counter)) | |
2297 | { | |
2298 | char *tmp_name; | |
2299 | ||
2300 | tmp_name = gdb_mangle_name (t, | |
2301 | method_counter, | |
2302 | field_counter); | |
2303 | phys_name = alloca (strlen (tmp_name) + 1); | |
2304 | strcpy (phys_name, tmp_name); | |
2305 | free (tmp_name); | |
2306 | } | |
2307 | else | |
2308 | phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter); | |
2309 | ||
2310 | /* Destructor is handled by caller, dont add it to the list */ | |
2311 | if (DESTRUCTOR_PREFIX_P (phys_name)) | |
2312 | continue; | |
2313 | ||
2314 | sym_arr[i1] = lookup_symbol (phys_name, | |
2315 | NULL, VAR_NAMESPACE, | |
2316 | (int *) NULL, | |
2317 | (struct symtab **) NULL); | |
2318 | if (sym_arr[i1]) | |
2319 | i1++; | |
2320 | else | |
2321 | { | |
2322 | /* This error message gets printed, but the method | |
2323 | still seems to be found | |
2324 | fputs_filtered("(Cannot find method ", gdb_stdout); | |
2325 | fprintf_symbol_filtered (gdb_stdout, phys_name, | |
2326 | language_cplus, | |
2327 | DMGL_PARAMS | DMGL_ANSI); | |
2328 | fputs_filtered(" - possibly inlined.)\n", gdb_stdout); | |
2329 | */ | |
2330 | } | |
2331 | } | |
2332 | } | |
2333 | } | |
2334 | ||
2335 | /* Only search baseclasses if there is no match yet, since names in | |
2336 | derived classes override those in baseclasses. | |
2337 | ||
2338 | FIXME: The above is not true; it is only true of member functions | |
2339 | if they have the same number of arguments (??? - section 13.1 of the | |
2340 | ARM says the function members are not in the same scope but doesn't | |
2341 | really spell out the rules in a way I understand. In any case, if | |
2342 | the number of arguments differ this is a case in which we can overload | |
2343 | rather than hiding without any problem, and gcc 2.4.5 does overload | |
2344 | rather than hiding in this case). */ | |
2345 | ||
2346 | if (i1 == 0) | |
2347 | for (ibase = 0; ibase < TYPE_N_BASECLASSES (t); ibase++) | |
2348 | i1 += find_methods (TYPE_BASECLASS (t, ibase), name, sym_arr + i1); | |
2349 | ||
2350 | return i1; | |
2351 | } | |
2352 | ||
2353 | /* Helper function for decode_line_1. | |
2354 | Build a canonical line spec in CANONICAL if it is non-NULL and if | |
2355 | the SAL has a symtab. | |
2356 | If SYMNAME is non-NULL the canonical line spec is `filename:symname'. | |
2357 | If SYMNAME is NULL the line number from SAL is used and the canonical | |
2358 | line spec is `filename:linenum'. */ | |
2359 | ||
2360 | static void | |
2361 | build_canonical_line_spec (sal, symname, canonical) | |
2362 | struct symtab_and_line *sal; | |
2363 | char *symname; | |
2364 | char ***canonical; | |
2365 | { | |
2366 | char **canonical_arr; | |
2367 | char *canonical_name; | |
2368 | char *filename; | |
2369 | struct symtab *s = sal->symtab; | |
2370 | ||
2371 | if (s == (struct symtab *)NULL | |
2372 | || s->filename == (char *)NULL | |
2373 | || canonical == (char ***)NULL) | |
2374 | return; | |
2375 | ||
2376 | canonical_arr = (char **) xmalloc (sizeof (char *)); | |
2377 | *canonical = canonical_arr; | |
2378 | ||
2379 | filename = s->filename; | |
2380 | if (symname != NULL) | |
2381 | { | |
2382 | canonical_name = xmalloc (strlen (filename) + strlen (symname) + 2); | |
2383 | sprintf (canonical_name, "%s:%s", filename, symname); | |
2384 | } | |
2385 | else | |
2386 | { | |
2387 | canonical_name = xmalloc (strlen (filename) + 30); | |
2388 | sprintf (canonical_name, "%s:%d", filename, sal->line); | |
2389 | } | |
2390 | canonical_arr[0] = canonical_name; | |
2391 | } | |
2392 | ||
2393 | /* Parse a string that specifies a line number. | |
2394 | Pass the address of a char * variable; that variable will be | |
2395 | advanced over the characters actually parsed. | |
2396 | ||
2397 | The string can be: | |
2398 | ||
2399 | LINENUM -- that line number in current file. PC returned is 0. | |
2400 | FILE:LINENUM -- that line in that file. PC returned is 0. | |
2401 | FUNCTION -- line number of openbrace of that function. | |
2402 | PC returned is the start of the function. | |
2403 | VARIABLE -- line number of definition of that variable. | |
2404 | PC returned is 0. | |
2405 | FILE:FUNCTION -- likewise, but prefer functions in that file. | |
2406 | *EXPR -- line in which address EXPR appears. | |
2407 | ||
2408 | FUNCTION may be an undebuggable function found in minimal symbol table. | |
2409 | ||
2410 | If the argument FUNFIRSTLINE is nonzero, we want the first line | |
2411 | of real code inside a function when a function is specified, and it is | |
2412 | not OK to specify a variable or type to get its line number. | |
2413 | ||
2414 | DEFAULT_SYMTAB specifies the file to use if none is specified. | |
2415 | It defaults to current_source_symtab. | |
2416 | DEFAULT_LINE specifies the line number to use for relative | |
2417 | line numbers (that start with signs). Defaults to current_source_line. | |
2418 | If CANONICAL is non-NULL, store an array of strings containing the canonical | |
2419 | line specs there if necessary. Currently overloaded member functions and | |
2420 | line numbers or static functions without a filename yield a canonical | |
2421 | line spec. The array and the line spec strings are allocated on the heap, | |
2422 | it is the callers responsibility to free them. | |
2423 | ||
2424 | Note that it is possible to return zero for the symtab | |
2425 | if no file is validly specified. Callers must check that. | |
2426 | Also, the line number returned may be invalid. */ | |
2427 | ||
2428 | /* We allow single quotes in various places. This is a hideous | |
2429 | kludge, which exists because the completer can't yet deal with the | |
2430 | lack of single quotes. FIXME: write a linespec_completer which we | |
2431 | can use as appropriate instead of make_symbol_completion_list. */ | |
2432 | ||
2433 | struct symtabs_and_lines | |
2434 | decode_line_1 (argptr, funfirstline, default_symtab, default_line, canonical) | |
2435 | char **argptr; | |
2436 | int funfirstline; | |
2437 | struct symtab *default_symtab; | |
2438 | int default_line; | |
2439 | char ***canonical; | |
2440 | { | |
2441 | struct symtabs_and_lines values; | |
2442 | #ifdef HPPA_COMPILER_BUG | |
2443 | /* FIXME: The native HP 9000/700 compiler has a bug which appears | |
2444 | when optimizing this file with target i960-vxworks. I haven't | |
2445 | been able to construct a simple test case. The problem is that | |
2446 | in the second call to SKIP_PROLOGUE below, the compiler somehow | |
2447 | does not realize that the statement val = find_pc_line (...) will | |
2448 | change the values of the fields of val. It extracts the elements | |
2449 | into registers at the top of the block, and does not update the | |
2450 | registers after the call to find_pc_line. You can check this by | |
2451 | inserting a printf at the end of find_pc_line to show what values | |
2452 | it is returning for val.pc and val.end and another printf after | |
2453 | the call to see what values the function actually got (remember, | |
2454 | this is compiling with cc -O, with this patch removed). You can | |
2455 | also examine the assembly listing: search for the second call to | |
2456 | skip_prologue; the LDO statement before the next call to | |
2457 | find_pc_line loads the address of the structure which | |
2458 | find_pc_line will return; if there is a LDW just before the LDO, | |
2459 | which fetches an element of the structure, then the compiler | |
2460 | still has the bug. | |
2461 | ||
2462 | Setting val to volatile avoids the problem. We must undef | |
2463 | volatile, because the HPPA native compiler does not define | |
2464 | __STDC__, although it does understand volatile, and so volatile | |
2465 | will have been defined away in defs.h. */ | |
2466 | #undef volatile | |
2467 | volatile struct symtab_and_line val; | |
2468 | #define volatile /*nothing*/ | |
2469 | #else | |
2470 | struct symtab_and_line val; | |
2471 | #endif | |
2472 | register char *p, *p1; | |
2473 | char *q, *pp, *ii, *p2; | |
2474 | #if 0 | |
2475 | char *q1; | |
2476 | #endif | |
2477 | register struct symtab *s; | |
2478 | ||
2479 | register struct symbol *sym; | |
2480 | /* The symtab that SYM was found in. */ | |
2481 | struct symtab *sym_symtab; | |
2482 | ||
2483 | register CORE_ADDR pc; | |
2484 | register struct minimal_symbol *msymbol; | |
2485 | char *copy; | |
2486 | struct symbol *sym_class; | |
2487 | int i1; | |
2488 | int is_quoted; | |
2489 | int has_parens; | |
2490 | int has_if = 0; | |
2491 | struct symbol **sym_arr; | |
2492 | struct type *t; | |
2493 | char *saved_arg = *argptr; | |
2494 | extern char *gdb_completer_quote_characters; | |
2495 | ||
2496 | INIT_SAL (&val); /* initialize to zeroes */ | |
2497 | ||
2498 | /* Defaults have defaults. */ | |
2499 | ||
2500 | if (default_symtab == 0) | |
2501 | { | |
2502 | default_symtab = current_source_symtab; | |
2503 | default_line = current_source_line; | |
2504 | } | |
2505 | ||
2506 | /* See if arg is *PC */ | |
2507 | ||
2508 | if (**argptr == '*') | |
2509 | { | |
2510 | (*argptr)++; | |
2511 | pc = parse_and_eval_address_1 (argptr); | |
2512 | ||
2513 | values.sals = (struct symtab_and_line *) | |
2514 | xmalloc (sizeof (struct symtab_and_line)); | |
2515 | ||
2516 | values.nelts = 1; | |
2517 | values.sals[0] = find_pc_line (pc, 0); | |
2518 | values.sals[0].pc = pc; | |
2519 | values.sals[0].section = find_pc_overlay (pc); | |
2520 | ||
2521 | return values; | |
2522 | } | |
2523 | ||
2524 | /* 'has_if' is for the syntax: | |
2525 | * (gdb) break foo if (a==b) | |
2526 | */ | |
2527 | if ((ii = strstr(*argptr, " if ")) != NULL || | |
2528 | (ii = strstr(*argptr, "\tif ")) != NULL || | |
2529 | (ii = strstr(*argptr, " if\t")) != NULL || | |
2530 | (ii = strstr(*argptr, "\tif\t")) != NULL || | |
2531 | (ii = strstr(*argptr, " if(")) != NULL || | |
2532 | (ii = strstr(*argptr, "\tif( ")) != NULL) | |
2533 | has_if = 1; | |
2534 | /* Temporarily zap out "if (condition)" to not | |
2535 | * confuse the parenthesis-checking code below. | |
2536 | * This is undone below. Do not change ii!! | |
2537 | */ | |
2538 | if (has_if) { | |
2539 | *ii = '\0'; | |
2540 | } | |
2541 | ||
2542 | /* Set various flags. | |
2543 | * 'has_parens' is important for overload checking, where | |
2544 | * we allow things like: | |
2545 | * (gdb) break c::f(int) | |
2546 | */ | |
2547 | ||
2548 | /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */ | |
2549 | ||
2550 | is_quoted = (**argptr | |
2551 | && strchr (gdb_completer_quote_characters, **argptr) != NULL); | |
2552 | ||
2553 | has_parens = ((pp = strchr (*argptr, '(')) != NULL | |
2554 | && (pp = strchr (pp, ')')) != NULL); | |
2555 | ||
2556 | /* Now that we're safely past the has_parens check, | |
2557 | * put back " if (condition)" so outer layers can see it | |
2558 | */ | |
2559 | if (has_if) | |
2560 | *ii = ' '; | |
2561 | ||
2562 | /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */ | |
2563 | /* May also be CLASS::MEMBER, or NAMESPACE::NAME */ | |
2564 | /* Look for ':', but ignore inside of <> */ | |
2565 | ||
2566 | s = NULL; | |
2567 | for (p = *argptr; *p; p++) | |
2568 | { | |
2569 | if (p[0] == '<') | |
2570 | { | |
2571 | char * temp_end = find_template_name_end (p); | |
2572 | if (!temp_end) | |
2573 | error ("malformed template specification in command"); | |
2574 | p = temp_end; | |
2575 | } | |
2576 | if (p[0] == ':' || p[0] == ' ' || p[0] == '\t' || !*p) | |
2577 | break; | |
2578 | if (p[0] == '.' && strchr (p, ':') == NULL) /* Java qualified method. */ | |
2579 | { | |
2580 | /* Find the *last* '.', since the others are package qualifiers. */ | |
2581 | for (p1 = p; *p1; p1++) | |
2582 | { | |
2583 | if (*p1 == '.') | |
2584 | p = p1; | |
2585 | } | |
2586 | break; | |
2587 | } | |
2588 | } | |
2589 | while (p[0] == ' ' || p[0] == '\t') p++; | |
2590 | ||
2591 | if ((p[0] == ':' || p[0] == '.') && !has_parens) | |
2592 | { | |
2593 | /* C++ */ | |
2594 | /* ... or Java */ | |
2595 | if (is_quoted) *argptr = *argptr+1; | |
2596 | if (p[0] == '.' || p[1] ==':') | |
2597 | { | |
2598 | int ix; | |
2599 | char * saved_arg2 = *argptr; | |
2600 | char * temp_end; | |
2601 | /* First check for "global" namespace specification, | |
2602 | of the form "::foo". If found, skip over the colons | |
2603 | and jump to normal symbol processing */ | |
2604 | if ((*argptr == p) || (p[-1] == ' ') || (p[-1] == '\t')) | |
2605 | saved_arg2 += 2; | |
2606 | ||
2607 | /* We have what looks like a class or namespace | |
2608 | scope specification (A::B), possibly with many | |
2609 | levels of namespaces or classes (A::B::C::D). | |
2610 | ||
2611 | Some versions of the HP ANSI C++ compiler (as also possibly | |
2612 | other compilers) generate class/function/member names with | |
2613 | embedded double-colons if they are inside namespaces. To | |
2614 | handle this, we loop a few times, considering larger and | |
2615 | larger prefixes of the string as though they were single | |
2616 | symbols. So, if the initially supplied string is | |
2617 | A::B::C::D::foo, we have to look up "A", then "A::B", | |
2618 | then "A::B::C", then "A::B::C::D", and finally | |
2619 | "A::B::C::D::foo" as single, monolithic symbols, because | |
2620 | A, B, C or D may be namespaces. | |
2621 | ||
2622 | Note that namespaces can nest only inside other | |
2623 | namespaces, and not inside classes. So we need only | |
2624 | consider *prefixes* of the string; there is no need to look up | |
2625 | "B::C" separately as a symbol in the previous example. */ | |
2626 | ||
2627 | p2 = p; /* save for restart */ | |
2628 | while (1) | |
2629 | { | |
2630 | /* Extract the class name. */ | |
2631 | p1 = p; | |
2632 | while (p != *argptr && p[-1] == ' ') --p; | |
2633 | copy = (char *) alloca (p - *argptr + 1); | |
2634 | memcpy (copy, *argptr, p - *argptr); | |
2635 | copy[p - *argptr] = 0; | |
2636 | ||
2637 | /* Discard the class name from the arg. */ | |
2638 | p = p1 + (p1[0] == ':' ? 2 : 1); | |
2639 | while (*p == ' ' || *p == '\t') p++; | |
2640 | *argptr = p; | |
2641 | ||
2642 | sym_class = lookup_symbol (copy, 0, STRUCT_NAMESPACE, 0, | |
2643 | (struct symtab **)NULL); | |
2644 | ||
2645 | if (sym_class && | |
2646 | (t = check_typedef (SYMBOL_TYPE (sym_class)), | |
2647 | (TYPE_CODE (t) == TYPE_CODE_STRUCT | |
2648 | || TYPE_CODE (t) == TYPE_CODE_UNION))) | |
2649 | { | |
2650 | /* Arg token is not digits => try it as a function name | |
2651 | Find the next token(everything up to end or next blank). */ | |
2652 | if (**argptr | |
2653 | && strchr (gdb_completer_quote_characters, **argptr) != NULL) | |
2654 | { | |
2655 | p = skip_quoted(*argptr); | |
2656 | *argptr = *argptr + 1; | |
2657 | } | |
2658 | else | |
2659 | { | |
2660 | p = *argptr; | |
2661 | while (*p && *p!=' ' && *p!='\t' && *p!=',' && *p!=':') p++; | |
2662 | } | |
2663 | /* | |
2664 | q = operator_chars (*argptr, &q1); | |
2665 | if (q1 - q) | |
2666 | { | |
2667 | char *opname; | |
2668 | char *tmp = alloca (q1 - q + 1); | |
2669 | memcpy (tmp, q, q1 - q); | |
2670 | tmp[q1 - q] = '\0'; | |
2671 | opname = cplus_mangle_opname (tmp, DMGL_ANSI); | |
2672 | if (opname == NULL) | |
2673 | { | |
2674 | error_begin (); | |
2675 | printf_filtered ("no mangling for \"%s\"\n", tmp); | |
2676 | cplusplus_hint (saved_arg); | |
2677 | return_to_top_level (RETURN_ERROR); | |
2678 | } | |
2679 | copy = (char*) alloca (3 + strlen(opname)); | |
2680 | sprintf (copy, "__%s", opname); | |
2681 | p = q1; | |
2682 | } | |
2683 | else | |
2684 | */ | |
2685 | { | |
2686 | copy = (char *) alloca (p - *argptr + 1 ); | |
2687 | memcpy (copy, *argptr, p - *argptr); | |
2688 | copy[p - *argptr] = '\0'; | |
2689 | if (p != *argptr | |
2690 | && copy[p - *argptr - 1] | |
2691 | && strchr (gdb_completer_quote_characters, | |
2692 | copy[p - *argptr - 1]) != NULL) | |
2693 | copy[p - *argptr - 1] = '\0'; | |
2694 | } | |
2695 | ||
2696 | /* no line number may be specified */ | |
2697 | while (*p == ' ' || *p == '\t') p++; | |
2698 | *argptr = p; | |
2699 | ||
2700 | sym = 0; | |
2701 | i1 = 0; /* counter for the symbol array */ | |
2702 | sym_arr = (struct symbol **) alloca(total_number_of_methods (t) | |
2703 | * sizeof(struct symbol *)); | |
2704 | ||
2705 | if (destructor_name_p (copy, t)) | |
2706 | { | |
2707 | /* Destructors are a special case. */ | |
2708 | int m_index, f_index; | |
2709 | ||
2710 | if (get_destructor_fn_field (t, &m_index, &f_index)) | |
2711 | { | |
2712 | struct fn_field *f = TYPE_FN_FIELDLIST1 (t, m_index); | |
2713 | ||
2714 | sym_arr[i1] = | |
2715 | lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, f_index), | |
2716 | NULL, VAR_NAMESPACE, (int *) NULL, | |
2717 | (struct symtab **)NULL); | |
2718 | if (sym_arr[i1]) | |
2719 | i1++; | |
2720 | } | |
2721 | } | |
2722 | else | |
2723 | i1 = find_methods (t, copy, sym_arr); | |
2724 | if (i1 == 1) | |
2725 | { | |
2726 | /* There is exactly one field with that name. */ | |
2727 | sym = sym_arr[0]; | |
2728 | ||
2729 | if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK) | |
2730 | { | |
2731 | values.sals = (struct symtab_and_line *) | |
2732 | xmalloc (sizeof (struct symtab_and_line)); | |
2733 | values.nelts = 1; | |
2734 | values.sals[0] = find_function_start_sal (sym, | |
2735 | funfirstline); | |
2736 | } | |
2737 | else | |
2738 | { | |
2739 | values.nelts = 0; | |
2740 | } | |
2741 | return values; | |
2742 | } | |
2743 | if (i1 > 0) | |
2744 | { | |
2745 | /* There is more than one field with that name | |
2746 | (overloaded). Ask the user which one to use. */ | |
2747 | return decode_line_2 (sym_arr, i1, funfirstline, canonical); | |
2748 | } | |
2749 | else | |
2750 | { | |
2751 | char *tmp; | |
2752 | ||
2753 | if (OPNAME_PREFIX_P (copy)) | |
2754 | { | |
2755 | tmp = (char *)alloca (strlen (copy+3) + 9); | |
2756 | strcpy (tmp, "operator "); | |
2757 | strcat (tmp, copy+3); | |
2758 | } | |
2759 | else | |
2760 | tmp = copy; | |
2761 | error_begin (); | |
2762 | if (tmp[0] == '~') | |
2763 | printf_filtered | |
2764 | ("the class `%s' does not have destructor defined\n", | |
2765 | SYMBOL_SOURCE_NAME(sym_class)); | |
2766 | else | |
2767 | printf_filtered | |
2768 | ("the class %s does not have any method named %s\n", | |
2769 | SYMBOL_SOURCE_NAME(sym_class), tmp); | |
2770 | cplusplus_hint (saved_arg); | |
2771 | return_to_top_level (RETURN_ERROR); | |
2772 | } | |
2773 | } | |
2774 | ||
2775 | /* Move pointer up to next possible class/namespace token */ | |
2776 | p = p2 + 1; /* restart with old value +1 */ | |
2777 | /* Move pointer ahead to next double-colon */ | |
2778 | while (*p && (p[0] != ' ') && (p[0] != '\t') && (p[0] != '\'')) { | |
2779 | if (p[0] == '<') { | |
2780 | temp_end = find_template_name_end (p); | |
2781 | if (!temp_end) | |
2782 | error ("malformed template specification in command"); | |
2783 | p = temp_end; | |
2784 | } | |
2785 | else if ((p[0] == ':') && (p[1] == ':')) | |
2786 | break; /* found double-colon */ | |
2787 | else | |
2788 | p++; | |
2789 | } | |
2790 | ||
2791 | if (*p != ':') | |
2792 | break; /* out of the while (1) */ | |
2793 | ||
2794 | p2 = p; /* save restart for next time around */ | |
2795 | *argptr = saved_arg2; /* restore argptr */ | |
2796 | } /* while (1) */ | |
2797 | ||
2798 | /* Last chance attempt -- check entire name as a symbol */ | |
2799 | /* Use "copy" in preparation for jumping out of this block, | |
2800 | to be consistent with usage following the jump target */ | |
2801 | copy = (char *) alloca (p - saved_arg2 + 1); | |
2802 | memcpy (copy, saved_arg2, p - saved_arg2); | |
2803 | /* Note: if is_quoted should be true, we snuff out quote here anyway */ | |
2804 | copy[p-saved_arg2] = '\000'; | |
2805 | /* Set argptr to skip over the name */ | |
2806 | *argptr = (*p == '\'') ? p + 1 : p; | |
2807 | /* Look up entire name */ | |
2808 | sym = lookup_symbol (copy, 0, VAR_NAMESPACE, 0, &sym_symtab); | |
2809 | s = (struct symtab *) 0; | |
2810 | /* Prepare to jump: restore the " if (condition)" so outer layers see it */ | |
2811 | if (has_if) | |
2812 | *ii = ' '; | |
2813 | /* Symbol was found --> jump to normal symbol processing. | |
2814 | Code following "symbol_found" expects "copy" to have the | |
2815 | symbol name, "sym" to have the symbol pointer, "s" to be | |
2816 | a specified file's symtab, and sym_symtab to be the symbol's | |
2817 | symtab. */ | |
2818 | /* By jumping there we avoid falling through the FILE:LINE and | |
2819 | FILE:FUNC processing stuff below */ | |
2820 | if (sym) | |
2821 | goto symbol_found; | |
2822 | ||
2823 | /* Couldn't find any interpretation as classes/namespaces, so give up */ | |
2824 | error_begin (); | |
2825 | /* The quotes are important if copy is empty. */ | |
2826 | printf_filtered | |
2827 | ("Can't find member of namespace, class, struct, or union named \"%s\"\n", copy); | |
2828 | cplusplus_hint (saved_arg); | |
2829 | return_to_top_level (RETURN_ERROR); | |
2830 | } | |
2831 | /* end of C++ */ | |
2832 | ||
2833 | ||
2834 | /* Extract the file name. */ | |
2835 | p1 = p; | |
2836 | while (p != *argptr && p[-1] == ' ') --p; | |
2837 | copy = (char *) alloca (p - *argptr + 1); | |
2838 | memcpy (copy, *argptr, p - *argptr); | |
2839 | copy[p - *argptr] = 0; | |
2840 | ||
2841 | /* Find that file's data. */ | |
2842 | s = lookup_symtab (copy); | |
2843 | if (s == 0) | |
2844 | { | |
2845 | if (!have_full_symbols () && !have_partial_symbols ()) | |
2846 | error (no_symtab_msg); | |
2847 | error ("No source file named %s.", copy); | |
2848 | } | |
2849 | ||
2850 | /* Discard the file name from the arg. */ | |
2851 | p = p1 + 1; | |
2852 | while (*p == ' ' || *p == '\t') p++; | |
2853 | *argptr = p; | |
2854 | } | |
7a292a7a SS |
2855 | #if 0 |
2856 | /* No one really seems to know why this was added. It certainly | |
2857 | breaks the command line, though, whenever the passed | |
2858 | name is of the form ClassName::Method. This bit of code | |
2859 | singles out the class name, and if funfirstline is set (for | |
2860 | example, you are setting a breakpoint at this function), | |
2861 | you get an error. This did not occur with earlier | |
2862 | verions, so I am ifdef'ing this out. 3/29/99 */ | |
c906108c SS |
2863 | else { |
2864 | /* Check if what we have till now is a symbol name */ | |
2865 | ||
2866 | /* We may be looking at a template instantiation such | |
2867 | as "foo<int>". Check here whether we know about it, | |
2868 | instead of falling through to the code below which | |
2869 | handles ordinary function names, because that code | |
2870 | doesn't like seeing '<' and '>' in a name -- the | |
2871 | skip_quoted call doesn't go past them. So see if we | |
2872 | can figure it out right now. */ | |
2873 | ||
2874 | copy = (char *) alloca (p - *argptr + 1); | |
2875 | memcpy (copy, *argptr, p - *argptr); | |
2876 | copy[p - *argptr] = '\000'; | |
2877 | sym = lookup_symbol (copy, 0, VAR_NAMESPACE, 0, &sym_symtab); | |
2878 | if (sym) { | |
2879 | /* Yes, we have a symbol; jump to symbol processing */ | |
2880 | /* Code after symbol_found expects S, SYM_SYMTAB, SYM, | |
2881 | and COPY to be set correctly */ | |
2882 | if (has_if) | |
2883 | *ii = ' '; | |
2884 | *argptr = (*p == '\'') ? p + 1 : p; | |
2885 | s = (struct symtab *) 0; | |
2886 | goto symbol_found; | |
2887 | } | |
2888 | /* Otherwise fall out from here and go to file/line spec | |
2889 | processing, etc. */ | |
2890 | } | |
7a292a7a | 2891 | #endif |
c906108c SS |
2892 | |
2893 | /* S is specified file's symtab, or 0 if no file specified. | |
2894 | arg no longer contains the file name. */ | |
2895 | ||
2896 | /* Check whether arg is all digits (and sign) */ | |
2897 | ||
2898 | q = *argptr; | |
2899 | if (*q == '-' || *q == '+') q++; | |
2900 | while (*q >= '0' && *q <= '9') | |
2901 | q++; | |
2902 | ||
2903 | if (q != *argptr && (*q == 0 || *q == ' ' || *q == '\t' || *q == ',')) | |
2904 | { | |
2905 | /* We found a token consisting of all digits -- at least one digit. */ | |
2906 | enum sign {none, plus, minus} sign = none; | |
2907 | ||
2908 | /* We might need a canonical line spec if no file was specified. */ | |
2909 | int need_canonical = (s == 0) ? 1 : 0; | |
2910 | ||
2911 | /* This is where we need to make sure that we have good defaults. | |
2912 | We must guarantee that this section of code is never executed | |
2913 | when we are called with just a function name, since | |
2914 | select_source_symtab calls us with such an argument */ | |
2915 | ||
2916 | if (s == 0 && default_symtab == 0) | |
2917 | { | |
2918 | select_source_symtab (0); | |
2919 | default_symtab = current_source_symtab; | |
2920 | default_line = current_source_line; | |
2921 | } | |
2922 | ||
2923 | if (**argptr == '+') | |
2924 | sign = plus, (*argptr)++; | |
2925 | else if (**argptr == '-') | |
2926 | sign = minus, (*argptr)++; | |
2927 | val.line = atoi (*argptr); | |
2928 | switch (sign) | |
2929 | { | |
2930 | case plus: | |
2931 | if (q == *argptr) | |
2932 | val.line = 5; | |
2933 | if (s == 0) | |
2934 | val.line = default_line + val.line; | |
2935 | break; | |
2936 | case minus: | |
2937 | if (q == *argptr) | |
2938 | val.line = 15; | |
2939 | if (s == 0) | |
2940 | val.line = default_line - val.line; | |
2941 | else | |
2942 | val.line = 1; | |
2943 | break; | |
2944 | case none: | |
2945 | break; /* No need to adjust val.line. */ | |
2946 | } | |
2947 | ||
2948 | while (*q == ' ' || *q == '\t') q++; | |
2949 | *argptr = q; | |
2950 | if (s == 0) | |
2951 | s = default_symtab; | |
2952 | ||
2953 | /* It is possible that this source file has more than one symtab, | |
2954 | and that the new line number specification has moved us from the | |
2955 | default (in s) to a new one. */ | |
2956 | val.symtab = find_line_symtab (s, val.line, NULL, NULL); | |
2957 | if (val.symtab == 0) | |
2958 | val.symtab = s; | |
2959 | ||
2960 | val.pc = 0; | |
2961 | values.sals = (struct symtab_and_line *) | |
2962 | xmalloc (sizeof (struct symtab_and_line)); | |
2963 | values.sals[0] = val; | |
2964 | values.nelts = 1; | |
2965 | if (need_canonical) | |
2966 | build_canonical_line_spec (values.sals, NULL, canonical); | |
2967 | return values; | |
2968 | } | |
2969 | ||
2970 | /* Arg token is not digits => try it as a variable name | |
2971 | Find the next token (everything up to end or next whitespace). */ | |
2972 | ||
2973 | if (**argptr == '$') /* May be a convenience variable */ | |
2974 | p = skip_quoted (*argptr + (((*argptr)[1] == '$') ? 2 : 1)); /* One or two $ chars possible */ | |
2975 | else if (is_quoted) | |
2976 | { | |
2977 | p = skip_quoted (*argptr); | |
2978 | if (p[-1] != '\'') | |
2979 | error ("Unmatched single quote."); | |
2980 | } | |
2981 | else if (has_parens) | |
2982 | { | |
2983 | p = pp+1; | |
2984 | } | |
2985 | else | |
2986 | { | |
2987 | p = skip_quoted(*argptr); | |
2988 | } | |
2989 | ||
2990 | copy = (char *) alloca (p - *argptr + 1); | |
2991 | memcpy (copy, *argptr, p - *argptr); | |
2992 | copy[p - *argptr] = '\0'; | |
2993 | if (p != *argptr | |
2994 | && copy[0] | |
2995 | && copy[0] == copy [p - *argptr - 1] | |
2996 | && strchr (gdb_completer_quote_characters, copy[0]) != NULL) | |
2997 | { | |
2998 | copy [p - *argptr - 1] = '\0'; | |
2999 | copy++; | |
3000 | } | |
3001 | while (*p == ' ' || *p == '\t') p++; | |
3002 | *argptr = p; | |
3003 | ||
3004 | /* If it starts with $: may be a legitimate variable or routine name | |
3005 | (e.g. HP-UX millicode routines such as $$dyncall), or it may | |
3006 | be history value, or it may be a convenience variable */ | |
3007 | ||
3008 | if (*copy == '$') | |
3009 | { | |
3010 | value_ptr valx; | |
3011 | int index = 0; | |
3012 | int need_canonical = 0; | |
3013 | ||
3014 | p = (copy[1] == '$') ? copy + 2 : copy + 1; | |
3015 | while (*p >= '0' && *p <= '9') | |
3016 | p++; | |
3017 | if (!*p) /* reached end of token without hitting non-digit */ | |
3018 | { | |
3019 | /* We have a value history reference */ | |
3020 | sscanf ((copy[1] == '$') ? copy + 2 : copy + 1, "%d", &index); | |
3021 | valx = access_value_history ((copy[1] == '$') ? -index : index); | |
3022 | if (TYPE_CODE (VALUE_TYPE (valx)) != TYPE_CODE_INT) | |
3023 | error ("History values used in line specs must have integer values."); | |
3024 | } | |
3025 | else | |
3026 | { | |
3027 | /* Not all digits -- may be user variable/function or a | |
3028 | convenience variable */ | |
3029 | ||
3030 | /* Look up entire name as a symbol first */ | |
3031 | sym = lookup_symbol (copy, 0, VAR_NAMESPACE, 0, &sym_symtab); | |
3032 | s = (struct symtab *) 0; | |
3033 | need_canonical = 1; | |
3034 | /* Symbol was found --> jump to normal symbol processing. | |
3035 | Code following "symbol_found" expects "copy" to have the | |
3036 | symbol name, "sym" to have the symbol pointer, "s" to be | |
3037 | a specified file's symtab, and sym_symtab to be the symbol's | |
3038 | symtab. */ | |
3039 | if (sym) | |
3040 | goto symbol_found; | |
3041 | ||
3042 | /* If symbol was not found, look in minimal symbol tables */ | |
3043 | msymbol = lookup_minimal_symbol (copy, 0, 0); | |
3044 | /* Min symbol was found --> jump to minsym processing. */ | |
3045 | if (msymbol) | |
3046 | goto minimal_symbol_found; | |
3047 | ||
3048 | /* Not a user variable or function -- must be convenience variable */ | |
3049 | need_canonical = (s == 0) ? 1 : 0; | |
3050 | valx = value_of_internalvar (lookup_internalvar (copy + 1)); | |
3051 | if (TYPE_CODE (VALUE_TYPE (valx)) != TYPE_CODE_INT) | |
3052 | error ("Convenience variables used in line specs must have integer values."); | |
3053 | } | |
3054 | ||
3055 | /* Either history value or convenience value from above, in valx */ | |
3056 | val.symtab = s ? s : default_symtab; | |
3057 | val.line = value_as_long (valx); | |
3058 | val.pc = 0; | |
3059 | ||
3060 | values.sals = (struct symtab_and_line *)xmalloc (sizeof val); | |
3061 | values.sals[0] = val; | |
3062 | values.nelts = 1; | |
3063 | ||
3064 | if (need_canonical) | |
3065 | build_canonical_line_spec (values.sals, NULL, canonical); | |
3066 | ||
3067 | return values; | |
3068 | } | |
3069 | ||
3070 | ||
3071 | /* Look up that token as a variable. | |
3072 | If file specified, use that file's per-file block to start with. */ | |
3073 | ||
3074 | sym = lookup_symbol (copy, | |
3075 | (s ? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK) | |
3076 | : get_selected_block ()), | |
3077 | VAR_NAMESPACE, 0, &sym_symtab); | |
3078 | ||
3079 | symbol_found: /* We also jump here from inside the C++ class/namespace | |
3080 | code on finding a symbol of the form "A::B::C" */ | |
3081 | ||
3082 | if (sym != NULL) | |
3083 | { | |
3084 | if (SYMBOL_CLASS (sym) == LOC_BLOCK) | |
3085 | { | |
3086 | /* Arg is the name of a function */ | |
3087 | values.sals = (struct symtab_and_line *) | |
3088 | xmalloc (sizeof (struct symtab_and_line)); | |
3089 | values.sals[0] = find_function_start_sal (sym, funfirstline); | |
3090 | values.nelts = 1; | |
3091 | ||
3092 | /* Don't use the SYMBOL_LINE; if used at all it points to | |
3093 | the line containing the parameters or thereabouts, not | |
3094 | the first line of code. */ | |
3095 | ||
3096 | /* We might need a canonical line spec if it is a static | |
3097 | function. */ | |
3098 | if (s == 0) | |
3099 | { | |
3100 | struct blockvector *bv = BLOCKVECTOR (sym_symtab); | |
3101 | struct block *b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
3102 | if (lookup_block_symbol (b, copy, VAR_NAMESPACE) != NULL) | |
3103 | build_canonical_line_spec (values.sals, copy, canonical); | |
3104 | } | |
3105 | return values; | |
3106 | } | |
3107 | else | |
3108 | { | |
3109 | if (funfirstline) | |
3110 | error ("\"%s\" is not a function", copy); | |
3111 | else if (SYMBOL_LINE (sym) != 0) | |
3112 | { | |
3113 | /* We know its line number. */ | |
3114 | values.sals = (struct symtab_and_line *) | |
3115 | xmalloc (sizeof (struct symtab_and_line)); | |
3116 | values.nelts = 1; | |
3117 | memset (&values.sals[0], 0, sizeof (values.sals[0])); | |
3118 | values.sals[0].symtab = sym_symtab; | |
3119 | values.sals[0].line = SYMBOL_LINE (sym); | |
3120 | return values; | |
3121 | } | |
3122 | else | |
3123 | /* This can happen if it is compiled with a compiler which doesn't | |
3124 | put out line numbers for variables. */ | |
3125 | /* FIXME: Shouldn't we just set .line and .symtab to zero | |
3126 | and return? For example, "info line foo" could print | |
3127 | the address. */ | |
3128 | error ("Line number not known for symbol \"%s\"", copy); | |
3129 | } | |
3130 | } | |
3131 | ||
3132 | msymbol = lookup_minimal_symbol (copy, NULL, NULL); | |
3133 | ||
3134 | minimal_symbol_found: /* We also jump here from the case for variables | |
3135 | that begin with '$' */ | |
3136 | ||
3137 | if (msymbol != NULL) | |
3138 | { | |
3139 | values.sals = (struct symtab_and_line *) | |
3140 | xmalloc (sizeof (struct symtab_and_line)); | |
3141 | values.sals[0] = find_pc_sect_line ( SYMBOL_VALUE_ADDRESS (msymbol), | |
3142 | (struct sec *)0,0 ); | |
3143 | values.sals[0].section = SYMBOL_BFD_SECTION (msymbol); | |
3144 | if (funfirstline) | |
3145 | { | |
3146 | values.sals[0].pc += FUNCTION_START_OFFSET; | |
3147 | SKIP_PROLOGUE (values.sals[0].pc); | |
3148 | } | |
3149 | values.nelts = 1; | |
3150 | return values; | |
3151 | } | |
3152 | ||
3153 | if (!have_full_symbols () && | |
3154 | !have_partial_symbols () && !have_minimal_symbols ()) | |
3155 | error (no_symtab_msg); | |
3156 | ||
3157 | error ("Function \"%s\" not defined.", copy); | |
3158 | return values; /* for lint */ | |
3159 | } | |
3160 | ||
3161 | struct symtabs_and_lines | |
3162 | decode_line_spec (string, funfirstline) | |
3163 | char *string; | |
3164 | int funfirstline; | |
3165 | { | |
3166 | struct symtabs_and_lines sals; | |
3167 | if (string == 0) | |
3168 | error ("Empty line specification."); | |
3169 | sals = decode_line_1 (&string, funfirstline, | |
3170 | current_source_symtab, current_source_line, | |
3171 | (char ***)NULL); | |
3172 | if (*string) | |
3173 | error ("Junk at end of line specification: %s", string); | |
3174 | return sals; | |
3175 | } | |
3176 | ||
3177 | /* Given a list of NELTS symbols in SYM_ARR, return a list of lines to | |
3178 | operate on (ask user if necessary). | |
3179 | If CANONICAL is non-NULL return a corresponding array of mangled names | |
3180 | as canonical line specs there. */ | |
3181 | ||
3182 | static struct symtabs_and_lines | |
3183 | decode_line_2 (sym_arr, nelts, funfirstline, canonical) | |
3184 | struct symbol *sym_arr[]; | |
3185 | int nelts; | |
3186 | int funfirstline; | |
3187 | char ***canonical; | |
3188 | { | |
3189 | struct symtabs_and_lines values, return_values; | |
3190 | char *args, *arg1; | |
3191 | int i; | |
3192 | char *prompt; | |
3193 | char *symname; | |
3194 | struct cleanup *old_chain; | |
3195 | char **canonical_arr = (char **)NULL; | |
3196 | ||
3197 | values.sals = (struct symtab_and_line *) | |
3198 | alloca (nelts * sizeof(struct symtab_and_line)); | |
3199 | return_values.sals = (struct symtab_and_line *) | |
3200 | xmalloc (nelts * sizeof(struct symtab_and_line)); | |
3201 | old_chain = make_cleanup (free, return_values.sals); | |
3202 | ||
3203 | if (canonical) | |
3204 | { | |
3205 | canonical_arr = (char **) xmalloc (nelts * sizeof (char *)); | |
3206 | make_cleanup (free, canonical_arr); | |
3207 | memset (canonical_arr, 0, nelts * sizeof (char *)); | |
3208 | *canonical = canonical_arr; | |
3209 | } | |
3210 | ||
3211 | i = 0; | |
3212 | printf_unfiltered("[0] cancel\n[1] all\n"); | |
3213 | while (i < nelts) | |
3214 | { | |
3215 | INIT_SAL (&return_values.sals[i]); /* initialize to zeroes */ | |
3216 | INIT_SAL (&values.sals[i]); | |
3217 | if (sym_arr[i] && SYMBOL_CLASS (sym_arr[i]) == LOC_BLOCK) | |
3218 | { | |
3219 | values.sals[i] = find_function_start_sal (sym_arr[i], funfirstline); | |
3220 | printf_unfiltered ("[%d] %s at %s:%d\n", | |
3221 | (i+2), | |
3222 | SYMBOL_SOURCE_NAME (sym_arr[i]), | |
3223 | values.sals[i].symtab->filename, | |
3224 | values.sals[i].line); | |
3225 | } | |
3226 | else | |
3227 | printf_unfiltered ("?HERE\n"); | |
3228 | i++; | |
3229 | } | |
3230 | ||
3231 | if ((prompt = getenv ("PS2")) == NULL) | |
3232 | { | |
3233 | prompt = "> "; | |
3234 | } | |
3235 | args = command_line_input (prompt, 0, "overload-choice"); | |
3236 | ||
3237 | if (args == 0 || *args == 0) | |
3238 | error_no_arg ("one or more choice numbers"); | |
3239 | ||
3240 | i = 0; | |
3241 | while (*args) | |
3242 | { | |
3243 | int num; | |
3244 | ||
3245 | arg1 = args; | |
3246 | while (*arg1 >= '0' && *arg1 <= '9') arg1++; | |
3247 | if (*arg1 && *arg1 != ' ' && *arg1 != '\t') | |
3248 | error ("Arguments must be choice numbers."); | |
3249 | ||
3250 | num = atoi (args); | |
3251 | ||
3252 | if (num == 0) | |
3253 | error ("cancelled"); | |
3254 | else if (num == 1) | |
3255 | { | |
3256 | if (canonical_arr) | |
3257 | { | |
3258 | for (i = 0; i < nelts; i++) | |
3259 | { | |
3260 | if (canonical_arr[i] == NULL) | |
3261 | { | |
3262 | symname = SYMBOL_NAME (sym_arr[i]); | |
3263 | canonical_arr[i] = savestring (symname, strlen (symname)); | |
3264 | } | |
3265 | } | |
3266 | } | |
3267 | memcpy (return_values.sals, values.sals, | |
3268 | (nelts * sizeof(struct symtab_and_line))); | |
3269 | return_values.nelts = nelts; | |
3270 | discard_cleanups (old_chain); | |
3271 | return return_values; | |
3272 | } | |
3273 | ||
3274 | if (num >= nelts + 2) | |
3275 | { | |
3276 | printf_unfiltered ("No choice number %d.\n", num); | |
3277 | } | |
3278 | else | |
3279 | { | |
3280 | num -= 2; | |
3281 | if (values.sals[num].pc) | |
3282 | { | |
3283 | if (canonical_arr) | |
3284 | { | |
3285 | symname = SYMBOL_NAME (sym_arr[num]); | |
3286 | make_cleanup (free, symname); | |
3287 | canonical_arr[i] = savestring (symname, strlen (symname)); | |
3288 | } | |
3289 | return_values.sals[i++] = values.sals[num]; | |
3290 | values.sals[num].pc = 0; | |
3291 | } | |
3292 | else | |
3293 | { | |
3294 | printf_unfiltered ("duplicate request for %d ignored.\n", num); | |
3295 | } | |
3296 | } | |
3297 | ||
3298 | args = arg1; | |
3299 | while (*args == ' ' || *args == '\t') args++; | |
3300 | } | |
3301 | return_values.nelts = i; | |
3302 | discard_cleanups (old_chain); | |
3303 | return return_values; | |
3304 | } | |
3305 | ||
3306 | \f | |
3307 | /* Slave routine for sources_info. Force line breaks at ,'s. | |
3308 | NAME is the name to print and *FIRST is nonzero if this is the first | |
3309 | name printed. Set *FIRST to zero. */ | |
3310 | static void | |
3311 | output_source_filename (name, first) | |
3312 | char *name; | |
3313 | int *first; | |
3314 | { | |
3315 | /* Table of files printed so far. Since a single source file can | |
3316 | result in several partial symbol tables, we need to avoid printing | |
3317 | it more than once. Note: if some of the psymtabs are read in and | |
3318 | some are not, it gets printed both under "Source files for which | |
3319 | symbols have been read" and "Source files for which symbols will | |
3320 | be read in on demand". I consider this a reasonable way to deal | |
3321 | with the situation. I'm not sure whether this can also happen for | |
3322 | symtabs; it doesn't hurt to check. */ | |
3323 | static char **tab = NULL; | |
3324 | /* Allocated size of tab in elements. | |
3325 | Start with one 256-byte block (when using GNU malloc.c). | |
3326 | 24 is the malloc overhead when range checking is in effect. */ | |
3327 | static int tab_alloc_size = (256 - 24) / sizeof (char *); | |
3328 | /* Current size of tab in elements. */ | |
3329 | static int tab_cur_size; | |
3330 | ||
3331 | char **p; | |
3332 | ||
3333 | if (*first) | |
3334 | { | |
3335 | if (tab == NULL) | |
3336 | tab = (char **) xmalloc (tab_alloc_size * sizeof (*tab)); | |
3337 | tab_cur_size = 0; | |
3338 | } | |
3339 | ||
3340 | /* Is NAME in tab? */ | |
3341 | for (p = tab; p < tab + tab_cur_size; p++) | |
3342 | if (STREQ (*p, name)) | |
3343 | /* Yes; don't print it again. */ | |
3344 | return; | |
3345 | /* No; add it to tab. */ | |
3346 | if (tab_cur_size == tab_alloc_size) | |
3347 | { | |
3348 | tab_alloc_size *= 2; | |
3349 | tab = (char **) xrealloc ((char *) tab, tab_alloc_size * sizeof (*tab)); | |
3350 | } | |
3351 | tab[tab_cur_size++] = name; | |
3352 | ||
3353 | if (*first) | |
3354 | { | |
3355 | *first = 0; | |
3356 | } | |
3357 | else | |
3358 | { | |
3359 | printf_filtered (", "); | |
3360 | } | |
3361 | ||
3362 | wrap_here (""); | |
3363 | fputs_filtered (name, gdb_stdout); | |
3364 | } | |
3365 | ||
3366 | static void | |
3367 | sources_info (ignore, from_tty) | |
3368 | char *ignore; | |
3369 | int from_tty; | |
3370 | { | |
3371 | register struct symtab *s; | |
3372 | register struct partial_symtab *ps; | |
3373 | register struct objfile *objfile; | |
3374 | int first; | |
3375 | ||
3376 | if (!have_full_symbols () && !have_partial_symbols ()) | |
3377 | { | |
3378 | error (no_symtab_msg); | |
3379 | } | |
3380 | ||
3381 | printf_filtered ("Source files for which symbols have been read in:\n\n"); | |
3382 | ||
3383 | first = 1; | |
3384 | ALL_SYMTABS (objfile, s) | |
3385 | { | |
3386 | output_source_filename (s -> filename, &first); | |
3387 | } | |
3388 | printf_filtered ("\n\n"); | |
3389 | ||
3390 | printf_filtered ("Source files for which symbols will be read in on demand:\n\n"); | |
3391 | ||
3392 | first = 1; | |
3393 | ALL_PSYMTABS (objfile, ps) | |
3394 | { | |
3395 | if (!ps->readin) | |
3396 | { | |
3397 | output_source_filename (ps -> filename, &first); | |
3398 | } | |
3399 | } | |
3400 | printf_filtered ("\n"); | |
3401 | } | |
3402 | ||
3403 | static int | |
3404 | file_matches (file, files, nfiles) | |
3405 | char *file; | |
3406 | char *files[]; | |
3407 | int nfiles; | |
3408 | { | |
3409 | int i; | |
3410 | ||
3411 | if (file != NULL && nfiles != 0) | |
3412 | { | |
3413 | for (i = 0; i < nfiles; i++) | |
3414 | { | |
3415 | if (strcmp (files[i], basename (file)) == 0) | |
3416 | return 1; | |
3417 | } | |
3418 | } | |
3419 | else if (nfiles == 0) | |
3420 | return 1; | |
3421 | return 0; | |
3422 | } | |
3423 | ||
3424 | /* Free any memory associated with a search. */ | |
3425 | void | |
3426 | free_search_symbols (symbols) | |
3427 | struct symbol_search *symbols; | |
3428 | { | |
3429 | struct symbol_search *p; | |
3430 | struct symbol_search *next; | |
3431 | ||
3432 | for (p = symbols; p != NULL; p = next) | |
3433 | { | |
3434 | next = p->next; | |
3435 | free (p); | |
3436 | } | |
3437 | } | |
3438 | ||
3439 | /* Search the symbol table for matches to the regular expression REGEXP, | |
3440 | returning the results in *MATCHES. | |
3441 | ||
3442 | Only symbols of KIND are searched: | |
3443 | FUNCTIONS_NAMESPACE - search all functions | |
3444 | TYPES_NAMESPACE - search all type names | |
3445 | METHODS_NAMESPACE - search all methods NOT IMPLEMENTED | |
3446 | VARIABLES_NAMESPACE - search all symbols, excluding functions, type names, | |
3447 | and constants (enums) | |
3448 | ||
3449 | free_search_symbols should be called when *MATCHES is no longer needed. | |
3450 | */ | |
3451 | void | |
3452 | search_symbols (regexp, kind, nfiles, files, matches) | |
3453 | char *regexp; | |
3454 | namespace_enum kind; | |
3455 | int nfiles; | |
3456 | char *files[]; | |
3457 | struct symbol_search **matches; | |
3458 | ||
3459 | { | |
3460 | register struct symtab *s; | |
3461 | register struct partial_symtab *ps; | |
3462 | register struct blockvector *bv; | |
3463 | struct blockvector *prev_bv = 0; | |
3464 | register struct block *b; | |
3465 | register int i = 0; | |
3466 | register int j; | |
3467 | register struct symbol *sym; | |
3468 | struct partial_symbol **psym; | |
3469 | struct objfile *objfile; | |
3470 | struct minimal_symbol *msymbol; | |
3471 | char *val; | |
3472 | int found_misc = 0; | |
3473 | static enum minimal_symbol_type types[] | |
3474 | = {mst_data, mst_text, mst_abs, mst_unknown}; | |
3475 | static enum minimal_symbol_type types2[] | |
3476 | = {mst_bss, mst_file_text, mst_abs, mst_unknown}; | |
3477 | static enum minimal_symbol_type types3[] | |
3478 | = {mst_file_data, mst_solib_trampoline, mst_abs, mst_unknown}; | |
3479 | static enum minimal_symbol_type types4[] | |
3480 | = {mst_file_bss, mst_text, mst_abs, mst_unknown}; | |
3481 | enum minimal_symbol_type ourtype; | |
3482 | enum minimal_symbol_type ourtype2; | |
3483 | enum minimal_symbol_type ourtype3; | |
3484 | enum minimal_symbol_type ourtype4; | |
3485 | struct symbol_search *sr; | |
3486 | struct symbol_search *psr; | |
3487 | struct symbol_search *tail; | |
3488 | struct cleanup *old_chain = NULL; | |
3489 | ||
3490 | if (kind < LABEL_NAMESPACE) | |
3491 | error ("must search on specific namespace"); | |
3492 | ||
3493 | ourtype = types[(int) (kind - LABEL_NAMESPACE)]; | |
3494 | ourtype2 = types2[(int) (kind - LABEL_NAMESPACE)]; | |
3495 | ourtype3 = types3[(int) (kind - LABEL_NAMESPACE)]; | |
3496 | ourtype4 = types4[(int) (kind - LABEL_NAMESPACE)]; | |
3497 | ||
3498 | sr = *matches = NULL; | |
3499 | tail = NULL; | |
3500 | ||
3501 | if (regexp != NULL) | |
3502 | { | |
3503 | /* Make sure spacing is right for C++ operators. | |
3504 | This is just a courtesy to make the matching less sensitive | |
3505 | to how many spaces the user leaves between 'operator' | |
3506 | and <TYPENAME> or <OPERATOR>. */ | |
3507 | char *opend; | |
3508 | char *opname = operator_chars (regexp, &opend); | |
3509 | if (*opname) | |
3510 | { | |
3511 | int fix = -1; /* -1 means ok; otherwise number of spaces needed. */ | |
3512 | if (isalpha(*opname) || *opname == '_' || *opname == '$') | |
3513 | { | |
3514 | /* There should 1 space between 'operator' and 'TYPENAME'. */ | |
3515 | if (opname[-1] != ' ' || opname[-2] == ' ') | |
3516 | fix = 1; | |
3517 | } | |
3518 | else | |
3519 | { | |
3520 | /* There should 0 spaces between 'operator' and 'OPERATOR'. */ | |
3521 | if (opname[-1] == ' ') | |
3522 | fix = 0; | |
3523 | } | |
3524 | /* If wrong number of spaces, fix it. */ | |
3525 | if (fix >= 0) | |
3526 | { | |
3527 | char *tmp = (char*) alloca(opend-opname+10); | |
3528 | sprintf(tmp, "operator%.*s%s", fix, " ", opname); | |
3529 | regexp = tmp; | |
3530 | } | |
3531 | } | |
3532 | ||
3533 | if (0 != (val = re_comp (regexp))) | |
3534 | error ("Invalid regexp (%s): %s", val, regexp); | |
3535 | } | |
3536 | ||
3537 | /* Search through the partial symtabs *first* for all symbols | |
3538 | matching the regexp. That way we don't have to reproduce all of | |
3539 | the machinery below. */ | |
3540 | ||
3541 | ALL_PSYMTABS (objfile, ps) | |
3542 | { | |
3543 | struct partial_symbol **bound, **gbound, **sbound; | |
3544 | int keep_going = 1; | |
3545 | ||
3546 | if (ps->readin) continue; | |
3547 | ||
3548 | gbound = objfile->global_psymbols.list + ps->globals_offset + ps->n_global_syms; | |
3549 | sbound = objfile->static_psymbols.list + ps->statics_offset + ps->n_static_syms; | |
3550 | bound = gbound; | |
3551 | ||
3552 | /* Go through all of the symbols stored in a partial | |
3553 | symtab in one loop. */ | |
3554 | psym = objfile->global_psymbols.list + ps->globals_offset; | |
3555 | while (keep_going) | |
3556 | { | |
3557 | if (psym >= bound) | |
3558 | { | |
3559 | if (bound == gbound && ps->n_static_syms != 0) | |
3560 | { | |
3561 | psym = objfile->static_psymbols.list + ps->statics_offset; | |
3562 | bound = sbound; | |
3563 | } | |
3564 | else | |
3565 | keep_going = 0; | |
3566 | continue; | |
3567 | } | |
3568 | else | |
3569 | { | |
3570 | QUIT; | |
3571 | ||
3572 | /* If it would match (logic taken from loop below) | |
3573 | load the file and go on to the next one */ | |
3574 | if (file_matches (ps->filename, files, nfiles) | |
3575 | && ((regexp == NULL || SYMBOL_MATCHES_REGEXP (*psym)) | |
3576 | && ((kind == VARIABLES_NAMESPACE && SYMBOL_CLASS (*psym) != LOC_TYPEDEF | |
3577 | && SYMBOL_CLASS (*psym) != LOC_BLOCK) | |
3578 | || (kind == FUNCTIONS_NAMESPACE && SYMBOL_CLASS (*psym) == LOC_BLOCK) | |
3579 | || (kind == TYPES_NAMESPACE && SYMBOL_CLASS (*psym) == LOC_TYPEDEF) | |
3580 | || (kind == METHODS_NAMESPACE && SYMBOL_CLASS (*psym) == LOC_BLOCK)))) | |
3581 | { | |
3582 | PSYMTAB_TO_SYMTAB(ps); | |
3583 | keep_going = 0; | |
3584 | } | |
3585 | } | |
3586 | psym++; | |
3587 | } | |
3588 | } | |
3589 | ||
3590 | /* Here, we search through the minimal symbol tables for functions | |
3591 | and variables that match, and force their symbols to be read. | |
3592 | This is in particular necessary for demangled variable names, | |
3593 | which are no longer put into the partial symbol tables. | |
3594 | The symbol will then be found during the scan of symtabs below. | |
3595 | ||
3596 | For functions, find_pc_symtab should succeed if we have debug info | |
3597 | for the function, for variables we have to call lookup_symbol | |
3598 | to determine if the variable has debug info. | |
3599 | If the lookup fails, set found_misc so that we will rescan to print | |
3600 | any matching symbols without debug info. | |
3601 | */ | |
3602 | ||
3603 | if (nfiles == 0 && (kind == VARIABLES_NAMESPACE || kind == FUNCTIONS_NAMESPACE)) | |
3604 | { | |
3605 | ALL_MSYMBOLS (objfile, msymbol) | |
3606 | { | |
3607 | if (MSYMBOL_TYPE (msymbol) == ourtype || | |
3608 | MSYMBOL_TYPE (msymbol) == ourtype2 || | |
3609 | MSYMBOL_TYPE (msymbol) == ourtype3 || | |
3610 | MSYMBOL_TYPE (msymbol) == ourtype4) | |
3611 | { | |
3612 | if (regexp == NULL || SYMBOL_MATCHES_REGEXP (msymbol)) | |
3613 | { | |
3614 | if (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol))) | |
3615 | { | |
3616 | if (kind == FUNCTIONS_NAMESPACE | |
3617 | || lookup_symbol (SYMBOL_NAME (msymbol), | |
3618 | (struct block *) NULL, | |
3619 | VAR_NAMESPACE, | |
3620 | 0, (struct symtab **) NULL) == NULL) | |
3621 | found_misc = 1; | |
3622 | } | |
3623 | } | |
3624 | } | |
3625 | } | |
3626 | } | |
3627 | ||
3628 | ALL_SYMTABS (objfile, s) | |
3629 | { | |
3630 | bv = BLOCKVECTOR (s); | |
3631 | /* Often many files share a blockvector. | |
3632 | Scan each blockvector only once so that | |
3633 | we don't get every symbol many times. | |
3634 | It happens that the first symtab in the list | |
3635 | for any given blockvector is the main file. */ | |
3636 | if (bv != prev_bv) | |
3637 | for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++) | |
3638 | { | |
3639 | b = BLOCKVECTOR_BLOCK (bv, i); | |
3640 | /* Skip the sort if this block is always sorted. */ | |
3641 | if (!BLOCK_SHOULD_SORT (b)) | |
3642 | sort_block_syms (b); | |
3643 | for (j = 0; j < BLOCK_NSYMS (b); j++) | |
3644 | { | |
3645 | QUIT; | |
3646 | sym = BLOCK_SYM (b, j); | |
3647 | if (file_matches (s->filename, files, nfiles) | |
3648 | && ((regexp == NULL || SYMBOL_MATCHES_REGEXP (sym)) | |
3649 | && ((kind == VARIABLES_NAMESPACE && SYMBOL_CLASS (sym) != LOC_TYPEDEF | |
3650 | && SYMBOL_CLASS (sym) != LOC_BLOCK | |
3651 | && SYMBOL_CLASS (sym) != LOC_CONST) | |
3652 | || (kind == FUNCTIONS_NAMESPACE && SYMBOL_CLASS (sym) == LOC_BLOCK) | |
3653 | || (kind == TYPES_NAMESPACE && SYMBOL_CLASS (sym) == LOC_TYPEDEF) | |
3654 | || (kind == METHODS_NAMESPACE && SYMBOL_CLASS (sym) == LOC_BLOCK)))) | |
3655 | { | |
3656 | /* match */ | |
3657 | psr = (struct symbol_search *) xmalloc (sizeof (struct symbol_search)); | |
3658 | psr->block = i; | |
3659 | psr->symtab = s; | |
3660 | psr->symbol = sym; | |
3661 | psr->msymbol = NULL; | |
3662 | psr->next = NULL; | |
3663 | if (tail == NULL) | |
3664 | { | |
3665 | sr = psr; | |
3666 | old_chain = make_cleanup ((make_cleanup_func) | |
3667 | free_search_symbols, sr); | |
3668 | } | |
3669 | else | |
3670 | tail->next = psr; | |
3671 | tail = psr; | |
3672 | } | |
3673 | } | |
3674 | } | |
3675 | prev_bv = bv; | |
3676 | } | |
3677 | ||
3678 | /* If there are no eyes, avoid all contact. I mean, if there are | |
3679 | no debug symbols, then print directly from the msymbol_vector. */ | |
3680 | ||
3681 | if (found_misc || kind != FUNCTIONS_NAMESPACE) | |
3682 | { | |
3683 | ALL_MSYMBOLS (objfile, msymbol) | |
3684 | { | |
3685 | if (MSYMBOL_TYPE (msymbol) == ourtype || | |
3686 | MSYMBOL_TYPE (msymbol) == ourtype2 || | |
3687 | MSYMBOL_TYPE (msymbol) == ourtype3 || | |
3688 | MSYMBOL_TYPE (msymbol) == ourtype4) | |
3689 | { | |
3690 | if (regexp == NULL || SYMBOL_MATCHES_REGEXP (msymbol)) | |
3691 | { | |
3692 | /* Functions: Look up by address. */ | |
3693 | if (kind != FUNCTIONS_NAMESPACE || | |
3694 | (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol)))) | |
3695 | { | |
3696 | /* Variables/Absolutes: Look up by name */ | |
3697 | if (lookup_symbol (SYMBOL_NAME (msymbol), | |
3698 | (struct block *) NULL, VAR_NAMESPACE, | |
3699 | 0, (struct symtab **) NULL) == NULL) | |
3700 | { | |
3701 | /* match */ | |
3702 | psr = (struct symbol_search *) xmalloc (sizeof (struct symbol_search)); | |
3703 | psr->block = i; | |
3704 | psr->msymbol = msymbol; | |
3705 | psr->symtab = NULL; | |
3706 | psr->symbol = NULL; | |
3707 | psr->next = NULL; | |
3708 | if (tail == NULL) | |
3709 | { | |
3710 | sr = psr; | |
3711 | old_chain = make_cleanup ((make_cleanup_func) | |
3712 | free_search_symbols, &sr); | |
3713 | } | |
3714 | else | |
3715 | tail->next = psr; | |
3716 | tail = psr; | |
3717 | } | |
3718 | } | |
3719 | } | |
3720 | } | |
3721 | } | |
3722 | } | |
3723 | ||
3724 | *matches = sr; | |
3725 | if (sr != NULL) | |
3726 | discard_cleanups (old_chain); | |
3727 | } | |
3728 | ||
3729 | /* Helper function for symtab_symbol_info, this function uses | |
3730 | the data returned from search_symbols() to print information | |
3731 | regarding the match to gdb_stdout. | |
3732 | */ | |
3733 | static void | |
3734 | print_symbol_info (kind, s, sym, block, last) | |
3735 | namespace_enum kind; | |
3736 | struct symtab *s; | |
3737 | struct symbol *sym; | |
3738 | int block; | |
3739 | char *last; | |
3740 | { | |
3741 | if (last == NULL || strcmp (last, s->filename) != 0) | |
3742 | { | |
3743 | fputs_filtered ("\nFile ", gdb_stdout); | |
3744 | fputs_filtered (s->filename, gdb_stdout); | |
3745 | fputs_filtered (":\n", gdb_stdout); | |
3746 | } | |
3747 | ||
3748 | if (kind != TYPES_NAMESPACE && block == STATIC_BLOCK) | |
3749 | printf_filtered ("static "); | |
3750 | ||
3751 | /* Typedef that is not a C++ class */ | |
3752 | if (kind == TYPES_NAMESPACE | |
3753 | && SYMBOL_NAMESPACE (sym) != STRUCT_NAMESPACE) | |
3754 | c_typedef_print (SYMBOL_TYPE(sym), sym, gdb_stdout); | |
3755 | /* variable, func, or typedef-that-is-c++-class */ | |
3756 | else if (kind < TYPES_NAMESPACE || | |
3757 | (kind == TYPES_NAMESPACE && | |
3758 | SYMBOL_NAMESPACE(sym) == STRUCT_NAMESPACE)) | |
3759 | { | |
3760 | type_print (SYMBOL_TYPE (sym), | |
3761 | (SYMBOL_CLASS (sym) == LOC_TYPEDEF | |
3762 | ? "" : SYMBOL_SOURCE_NAME (sym)), | |
3763 | gdb_stdout, 0); | |
3764 | ||
3765 | printf_filtered (";\n"); | |
3766 | } | |
3767 | else | |
3768 | { | |
3769 | # if 0 | |
3770 | /* Tiemann says: "info methods was never implemented." */ | |
3771 | char *demangled_name; | |
3772 | c_type_print_base (TYPE_FN_FIELD_TYPE(t, block), | |
3773 | gdb_stdout, 0, 0); | |
3774 | c_type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t, block), | |
3775 | gdb_stdout, 0); | |
3776 | if (TYPE_FN_FIELD_STUB (t, block)) | |
3777 | check_stub_method (TYPE_DOMAIN_TYPE (type), j, block); | |
3778 | demangled_name = | |
3779 | cplus_demangle (TYPE_FN_FIELD_PHYSNAME (t, block), | |
3780 | DMGL_ANSI | DMGL_PARAMS); | |
3781 | if (demangled_name == NULL) | |
3782 | fprintf_filtered (stream, "<badly mangled name %s>", | |
3783 | TYPE_FN_FIELD_PHYSNAME (t, block)); | |
3784 | else | |
3785 | { | |
3786 | fputs_filtered (demangled_name, stream); | |
3787 | free (demangled_name); | |
3788 | } | |
3789 | # endif | |
3790 | } | |
3791 | } | |
3792 | ||
3793 | /* This help function for symtab_symbol_info() prints information | |
3794 | for non-debugging symbols to gdb_stdout. | |
3795 | */ | |
3796 | static void | |
3797 | print_msymbol_info (msymbol) | |
3798 | struct minimal_symbol *msymbol; | |
3799 | { | |
3800 | printf_filtered (" %08lx %s\n", | |
3801 | (unsigned long) SYMBOL_VALUE_ADDRESS (msymbol), | |
3802 | SYMBOL_SOURCE_NAME (msymbol)); | |
3803 | } | |
3804 | ||
3805 | /* This is the guts of the commands "info functions", "info types", and | |
3806 | "info variables". It calls search_symbols to find all matches and then | |
3807 | print_[m]symbol_info to print out some useful information about the | |
3808 | matches. | |
3809 | */ | |
3810 | static void | |
3811 | symtab_symbol_info (regexp, kind, from_tty) | |
3812 | char *regexp; | |
3813 | namespace_enum kind; | |
3814 | int from_tty; | |
3815 | { | |
3816 | static char *classnames[] | |
3817 | = {"variable", "function", "type", "method"}; | |
3818 | struct symbol_search *symbols; | |
3819 | struct symbol_search *p; | |
3820 | struct cleanup *old_chain; | |
3821 | char *last_filename = NULL; | |
3822 | int first = 1; | |
3823 | ||
3824 | /* must make sure that if we're interrupted, symbols gets freed */ | |
3825 | search_symbols (regexp, kind, 0, (char **) NULL, &symbols); | |
3826 | old_chain = make_cleanup ((make_cleanup_func) free_search_symbols, symbols); | |
3827 | ||
3828 | printf_filtered (regexp | |
3829 | ? "All %ss matching regular expression \"%s\":\n" | |
3830 | : "All defined %ss:\n", | |
3831 | classnames[(int) (kind - LABEL_NAMESPACE - 1)], regexp); | |
3832 | ||
3833 | for (p = symbols; p != NULL; p = p->next) | |
3834 | { | |
3835 | QUIT; | |
3836 | ||
3837 | if (p->msymbol != NULL) | |
3838 | { | |
3839 | if (first) | |
3840 | { | |
3841 | printf_filtered ("\nNon-debugging symbols:\n"); | |
3842 | first = 0; | |
3843 | } | |
3844 | print_msymbol_info (p->msymbol); | |
3845 | } | |
3846 | else | |
3847 | { | |
3848 | print_symbol_info (kind, | |
3849 | p->symtab, | |
3850 | p->symbol, | |
3851 | p->block, | |
3852 | last_filename); | |
3853 | last_filename = p->symtab->filename; | |
3854 | } | |
3855 | } | |
3856 | ||
3857 | do_cleanups (old_chain); | |
3858 | } | |
3859 | ||
3860 | static void | |
3861 | variables_info (regexp, from_tty) | |
3862 | char *regexp; | |
3863 | int from_tty; | |
3864 | { | |
3865 | symtab_symbol_info (regexp, VARIABLES_NAMESPACE, from_tty); | |
3866 | } | |
3867 | ||
3868 | static void | |
3869 | functions_info (regexp, from_tty) | |
3870 | char *regexp; | |
3871 | int from_tty; | |
3872 | { | |
3873 | symtab_symbol_info (regexp, FUNCTIONS_NAMESPACE, from_tty); | |
3874 | } | |
3875 | ||
3876 | static void | |
3877 | types_info (regexp, from_tty) | |
3878 | char *regexp; | |
3879 | int from_tty; | |
3880 | { | |
3881 | symtab_symbol_info (regexp, TYPES_NAMESPACE, from_tty); | |
3882 | } | |
3883 | ||
3884 | #if 0 | |
3885 | /* Tiemann says: "info methods was never implemented." */ | |
3886 | static void | |
3887 | methods_info (regexp) | |
3888 | char *regexp; | |
3889 | { | |
3890 | symtab_symbol_info (regexp, METHODS_NAMESPACE, 0, from_tty); | |
3891 | } | |
3892 | #endif /* 0 */ | |
3893 | ||
3894 | /* Breakpoint all functions matching regular expression. */ | |
3895 | static void | |
3896 | rbreak_command (regexp, from_tty) | |
3897 | char *regexp; | |
3898 | int from_tty; | |
3899 | { | |
3900 | struct symbol_search *ss; | |
3901 | struct symbol_search *p; | |
3902 | struct cleanup *old_chain; | |
3903 | ||
3904 | search_symbols (regexp, FUNCTIONS_NAMESPACE, 0, (char **) NULL, &ss); | |
3905 | old_chain = make_cleanup ((make_cleanup_func) free_search_symbols, ss); | |
3906 | ||
3907 | for (p = ss; p != NULL; p = p->next) | |
3908 | { | |
3909 | if (p->msymbol == NULL) | |
3910 | { | |
3911 | char *string = (char *) alloca (strlen (p->symtab->filename) | |
3912 | + strlen (SYMBOL_NAME (p->symbol)) | |
3913 | + 4); | |
3914 | strcpy (string, p->symtab->filename); | |
3915 | strcat (string, ":'"); | |
3916 | strcat (string, SYMBOL_NAME (p->symbol)); | |
3917 | strcat (string, "'"); | |
3918 | break_command (string, from_tty); | |
3919 | print_symbol_info (FUNCTIONS_NAMESPACE, | |
3920 | p->symtab, | |
3921 | p->symbol, | |
3922 | p->block, | |
3923 | p->symtab->filename); | |
3924 | } | |
3925 | else | |
3926 | { | |
3927 | break_command (SYMBOL_NAME (p->msymbol), from_tty); | |
3928 | printf_filtered ("<function, no debug info> %s;\n", | |
3929 | SYMBOL_SOURCE_NAME (p->msymbol)); | |
3930 | } | |
3931 | } | |
3932 | ||
3933 | do_cleanups (old_chain); | |
3934 | } | |
3935 | ||
3936 | \f | |
3937 | /* Return Nonzero if block a is lexically nested within block b, | |
3938 | or if a and b have the same pc range. | |
3939 | Return zero otherwise. */ | |
3940 | int | |
3941 | contained_in (a, b) | |
3942 | struct block *a, *b; | |
3943 | { | |
3944 | if (!a || !b) | |
3945 | return 0; | |
3946 | return BLOCK_START (a) >= BLOCK_START (b) | |
3947 | && BLOCK_END (a) <= BLOCK_END (b); | |
3948 | } | |
3949 | ||
3950 | \f | |
3951 | /* Helper routine for make_symbol_completion_list. */ | |
3952 | ||
3953 | static int return_val_size; | |
3954 | static int return_val_index; | |
3955 | static char **return_val; | |
3956 | ||
3957 | #define COMPLETION_LIST_ADD_SYMBOL(symbol, sym_text, len, text, word) \ | |
3958 | do { \ | |
3959 | if (SYMBOL_DEMANGLED_NAME (symbol) != NULL) \ | |
3960 | /* Put only the mangled name on the list. */ \ | |
3961 | /* Advantage: "b foo<TAB>" completes to "b foo(int, int)" */ \ | |
3962 | /* Disadvantage: "b foo__i<TAB>" doesn't complete. */ \ | |
3963 | completion_list_add_name \ | |
3964 | (SYMBOL_DEMANGLED_NAME (symbol), (sym_text), (len), (text), (word)); \ | |
3965 | else \ | |
3966 | completion_list_add_name \ | |
3967 | (SYMBOL_NAME (symbol), (sym_text), (len), (text), (word)); \ | |
3968 | } while (0) | |
3969 | ||
3970 | /* Test to see if the symbol specified by SYMNAME (which is already | |
3971 | demangled for C++ symbols) matches SYM_TEXT in the first SYM_TEXT_LEN | |
3972 | characters. If so, add it to the current completion list. */ | |
3973 | ||
3974 | static void | |
3975 | completion_list_add_name (symname, sym_text, sym_text_len, text, word) | |
3976 | char *symname; | |
3977 | char *sym_text; | |
3978 | int sym_text_len; | |
3979 | char *text; | |
3980 | char *word; | |
3981 | { | |
3982 | int newsize; | |
3983 | int i; | |
3984 | ||
3985 | /* clip symbols that cannot match */ | |
3986 | ||
3987 | if (strncmp (symname, sym_text, sym_text_len) != 0) | |
3988 | { | |
3989 | return; | |
3990 | } | |
3991 | ||
3992 | /* Clip any symbol names that we've already considered. (This is a | |
3993 | time optimization) */ | |
3994 | ||
3995 | for (i = 0; i < return_val_index; ++i) | |
3996 | { | |
3997 | if (STREQ (symname, return_val[i])) | |
3998 | { | |
3999 | return; | |
4000 | } | |
4001 | } | |
4002 | ||
4003 | /* We have a match for a completion, so add SYMNAME to the current list | |
4004 | of matches. Note that the name is moved to freshly malloc'd space. */ | |
4005 | ||
4006 | { | |
4007 | char *new; | |
4008 | if (word == sym_text) | |
4009 | { | |
4010 | new = xmalloc (strlen (symname) + 5); | |
4011 | strcpy (new, symname); | |
4012 | } | |
4013 | else if (word > sym_text) | |
4014 | { | |
4015 | /* Return some portion of symname. */ | |
4016 | new = xmalloc (strlen (symname) + 5); | |
4017 | strcpy (new, symname + (word - sym_text)); | |
4018 | } | |
4019 | else | |
4020 | { | |
4021 | /* Return some of SYM_TEXT plus symname. */ | |
4022 | new = xmalloc (strlen (symname) + (sym_text - word) + 5); | |
4023 | strncpy (new, word, sym_text - word); | |
4024 | new[sym_text - word] = '\0'; | |
4025 | strcat (new, symname); | |
4026 | } | |
4027 | ||
4028 | /* Recheck for duplicates if we intend to add a modified symbol. */ | |
4029 | if (word != sym_text) | |
4030 | { | |
4031 | for (i = 0; i < return_val_index; ++i) | |
4032 | { | |
4033 | if (STREQ (new, return_val[i])) | |
4034 | { | |
4035 | free (new); | |
4036 | return; | |
4037 | } | |
4038 | } | |
4039 | } | |
4040 | ||
4041 | if (return_val_index + 3 > return_val_size) | |
4042 | { | |
4043 | newsize = (return_val_size *= 2) * sizeof (char *); | |
4044 | return_val = (char **) xrealloc ((char *) return_val, newsize); | |
4045 | } | |
4046 | return_val[return_val_index++] = new; | |
4047 | return_val[return_val_index] = NULL; | |
4048 | } | |
4049 | } | |
4050 | ||
4051 | /* Return a NULL terminated array of all symbols (regardless of class) which | |
4052 | begin by matching TEXT. If the answer is no symbols, then the return value | |
4053 | is an array which contains only a NULL pointer. | |
4054 | ||
4055 | Problem: All of the symbols have to be copied because readline frees them. | |
4056 | I'm not going to worry about this; hopefully there won't be that many. */ | |
4057 | ||
4058 | char ** | |
4059 | make_symbol_completion_list (text, word) | |
4060 | char *text; | |
4061 | char *word; | |
4062 | { | |
4063 | register struct symbol *sym; | |
4064 | register struct symtab *s; | |
4065 | register struct partial_symtab *ps; | |
4066 | register struct minimal_symbol *msymbol; | |
4067 | register struct objfile *objfile; | |
4068 | register struct block *b, *surrounding_static_block = 0; | |
4069 | register int i, j; | |
4070 | struct partial_symbol **psym; | |
4071 | /* The symbol we are completing on. Points in same buffer as text. */ | |
4072 | char *sym_text; | |
4073 | /* Length of sym_text. */ | |
4074 | int sym_text_len; | |
4075 | ||
4076 | /* Now look for the symbol we are supposed to complete on. | |
4077 | FIXME: This should be language-specific. */ | |
4078 | { | |
4079 | char *p; | |
4080 | char quote_found; | |
4081 | char *quote_pos = NULL; | |
4082 | ||
4083 | /* First see if this is a quoted string. */ | |
4084 | quote_found = '\0'; | |
4085 | for (p = text; *p != '\0'; ++p) | |
4086 | { | |
4087 | if (quote_found != '\0') | |
4088 | { | |
4089 | if (*p == quote_found) | |
4090 | /* Found close quote. */ | |
4091 | quote_found = '\0'; | |
4092 | else if (*p == '\\' && p[1] == quote_found) | |
4093 | /* A backslash followed by the quote character | |
4094 | doesn't end the string. */ | |
4095 | ++p; | |
4096 | } | |
4097 | else if (*p == '\'' || *p == '"') | |
4098 | { | |
4099 | quote_found = *p; | |
4100 | quote_pos = p; | |
4101 | } | |
4102 | } | |
4103 | if (quote_found == '\'') | |
4104 | /* A string within single quotes can be a symbol, so complete on it. */ | |
4105 | sym_text = quote_pos + 1; | |
4106 | else if (quote_found == '"') | |
4107 | /* A double-quoted string is never a symbol, nor does it make sense | |
4108 | to complete it any other way. */ | |
4109 | return NULL; | |
4110 | else | |
4111 | { | |
4112 | /* It is not a quoted string. Break it based on the characters | |
4113 | which are in symbols. */ | |
4114 | while (p > text) | |
4115 | { | |
4116 | if (isalnum (p[-1]) || p[-1] == '_' || p[-1] == '\0') | |
4117 | --p; | |
4118 | else | |
4119 | break; | |
4120 | } | |
4121 | sym_text = p; | |
4122 | } | |
4123 | } | |
4124 | ||
4125 | sym_text_len = strlen (sym_text); | |
4126 | ||
4127 | return_val_size = 100; | |
4128 | return_val_index = 0; | |
4129 | return_val = (char **) xmalloc ((return_val_size + 1) * sizeof (char *)); | |
4130 | return_val[0] = NULL; | |
4131 | ||
4132 | /* Look through the partial symtabs for all symbols which begin | |
4133 | by matching SYM_TEXT. Add each one that you find to the list. */ | |
4134 | ||
4135 | ALL_PSYMTABS (objfile, ps) | |
4136 | { | |
4137 | /* If the psymtab's been read in we'll get it when we search | |
4138 | through the blockvector. */ | |
4139 | if (ps->readin) continue; | |
4140 | ||
4141 | for (psym = objfile->global_psymbols.list + ps->globals_offset; | |
4142 | psym < (objfile->global_psymbols.list + ps->globals_offset | |
4143 | + ps->n_global_syms); | |
4144 | psym++) | |
4145 | { | |
4146 | /* If interrupted, then quit. */ | |
4147 | QUIT; | |
4148 | COMPLETION_LIST_ADD_SYMBOL (*psym, sym_text, sym_text_len, text, word); | |
4149 | } | |
4150 | ||
4151 | for (psym = objfile->static_psymbols.list + ps->statics_offset; | |
4152 | psym < (objfile->static_psymbols.list + ps->statics_offset | |
4153 | + ps->n_static_syms); | |
4154 | psym++) | |
4155 | { | |
4156 | QUIT; | |
4157 | COMPLETION_LIST_ADD_SYMBOL (*psym, sym_text, sym_text_len, text, word); | |
4158 | } | |
4159 | } | |
4160 | ||
4161 | /* At this point scan through the misc symbol vectors and add each | |
4162 | symbol you find to the list. Eventually we want to ignore | |
4163 | anything that isn't a text symbol (everything else will be | |
4164 | handled by the psymtab code above). */ | |
4165 | ||
4166 | ALL_MSYMBOLS (objfile, msymbol) | |
4167 | { | |
4168 | QUIT; | |
4169 | COMPLETION_LIST_ADD_SYMBOL (msymbol, sym_text, sym_text_len, text, word); | |
4170 | } | |
4171 | ||
4172 | /* Search upwards from currently selected frame (so that we can | |
4173 | complete on local vars. */ | |
4174 | ||
4175 | for (b = get_selected_block (); b != NULL; b = BLOCK_SUPERBLOCK (b)) | |
4176 | { | |
4177 | if (!BLOCK_SUPERBLOCK (b)) | |
4178 | { | |
4179 | surrounding_static_block = b; /* For elmin of dups */ | |
4180 | } | |
4181 | ||
4182 | /* Also catch fields of types defined in this places which match our | |
4183 | text string. Only complete on types visible from current context. */ | |
4184 | ||
4185 | for (i = 0; i < BLOCK_NSYMS (b); i++) | |
4186 | { | |
4187 | sym = BLOCK_SYM (b, i); | |
4188 | COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word); | |
4189 | if (SYMBOL_CLASS (sym) == LOC_TYPEDEF) | |
4190 | { | |
4191 | struct type *t = SYMBOL_TYPE (sym); | |
4192 | enum type_code c = TYPE_CODE (t); | |
4193 | ||
4194 | if (c == TYPE_CODE_UNION || c == TYPE_CODE_STRUCT) | |
4195 | { | |
4196 | for (j = TYPE_N_BASECLASSES (t); j < TYPE_NFIELDS (t); j++) | |
4197 | { | |
4198 | if (TYPE_FIELD_NAME (t, j)) | |
4199 | { | |
4200 | completion_list_add_name (TYPE_FIELD_NAME (t, j), | |
4201 | sym_text, sym_text_len, text, word); | |
4202 | } | |
4203 | } | |
4204 | } | |
4205 | } | |
4206 | } | |
4207 | } | |
4208 | ||
4209 | /* Go through the symtabs and check the externs and statics for | |
4210 | symbols which match. */ | |
4211 | ||
4212 | ALL_SYMTABS (objfile, s) | |
4213 | { | |
4214 | QUIT; | |
4215 | b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK); | |
4216 | for (i = 0; i < BLOCK_NSYMS (b); i++) | |
4217 | { | |
4218 | sym = BLOCK_SYM (b, i); | |
4219 | COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word); | |
4220 | } | |
4221 | } | |
4222 | ||
4223 | ALL_SYMTABS (objfile, s) | |
4224 | { | |
4225 | QUIT; | |
4226 | b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK); | |
4227 | /* Don't do this block twice. */ | |
4228 | if (b == surrounding_static_block) continue; | |
4229 | for (i = 0; i < BLOCK_NSYMS (b); i++) | |
4230 | { | |
4231 | sym = BLOCK_SYM (b, i); | |
4232 | COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word); | |
4233 | } | |
4234 | } | |
4235 | ||
4236 | return (return_val); | |
4237 | } | |
4238 | ||
4239 | /* Determine if PC is in the prologue of a function. The prologue is the area | |
4240 | between the first instruction of a function, and the first executable line. | |
4241 | Returns 1 if PC *might* be in prologue, 0 if definately *not* in prologue. | |
4242 | ||
4243 | If non-zero, func_start is where we think the prologue starts, possibly | |
4244 | by previous examination of symbol table information. | |
4245 | */ | |
4246 | ||
4247 | int | |
4248 | in_prologue (pc, func_start) | |
4249 | CORE_ADDR pc; | |
4250 | CORE_ADDR func_start; | |
4251 | { | |
4252 | struct symtab_and_line sal; | |
4253 | CORE_ADDR func_addr, func_end; | |
4254 | ||
4255 | if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end)) | |
4256 | goto nosyms; /* Might be in prologue */ | |
4257 | ||
4258 | sal = find_pc_line (func_addr, 0); | |
4259 | ||
4260 | if (sal.line == 0) | |
4261 | goto nosyms; | |
4262 | ||
4263 | /* sal.end is the address of the first instruction past sal.line. */ | |
4264 | if (sal.end > func_addr | |
4265 | && sal.end <= func_end) /* Is prologue in function? */ | |
4266 | return pc < sal.end; /* Yes, is pc in prologue? */ | |
4267 | ||
4268 | /* The line after the prologue seems to be outside the function. In this | |
4269 | case, tell the caller to find the prologue the hard way. */ | |
4270 | ||
4271 | return 1; | |
4272 | ||
4273 | /* Come here when symtabs don't contain line # info. In this case, it is | |
4274 | likely that the user has stepped into a library function w/o symbols, or | |
4275 | is doing a stepi/nexti through code without symbols. */ | |
4276 | ||
4277 | nosyms: | |
4278 | ||
4279 | /* If func_start is zero (meaning unknown) then we don't know whether pc is | |
4280 | in the prologue or not. I.E. it might be. */ | |
4281 | ||
4282 | if (!func_start) return 1; | |
4283 | ||
4284 | /* We need to call the target-specific prologue skipping functions with the | |
4285 | function's start address because PC may be pointing at an instruction that | |
4286 | could be mistakenly considered part of the prologue. */ | |
4287 | ||
4288 | SKIP_PROLOGUE (func_start); | |
4289 | ||
4290 | return pc < func_start; | |
4291 | } | |
4292 | ||
4293 | ||
4294 | /* Begin overload resolution functions */ | |
4295 | /* Helper routine for make_symbol_completion_list. */ | |
4296 | ||
4297 | static int sym_return_val_size; | |
4298 | static int sym_return_val_index; | |
4299 | static struct symbol **sym_return_val; | |
4300 | ||
4301 | /* Test to see if the symbol specified by SYMNAME (which is already | |
4302 | demangled for C++ symbols) matches SYM_TEXT in the first SYM_TEXT_LEN | |
4303 | characters. If so, add it to the current completion list. */ | |
4304 | ||
4305 | static void | |
4306 | overload_list_add_symbol (sym, oload_name) | |
4307 | struct symbol * sym; | |
4308 | char * oload_name; | |
4309 | { | |
4310 | int newsize; | |
4311 | int i; | |
4312 | ||
4313 | /* Get the demangled name without parameters */ | |
4314 | char * sym_name = cplus_demangle (SYMBOL_NAME (sym), DMGL_ARM | DMGL_ANSI); | |
4315 | if (!sym_name) | |
4316 | { | |
4317 | sym_name = (char *) xmalloc (strlen (SYMBOL_NAME (sym)) + 1); | |
4318 | strcpy (sym_name, SYMBOL_NAME (sym)); | |
4319 | } | |
4320 | ||
4321 | /* skip symbols that cannot match */ | |
4322 | if (strcmp (sym_name, oload_name) != 0) | |
4323 | return; | |
4324 | ||
4325 | /* If there is no type information, we can't do anything, so skip */ | |
4326 | if (SYMBOL_TYPE (sym) == NULL) | |
4327 | return; | |
4328 | ||
4329 | /* skip any symbols that we've already considered. */ | |
4330 | for (i = 0; i < sym_return_val_index; ++i) | |
4331 | if (!strcmp (SYMBOL_NAME (sym), SYMBOL_NAME (sym_return_val[i]))) | |
4332 | return; | |
4333 | ||
4334 | /* We have a match for an overload instance, so add SYM to the current list | |
4335 | * of overload instances */ | |
4336 | if (sym_return_val_index + 3 > sym_return_val_size) | |
4337 | { | |
4338 | newsize = (sym_return_val_size *= 2) * sizeof (struct symbol *); | |
4339 | sym_return_val = (struct symbol **) xrealloc ((char *) sym_return_val, newsize); | |
4340 | } | |
4341 | sym_return_val[sym_return_val_index++] = sym; | |
4342 | sym_return_val[sym_return_val_index] = NULL; | |
4343 | ||
4344 | free (sym_name); | |
4345 | } | |
4346 | ||
4347 | /* Return a null-terminated list of pointers to function symbols that | |
4348 | * match name of the supplied symbol FSYM. | |
4349 | * This is used in finding all overloaded instances of a function name. | |
4350 | * This has been modified from make_symbol_completion_list. */ | |
4351 | ||
4352 | ||
4353 | struct symbol ** | |
4354 | make_symbol_overload_list (fsym) | |
4355 | struct symbol * fsym; | |
4356 | { | |
4357 | register struct symbol *sym; | |
4358 | register struct symtab *s; | |
4359 | register struct partial_symtab *ps; | |
4360 | register struct minimal_symbol *msymbol; | |
4361 | register struct objfile *objfile; | |
4362 | register struct block *b, *surrounding_static_block = 0; | |
4363 | register int i, j; | |
4364 | struct partial_symbol **psym; | |
4365 | /* The name we are completing on. */ | |
4366 | char *oload_name = NULL; | |
4367 | /* Length of name. */ | |
4368 | int oload_name_len = 0; | |
4369 | ||
4370 | /* Look for the symbol we are supposed to complete on. | |
4371 | * FIXME: This should be language-specific. */ | |
4372 | ||
4373 | oload_name = cplus_demangle (SYMBOL_NAME (fsym), DMGL_ARM | DMGL_ANSI); | |
4374 | if (!oload_name) | |
4375 | { | |
4376 | oload_name = (char *) xmalloc (strlen (SYMBOL_NAME (fsym)) + 1); | |
4377 | strcpy (oload_name, SYMBOL_NAME (fsym)); | |
4378 | } | |
4379 | oload_name_len = strlen (oload_name); | |
4380 | ||
4381 | sym_return_val_size = 100; | |
4382 | sym_return_val_index = 0; | |
4383 | sym_return_val = (struct symbol **) xmalloc ((sym_return_val_size + 1) * sizeof (struct symbol *)); | |
4384 | sym_return_val[0] = NULL; | |
4385 | ||
7a292a7a SS |
4386 | /* Comment and #if 0 from Rajiv Mirani <mirani@cup.hp.com>. |
4387 | However, leaving #if 0's around is uncool. We need to figure out | |
4388 | what this is really trying to do, decide whether we want that, | |
4389 | and either fix it or delete it. --- Jim Blandy, Mar 1999 */ | |
4390 | ||
4391 | /* ??? RM: What in hell is this? overload_list_add_symbol expects a symbol, | |
4392 | * not a partial_symbol or a minimal_symbol. And it looks at the type field | |
4393 | * of the symbol, and we don't know the type of minimal and partial symbols | |
4394 | */ | |
4395 | #if 0 | |
c906108c SS |
4396 | /* Look through the partial symtabs for all symbols which begin |
4397 | by matching OLOAD_NAME. Add each one that you find to the list. */ | |
4398 | ||
4399 | ALL_PSYMTABS (objfile, ps) | |
4400 | { | |
4401 | /* If the psymtab's been read in we'll get it when we search | |
4402 | through the blockvector. */ | |
4403 | if (ps->readin) continue; | |
4404 | ||
4405 | for (psym = objfile->global_psymbols.list + ps->globals_offset; | |
4406 | psym < (objfile->global_psymbols.list + ps->globals_offset | |
4407 | + ps->n_global_syms); | |
4408 | psym++) | |
4409 | { | |
4410 | /* If interrupted, then quit. */ | |
4411 | QUIT; | |
4412 | overload_list_add_symbol (*psym, oload_name); | |
4413 | } | |
4414 | ||
4415 | for (psym = objfile->static_psymbols.list + ps->statics_offset; | |
4416 | psym < (objfile->static_psymbols.list + ps->statics_offset | |
4417 | + ps->n_static_syms); | |
4418 | psym++) | |
4419 | { | |
4420 | QUIT; | |
4421 | overload_list_add_symbol (*psym, oload_name); | |
4422 | } | |
4423 | } | |
4424 | ||
4425 | /* At this point scan through the misc symbol vectors and add each | |
4426 | symbol you find to the list. Eventually we want to ignore | |
4427 | anything that isn't a text symbol (everything else will be | |
4428 | handled by the psymtab code above). */ | |
4429 | ||
4430 | ALL_MSYMBOLS (objfile, msymbol) | |
4431 | { | |
4432 | QUIT; | |
4433 | overload_list_add_symbol (msymbol, oload_name); | |
4434 | } | |
7a292a7a | 4435 | #endif |
c906108c SS |
4436 | |
4437 | /* Search upwards from currently selected frame (so that we can | |
4438 | complete on local vars. */ | |
4439 | ||
4440 | for (b = get_selected_block (); b != NULL; b = BLOCK_SUPERBLOCK (b)) | |
4441 | { | |
4442 | if (!BLOCK_SUPERBLOCK (b)) | |
4443 | { | |
4444 | surrounding_static_block = b; /* For elimination of dups */ | |
4445 | } | |
4446 | ||
4447 | /* Also catch fields of types defined in this places which match our | |
4448 | text string. Only complete on types visible from current context. */ | |
4449 | ||
4450 | for (i = 0; i < BLOCK_NSYMS (b); i++) | |
4451 | { | |
4452 | sym = BLOCK_SYM (b, i); | |
4453 | overload_list_add_symbol (sym, oload_name); | |
4454 | } | |
4455 | } | |
4456 | ||
4457 | /* Go through the symtabs and check the externs and statics for | |
4458 | symbols which match. */ | |
4459 | ||
4460 | ALL_SYMTABS (objfile, s) | |
4461 | { | |
4462 | QUIT; | |
4463 | b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK); | |
4464 | for (i = 0; i < BLOCK_NSYMS (b); i++) | |
4465 | { | |
4466 | sym = BLOCK_SYM (b, i); | |
4467 | overload_list_add_symbol (sym, oload_name); | |
4468 | } | |
4469 | } | |
4470 | ||
4471 | ALL_SYMTABS (objfile, s) | |
4472 | { | |
4473 | QUIT; | |
4474 | b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK); | |
4475 | /* Don't do this block twice. */ | |
4476 | if (b == surrounding_static_block) continue; | |
4477 | for (i = 0; i < BLOCK_NSYMS (b); i++) | |
4478 | { | |
4479 | sym = BLOCK_SYM (b, i); | |
4480 | overload_list_add_symbol (sym, oload_name); | |
4481 | } | |
4482 | } | |
4483 | ||
4484 | free (oload_name); | |
4485 | ||
4486 | return (sym_return_val); | |
4487 | } | |
4488 | ||
4489 | /* End of overload resolution functions */ | |
4490 | ||
4491 | \f | |
4492 | void | |
4493 | _initialize_symtab () | |
4494 | { | |
4495 | add_info ("variables", variables_info, | |
4496 | "All global and static variable names, or those matching REGEXP."); | |
4497 | if (dbx_commands) | |
4498 | add_com("whereis", class_info, variables_info, | |
4499 | "All global and static variable names, or those matching REGEXP."); | |
4500 | ||
4501 | add_info ("functions", functions_info, | |
4502 | "All function names, or those matching REGEXP."); | |
4503 | ||
4504 | /* FIXME: This command has at least the following problems: | |
4505 | 1. It prints builtin types (in a very strange and confusing fashion). | |
4506 | 2. It doesn't print right, e.g. with | |
4507 | typedef struct foo *FOO | |
4508 | type_print prints "FOO" when we want to make it (in this situation) | |
4509 | print "struct foo *". | |
4510 | I also think "ptype" or "whatis" is more likely to be useful (but if | |
4511 | there is much disagreement "info types" can be fixed). */ | |
4512 | add_info ("types", types_info, | |
4513 | "All type names, or those matching REGEXP."); | |
4514 | ||
4515 | #if 0 | |
4516 | add_info ("methods", methods_info, | |
4517 | "All method names, or those matching REGEXP::REGEXP.\n\ | |
4518 | If the class qualifier is omitted, it is assumed to be the current scope.\n\ | |
4519 | If the first REGEXP is omitted, then all methods matching the second REGEXP\n\ | |
4520 | are listed."); | |
4521 | #endif | |
4522 | add_info ("sources", sources_info, | |
4523 | "Source files in the program."); | |
4524 | ||
4525 | add_com ("rbreak", class_breakpoint, rbreak_command, | |
4526 | "Set a breakpoint for all functions matching REGEXP."); | |
4527 | ||
4528 | if (xdb_commands) | |
4529 | { | |
4530 | add_com ("lf", class_info, sources_info, "Source files in the program"); | |
4531 | add_com ("lg", class_info, variables_info, | |
4532 | "All global and static variable names, or those matching REGEXP."); | |
4533 | } | |
4534 | ||
4535 | /* Initialize the one built-in type that isn't language dependent... */ | |
4536 | builtin_type_error = init_type (TYPE_CODE_ERROR, 0, 0, | |
4537 | "<unknown type>", (struct objfile *) NULL); | |
4538 | } |