Commit | Line | Data |
---|---|---|
bd5635a1 | 1 | /* Symbol table lookup for the GNU debugger, GDB. |
cba0d141 | 2 | Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992 Free Software Foundation, Inc. |
bd5635a1 RP |
3 | |
4 | This file is part of GDB. | |
5 | ||
997a978c | 6 | This program is free software; you can redistribute it and/or modify |
bd5635a1 | 7 | it under the terms of the GNU General Public License as published by |
997a978c JG |
8 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. | |
bd5635a1 | 10 | |
997a978c | 11 | This program is distributed in the hope that it will be useful, |
bd5635a1 RP |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
997a978c JG |
17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
bd5635a1 RP |
19 | |
20 | #include <stdio.h> | |
21 | #include "defs.h" | |
22 | #include "symtab.h" | |
cba0d141 | 23 | #include "gdbtypes.h" |
bd5635a1 RP |
24 | #include "gdbcore.h" |
25 | #include "frame.h" | |
26 | #include "target.h" | |
27 | #include "value.h" | |
28 | #include "symfile.h" | |
29 | #include "gdbcmd.h" | |
5594d534 | 30 | #include "regex.h" |
cba0d141 | 31 | #include "expression.h" |
997a978c | 32 | #include "language.h" |
bd5635a1 RP |
33 | |
34 | #include <obstack.h> | |
35 | #include <assert.h> | |
36 | ||
37 | #include <sys/types.h> | |
38 | #include <fcntl.h> | |
39 | #include <string.h> | |
40 | #include <sys/stat.h> | |
41 | ||
cba0d141 | 42 | /* Prototypes for local functions */ |
bd5635a1 | 43 | |
cba0d141 JG |
44 | static int |
45 | find_methods PARAMS ((struct type *, char *, char **, struct symbol **)); | |
46 | ||
47 | static void | |
48 | completion_list_add_symbol PARAMS ((char *)); | |
49 | ||
50 | static struct symtabs_and_lines | |
51 | decode_line_2 PARAMS ((struct symbol *[], int, int)); | |
52 | ||
53 | static void | |
54 | rbreak_command PARAMS ((char *)); | |
55 | ||
56 | static void | |
57 | types_info PARAMS ((char *)); | |
58 | ||
59 | static void | |
60 | functions_info PARAMS ((char *)); | |
61 | ||
62 | static void | |
63 | variables_info PARAMS ((char *)); | |
64 | ||
65 | static void | |
66 | list_symbols PARAMS ((char *, int, int)); | |
67 | ||
68 | static void | |
69 | sources_info PARAMS ((void)); | |
70 | ||
71 | static void | |
72 | output_source_filename PARAMS ((char *, int *)); | |
73 | ||
74 | static char * | |
75 | operator_chars PARAMS ((char *, char **)); | |
76 | ||
77 | static int | |
78 | find_line_common PARAMS ((struct linetable *, int, int *)); | |
79 | ||
80 | static struct partial_symbol * | |
81 | lookup_partial_symbol PARAMS ((struct partial_symtab *, const char *, | |
82 | int, enum namespace)); | |
83 | ||
84 | static struct partial_symbol * | |
85 | lookup_demangled_partial_symbol PARAMS ((const struct partial_symtab *, | |
86 | const char *)); | |
87 | ||
88 | static struct symbol * | |
89 | lookup_demangled_block_symbol PARAMS ((const struct block *, const char *)); | |
bd5635a1 | 90 | |
cba0d141 JG |
91 | static struct symtab * |
92 | lookup_symtab_1 PARAMS ((char *)); | |
93 | ||
94 | /* */ | |
bd5635a1 | 95 | |
997a978c | 96 | /* The single non-language-specific builtin type */ |
bd5635a1 RP |
97 | struct type *builtin_type_error; |
98 | ||
99 | /* Block in which the most recently searched-for symbol was found. | |
100 | Might be better to make this a parameter to lookup_symbol and | |
101 | value_of_this. */ | |
cba0d141 JG |
102 | |
103 | const struct block *block_found; | |
bd5635a1 RP |
104 | |
105 | char no_symtab_msg[] = "No symbol table is loaded. Use the \"file\" command."; | |
106 | ||
107 | /* Check for a symtab of a specific name; first in symtabs, then in | |
108 | psymtabs. *If* there is no '/' in the name, a match after a '/' | |
109 | in the symtab filename will also work. */ | |
110 | ||
111 | static struct symtab * | |
112 | lookup_symtab_1 (name) | |
113 | char *name; | |
114 | { | |
115 | register struct symtab *s; | |
116 | register struct partial_symtab *ps; | |
117 | register char *slash = strchr (name, '/'); | |
118 | register int len = strlen (name); | |
cba0d141 | 119 | register struct objfile *objfile; |
bd5635a1 | 120 | |
bd5635a1 | 121 | |
cba0d141 JG |
122 | for (objfile = object_files; objfile != NULL; objfile = objfile -> next) |
123 | { | |
124 | for (s = objfile -> symtabs; s != NULL; s = s -> next) | |
125 | { | |
126 | if (strcmp (name, s->filename) == 0) | |
127 | { | |
128 | return (s); | |
129 | } | |
130 | } | |
131 | } | |
132 | for (objfile = object_files; objfile != NULL; objfile = objfile -> next) | |
133 | { | |
134 | for (ps = objfile -> psymtabs; ps != NULL; ps = ps->next) | |
135 | { | |
136 | if (strcmp (name, ps -> filename) == 0) | |
137 | { | |
138 | if (ps -> readin) | |
139 | { | |
140 | error ("Internal: readin pst for `%s' found when no symtab found.", name); | |
141 | } | |
142 | return (PSYMTAB_TO_SYMTAB (ps)); | |
143 | } | |
144 | } | |
145 | } | |
bd5635a1 RP |
146 | if (!slash) |
147 | { | |
cba0d141 | 148 | for (objfile = object_files; objfile != NULL; objfile = objfile -> next) |
bd5635a1 | 149 | { |
cba0d141 JG |
150 | for (s = objfile -> symtabs; s != NULL; s = s -> next) |
151 | { | |
152 | int l = strlen (s->filename); | |
153 | ||
154 | if (s->filename[l - len -1] == '/' | |
155 | && (strcmp (s->filename + l - len, name) == 0)) | |
156 | { | |
157 | return (s); | |
158 | } | |
159 | } | |
bd5635a1 RP |
160 | } |
161 | ||
cba0d141 | 162 | for (objfile = object_files; objfile != NULL; objfile = objfile -> next) |
bd5635a1 | 163 | { |
cba0d141 | 164 | for (ps = objfile -> psymtabs; ps != NULL; ps = ps -> next) |
bd5635a1 | 165 | { |
cba0d141 JG |
166 | int l = strlen (ps -> filename); |
167 | ||
168 | if (ps -> filename[l - len - 1] == '/' | |
169 | && (strcmp (ps->filename + l - len, name) == 0)) | |
170 | { | |
171 | if (ps -> readin) | |
172 | { | |
173 | error ("Internal: readin pst for `%s' found when no symtab found.", name); | |
174 | } | |
175 | return (PSYMTAB_TO_SYMTAB (ps)); | |
176 | } | |
bd5635a1 RP |
177 | } |
178 | } | |
179 | } | |
cba0d141 | 180 | return (NULL); |
bd5635a1 RP |
181 | } |
182 | ||
183 | /* Lookup the symbol table of a source file named NAME. Try a couple | |
184 | of variations if the first lookup doesn't work. */ | |
185 | ||
186 | struct symtab * | |
187 | lookup_symtab (name) | |
188 | char *name; | |
189 | { | |
190 | register struct symtab *s; | |
191 | register char *copy; | |
192 | ||
193 | s = lookup_symtab_1 (name); | |
194 | if (s) return s; | |
195 | ||
196 | /* If name not found as specified, see if adding ".c" helps. */ | |
197 | ||
198 | copy = (char *) alloca (strlen (name) + 3); | |
199 | strcpy (copy, name); | |
200 | strcat (copy, ".c"); | |
201 | s = lookup_symtab_1 (copy); | |
202 | if (s) return s; | |
203 | ||
204 | /* We didn't find anything; die. */ | |
205 | return 0; | |
206 | } | |
207 | ||
208 | /* Lookup the partial symbol table of a source file named NAME. This | |
209 | only returns true on an exact match (ie. this semantics are | |
210 | different from lookup_symtab. */ | |
211 | ||
212 | struct partial_symtab * | |
213 | lookup_partial_symtab (name) | |
214 | char *name; | |
215 | { | |
cba0d141 JG |
216 | register struct partial_symtab *pst; |
217 | register struct objfile *objfile; | |
bd5635a1 | 218 | |
cba0d141 | 219 | for (objfile = object_files; objfile != NULL; objfile = objfile -> next) |
bd5635a1 | 220 | { |
cba0d141 | 221 | for (pst = objfile -> psymtabs; pst != NULL; pst = pst -> next) |
bd5635a1 | 222 | { |
cba0d141 JG |
223 | if (strcmp (name, pst -> filename) == 0) |
224 | { | |
225 | return (pst); | |
226 | } | |
bd5635a1 | 227 | } |
cba0d141 JG |
228 | } |
229 | return (NULL); | |
bd5635a1 | 230 | } |
cba0d141 | 231 | \f |
bd5635a1 RP |
232 | /* Demangle a GDB method stub type. */ |
233 | char * | |
bcccec8c | 234 | gdb_mangle_name (type, i, j) |
bd5635a1 | 235 | struct type *type; |
bcccec8c | 236 | int i, j; |
bd5635a1 | 237 | { |
bcccec8c PB |
238 | int mangled_name_len; |
239 | char *mangled_name; | |
240 | struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i); | |
241 | struct fn_field *method = &f[j]; | |
242 | char *field_name = TYPE_FN_FIELDLIST_NAME (type, i); | |
7c4f3f4a | 243 | int is_constructor = strcmp(field_name, TYPE_NAME (type)) == 0; |
bd5635a1 | 244 | |
bcccec8c | 245 | /* Need a new type prefix. */ |
bcccec8c PB |
246 | char *const_prefix = method->is_const ? "C" : ""; |
247 | char *volatile_prefix = method->is_volatile ? "V" : ""; | |
248 | char *newname = type_name_no_tag (type); | |
249 | char buf[20]; | |
250 | int len = strlen (newname); | |
251 | ||
252 | sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len); | |
7c4f3f4a | 253 | mangled_name_len = ((is_constructor ? 0 : strlen (field_name)) |
bcccec8c PB |
254 | + strlen (buf) + len |
255 | + strlen (TYPE_FN_FIELD_PHYSNAME (f, j)) | |
256 | + 1); | |
257 | ||
7d9884b9 JG |
258 | /* Only needed for GNU-mangled names. ANSI-mangled names |
259 | work with the normal mechanisms. */ | |
bcccec8c PB |
260 | if (OPNAME_PREFIX_P (field_name)) |
261 | { | |
7d9884b9 | 262 | char *opname = cplus_mangle_opname (field_name + 3, 0); |
bcccec8c PB |
263 | if (opname == NULL) |
264 | error ("No mangling for \"%s\"", field_name); | |
265 | mangled_name_len += strlen (opname); | |
266 | mangled_name = (char *)xmalloc (mangled_name_len); | |
267 | ||
268 | strncpy (mangled_name, field_name, 3); | |
269 | mangled_name[3] = '\0'; | |
270 | strcat (mangled_name, opname); | |
271 | } | |
272 | else | |
bd5635a1 | 273 | { |
bcccec8c | 274 | mangled_name = (char *)xmalloc (mangled_name_len); |
7c4f3f4a MT |
275 | if (is_constructor) |
276 | mangled_name[0] = '\0'; | |
277 | else | |
278 | strcpy (mangled_name, field_name); | |
bd5635a1 | 279 | } |
bcccec8c PB |
280 | strcat (mangled_name, buf); |
281 | strcat (mangled_name, newname); | |
282 | strcat (mangled_name, TYPE_FN_FIELD_PHYSNAME (f, j)); | |
283 | ||
284 | return mangled_name; | |
bd5635a1 RP |
285 | } |
286 | ||
cba0d141 JG |
287 | \f |
288 | /* Find which partial symtab on contains PC. Return 0 if none. */ | |
f1d77e90 | 289 | |
cba0d141 JG |
290 | struct partial_symtab * |
291 | find_pc_psymtab (pc) | |
292 | register CORE_ADDR pc; | |
d96b54ea | 293 | { |
cba0d141 JG |
294 | register struct partial_symtab *pst; |
295 | register struct objfile *objfile; | |
d96b54ea | 296 | |
cba0d141 | 297 | for (objfile = object_files; objfile != NULL; objfile = objfile -> next) |
bd5635a1 | 298 | { |
cba0d141 | 299 | for (pst = objfile -> psymtabs; pst != NULL; pst = pst -> next) |
bd5635a1 | 300 | { |
cba0d141 | 301 | if (pc >= pst -> textlow && pc < pst -> texthigh) |
bd5635a1 | 302 | { |
cba0d141 | 303 | return (pst); |
bd5635a1 | 304 | } |
f1d77e90 | 305 | } |
bd5635a1 | 306 | } |
cba0d141 | 307 | return (NULL); |
bd5635a1 RP |
308 | } |
309 | ||
310 | /* Find which partial symbol within a psymtab contains PC. Return 0 | |
311 | if none. Check all psymtabs if PSYMTAB is 0. */ | |
312 | struct partial_symbol * | |
313 | find_pc_psymbol (psymtab, pc) | |
314 | struct partial_symtab *psymtab; | |
315 | CORE_ADDR pc; | |
316 | { | |
317 | struct partial_symbol *best, *p; | |
318 | CORE_ADDR best_pc; | |
319 | ||
320 | if (!psymtab) | |
321 | psymtab = find_pc_psymtab (pc); | |
322 | if (!psymtab) | |
323 | return 0; | |
324 | ||
325 | best_pc = psymtab->textlow - 1; | |
326 | ||
cba0d141 JG |
327 | for (p = psymtab->objfile->static_psymbols.list + psymtab->statics_offset; |
328 | (p - (psymtab->objfile->static_psymbols.list + psymtab->statics_offset) | |
bd5635a1 RP |
329 | < psymtab->n_static_syms); |
330 | p++) | |
331 | if (SYMBOL_NAMESPACE (p) == VAR_NAMESPACE | |
332 | && SYMBOL_CLASS (p) == LOC_BLOCK | |
333 | && pc >= SYMBOL_VALUE_ADDRESS (p) | |
334 | && SYMBOL_VALUE_ADDRESS (p) > best_pc) | |
335 | { | |
336 | best_pc = SYMBOL_VALUE_ADDRESS (p); | |
337 | best = p; | |
338 | } | |
339 | if (best_pc == psymtab->textlow - 1) | |
340 | return 0; | |
341 | return best; | |
342 | } | |
343 | ||
344 | \f | |
345 | /* Find the definition for a specified symbol name NAME | |
346 | in namespace NAMESPACE, visible from lexical block BLOCK. | |
347 | Returns the struct symbol pointer, or zero if no symbol is found. | |
348 | If SYMTAB is non-NULL, store the symbol table in which the | |
349 | symbol was found there, or NULL if not found. | |
350 | C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if | |
351 | NAME is a field of the current implied argument `this'. If so set | |
352 | *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero. | |
353 | BLOCK_FOUND is set to the block in which NAME is found (in the case of | |
354 | a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */ | |
355 | ||
356 | struct symbol * | |
357 | lookup_symbol (name, block, namespace, is_a_field_of_this, symtab) | |
cba0d141 JG |
358 | const char *name; |
359 | register const struct block *block; | |
360 | const enum namespace namespace; | |
bd5635a1 RP |
361 | int *is_a_field_of_this; |
362 | struct symtab **symtab; | |
363 | { | |
364 | register struct symbol *sym; | |
365 | register struct symtab *s; | |
366 | register struct partial_symtab *ps; | |
367 | struct blockvector *bv; | |
cba0d141 JG |
368 | register struct objfile *objfile; |
369 | register struct block *b; | |
370 | register int found; | |
371 | register struct minimal_symbol *msymbol; | |
bd5635a1 RP |
372 | |
373 | /* Search specified block and its superiors. */ | |
374 | ||
375 | while (block != 0) | |
376 | { | |
377 | sym = lookup_block_symbol (block, name, namespace); | |
378 | if (sym) | |
379 | { | |
380 | block_found = block; | |
381 | if (symtab != NULL) | |
382 | { | |
383 | /* Search the list of symtabs for one which contains the | |
384 | address of the start of this block. */ | |
cba0d141 JG |
385 | for (found = 0, objfile = object_files; |
386 | !found && objfile != NULL; | |
387 | objfile = objfile -> next) | |
bd5635a1 | 388 | { |
cba0d141 JG |
389 | for (s = objfile -> symtabs; s != NULL; s = s -> next) |
390 | { | |
391 | bv = BLOCKVECTOR (s); | |
392 | b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
393 | if (BLOCK_START (b) <= BLOCK_START (block) | |
394 | && BLOCK_END (b) > BLOCK_START (block)) | |
395 | { | |
396 | found++; | |
397 | break; | |
398 | } | |
399 | } | |
bd5635a1 RP |
400 | } |
401 | *symtab = s; | |
402 | } | |
403 | ||
cba0d141 | 404 | return (sym); |
bd5635a1 RP |
405 | } |
406 | block = BLOCK_SUPERBLOCK (block); | |
407 | } | |
408 | ||
b039ac3a JK |
409 | /* But that doesn't do any demangling for the STATIC_BLOCK. |
410 | I'm not sure whether demangling is needed in the case of | |
411 | nested function in inner blocks; if so this needs to be changed. | |
412 | ||
413 | Don't need to mess with the psymtabs; if we have a block, | |
414 | that file is read in. If we don't, then we deal later with | |
415 | all the psymtab stuff that needs checking. */ | |
416 | if (namespace == VAR_NAMESPACE && block != NULL) | |
417 | { | |
418 | struct block *b; | |
419 | /* Find the right symtab. */ | |
cba0d141 | 420 | for (objfile = object_files; objfile != NULL; objfile = objfile -> next) |
b039ac3a | 421 | { |
cba0d141 | 422 | for (s = objfile -> symtabs; s != NULL; s = s -> next) |
b039ac3a | 423 | { |
cba0d141 JG |
424 | bv = BLOCKVECTOR (s); |
425 | b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
426 | if (BLOCK_START (b) <= BLOCK_START (block) | |
427 | && BLOCK_END (b) > BLOCK_START (block)) | |
b039ac3a | 428 | { |
cba0d141 JG |
429 | sym = lookup_demangled_block_symbol (b, name); |
430 | if (sym) | |
431 | { | |
432 | block_found = b; | |
433 | if (symtab != NULL) | |
434 | *symtab = s; | |
435 | return sym; | |
436 | } | |
b039ac3a JK |
437 | } |
438 | } | |
439 | } | |
440 | } | |
441 | ||
442 | ||
bd5635a1 RP |
443 | /* C++: If requested to do so by the caller, |
444 | check to see if NAME is a field of `this'. */ | |
445 | if (is_a_field_of_this) | |
446 | { | |
447 | struct value *v = value_of_this (0); | |
448 | ||
449 | *is_a_field_of_this = 0; | |
450 | if (v && check_field (v, name)) | |
451 | { | |
452 | *is_a_field_of_this = 1; | |
453 | if (symtab != NULL) | |
454 | *symtab = NULL; | |
455 | return 0; | |
456 | } | |
457 | } | |
458 | ||
459 | /* Now search all global blocks. Do the symtab's first, then | |
460 | check the psymtab's */ | |
cba0d141 JG |
461 | |
462 | for (objfile = object_files; objfile != NULL; objfile = objfile -> next) | |
bd5635a1 | 463 | { |
cba0d141 | 464 | for (s = objfile -> symtabs; s != NULL; s = s -> next) |
bd5635a1 | 465 | { |
cba0d141 JG |
466 | bv = BLOCKVECTOR (s); |
467 | block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
468 | sym = lookup_block_symbol (block, name, namespace); | |
469 | if (sym) | |
470 | { | |
471 | block_found = block; | |
472 | if (symtab != NULL) | |
473 | *symtab = s; | |
474 | return sym; | |
475 | } | |
bd5635a1 RP |
476 | } |
477 | } | |
478 | ||
479 | /* Check for the possibility of the symbol being a global function | |
cba0d141 | 480 | that is stored in one of the minimal symbol tables. Eventually, all |
bd5635a1 RP |
481 | global symbols might be resolved in this way. */ |
482 | ||
483 | if (namespace == VAR_NAMESPACE) | |
484 | { | |
cba0d141 | 485 | msymbol = lookup_minimal_symbol (name, (struct objfile *) NULL); |
bd5635a1 | 486 | /* Look for a mangled C++ name for NAME. */ |
cba0d141 | 487 | if (msymbol == NULL) |
bd5635a1 RP |
488 | { |
489 | int name_len = strlen (name); | |
490 | ||
cba0d141 | 491 | #if 0 /* FIXME: Needs to be fixed to use new minimal symbol tables */ |
bd5635a1 RP |
492 | for (ind = misc_function_count; --ind >= 0; ) |
493 | /* Assume orginal name is prefix of mangled name. */ | |
494 | if (!strncmp (misc_function_vector[ind].name, name, name_len)) | |
495 | { | |
496 | char *demangled = | |
497 | cplus_demangle(misc_function_vector[ind].name, -1); | |
498 | if (demangled != NULL) | |
499 | { | |
500 | int cond = strcmp (demangled, name); | |
501 | free (demangled); | |
502 | if (!cond) | |
503 | break; | |
504 | } | |
505 | } | |
506 | /* Loop terminates on no match with ind == -1. */ | |
cba0d141 | 507 | #endif |
bd5635a1 RP |
508 | } |
509 | ||
cba0d141 | 510 | if (msymbol != NULL) |
bd5635a1 | 511 | { |
cba0d141 | 512 | s = find_pc_symtab (msymbol -> address); |
997a978c JG |
513 | /* If S is zero, there are no debug symbols for this file. |
514 | Skip this stuff and check for matching static symbols below. */ | |
bd5635a1 RP |
515 | if (s) |
516 | { | |
517 | bv = BLOCKVECTOR (s); | |
3ba6a043 | 518 | block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); |
cba0d141 | 519 | sym = lookup_block_symbol (block, msymbol -> name, namespace); |
818de002 PB |
520 | #if 0 /* defined(IBM6000) */ |
521 | /* we kept static functions in misc_function_vector as well as | |
522 | in static scope. We want to find them in the symbol table. */ | |
523 | ||
524 | if (!sym) { | |
525 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
526 | sym = lookup_block_symbol (block, misc_function_vector[ind].name, | |
527 | namespace); | |
528 | } | |
529 | #endif | |
530 | ||
cba0d141 | 531 | /* sym == 0 if symbol was found in the minimal symbol table |
bd5635a1 | 532 | but not in the symtab. |
cba0d141 | 533 | Return 0 to use the msymbol definition of "foo_". |
bd5635a1 RP |
534 | |
535 | This happens for Fortran "foo_" symbols, | |
536 | which are "foo" in the symtab. | |
537 | ||
538 | This can also happen if "asm" is used to make a | |
539 | regular symbol but not a debugging symbol, e.g. | |
540 | asm(".globl _main"); | |
541 | asm("_main:"); | |
542 | */ | |
543 | ||
544 | if (symtab != NULL) | |
545 | *symtab = s; | |
546 | return sym; | |
547 | } | |
548 | } | |
549 | } | |
550 | ||
cba0d141 JG |
551 | for (objfile = object_files; objfile != NULL; objfile = objfile -> next) |
552 | { | |
553 | for (ps = objfile -> psymtabs; ps != NULL; ps = ps->next) | |
554 | { | |
555 | if (!ps->readin && lookup_partial_symbol (ps, name, 1, namespace)) | |
556 | { | |
557 | s = PSYMTAB_TO_SYMTAB(ps); | |
558 | bv = BLOCKVECTOR (s); | |
559 | block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
560 | sym = lookup_block_symbol (block, name, namespace); | |
561 | if (!sym) | |
562 | error ("Internal: global symbol `%s' found in psymtab but not in symtab", name); | |
563 | if (symtab != NULL) | |
564 | *symtab = s; | |
565 | return sym; | |
566 | } | |
567 | } | |
568 | } | |
bd5635a1 RP |
569 | |
570 | /* Now search all per-file blocks. | |
571 | Not strictly correct, but more useful than an error. | |
572 | Do the symtabs first, then check the psymtabs */ | |
573 | ||
cba0d141 | 574 | for (objfile = object_files; objfile != NULL; objfile = objfile -> next) |
bd5635a1 | 575 | { |
cba0d141 | 576 | for (s = objfile -> symtabs; s != NULL; s = s -> next) |
bd5635a1 | 577 | { |
cba0d141 JG |
578 | bv = BLOCKVECTOR (s); |
579 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
580 | sym = lookup_block_symbol (block, name, namespace); | |
581 | if (sym) | |
582 | { | |
583 | block_found = block; | |
584 | if (symtab != NULL) | |
585 | *symtab = s; | |
586 | return sym; | |
587 | } | |
bd5635a1 RP |
588 | } |
589 | } | |
590 | ||
cba0d141 JG |
591 | for (objfile = object_files; objfile != NULL; objfile = objfile -> next) |
592 | { | |
593 | for (ps = objfile -> psymtabs; ps != NULL; ps = ps -> next) | |
594 | { | |
595 | if (!ps->readin && lookup_partial_symbol (ps, name, 0, namespace)) | |
596 | { | |
597 | s = PSYMTAB_TO_SYMTAB(ps); | |
598 | bv = BLOCKVECTOR (s); | |
599 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
600 | sym = lookup_block_symbol (block, name, namespace); | |
601 | if (!sym) | |
602 | error ("Internal: static symbol `%s' found in psymtab but not in symtab", name); | |
603 | if (symtab != NULL) | |
604 | *symtab = s; | |
605 | return sym; | |
606 | } | |
607 | } | |
608 | } | |
bd5635a1 | 609 | |
b039ac3a JK |
610 | /* Now search all per-file blocks for static mangled symbols. |
611 | Do the symtabs first, then check the psymtabs. */ | |
612 | ||
7c4f3f4a | 613 | if (namespace == VAR_NAMESPACE) |
b039ac3a | 614 | { |
cba0d141 | 615 | for (objfile = object_files; objfile != NULL; objfile = objfile -> next) |
b039ac3a | 616 | { |
cba0d141 | 617 | for (s = objfile -> symtabs; s != NULL; s = s -> next) |
b039ac3a | 618 | { |
cba0d141 JG |
619 | bv = BLOCKVECTOR (s); |
620 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
621 | sym = lookup_demangled_block_symbol (block, name); | |
622 | if (sym) | |
623 | { | |
624 | block_found = block; | |
625 | if (symtab != NULL) | |
626 | *symtab = s; | |
627 | return sym; | |
628 | } | |
b039ac3a JK |
629 | } |
630 | } | |
631 | ||
cba0d141 JG |
632 | for (objfile = object_files; objfile != NULL; objfile = objfile -> next) |
633 | { | |
634 | for (ps = objfile -> psymtabs; ps != NULL; ps = ps -> next) | |
635 | { | |
636 | if (!ps->readin && lookup_demangled_partial_symbol (ps, name)) | |
637 | { | |
638 | s = PSYMTAB_TO_SYMTAB(ps); | |
639 | bv = BLOCKVECTOR (s); | |
640 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
641 | sym = lookup_demangled_block_symbol (block, name); | |
642 | if (!sym) | |
643 | error ("Internal: mangled static symbol `%s' found in psymtab but not in symtab", name); | |
644 | if (symtab != NULL) | |
645 | *symtab = s; | |
646 | return sym; | |
647 | } | |
648 | } | |
649 | } | |
b039ac3a JK |
650 | } |
651 | ||
bd5635a1 RP |
652 | if (symtab != NULL) |
653 | *symtab = NULL; | |
654 | return 0; | |
655 | } | |
656 | ||
b039ac3a JK |
657 | /* Look for a static demangled symbol in block BLOCK. */ |
658 | ||
659 | static struct symbol * | |
660 | lookup_demangled_block_symbol (block, name) | |
cba0d141 JG |
661 | register const struct block *block; |
662 | const char *name; | |
b039ac3a JK |
663 | { |
664 | register int bot, top, inc; | |
665 | register struct symbol *sym; | |
666 | ||
667 | bot = 0; | |
668 | top = BLOCK_NSYMS (block); | |
669 | inc = name[0]; | |
670 | ||
671 | while (bot < top) | |
672 | { | |
673 | sym = BLOCK_SYM (block, bot); | |
674 | if (SYMBOL_NAME (sym)[0] == inc | |
675 | && SYMBOL_NAMESPACE (sym) == VAR_NAMESPACE) | |
676 | { | |
677 | char *demangled = cplus_demangle(SYMBOL_NAME (sym), -1); | |
678 | if (demangled != NULL) | |
679 | { | |
680 | int cond = strcmp (demangled, name); | |
681 | free (demangled); | |
682 | if (!cond) | |
683 | return sym; | |
684 | } | |
685 | } | |
686 | bot++; | |
687 | } | |
688 | ||
689 | return 0; | |
690 | } | |
691 | ||
692 | /* Look, in partial_symtab PST, for static mangled symbol NAME. */ | |
693 | ||
694 | static struct partial_symbol * | |
695 | lookup_demangled_partial_symbol (pst, name) | |
cba0d141 JG |
696 | const struct partial_symtab *pst; |
697 | const char *name; | |
b039ac3a JK |
698 | { |
699 | struct partial_symbol *start, *psym; | |
700 | int length = pst->n_static_syms; | |
701 | register int inc = name[0]; | |
702 | ||
703 | if (!length) | |
704 | return (struct partial_symbol *) 0; | |
705 | ||
cba0d141 | 706 | start = pst->objfile->static_psymbols.list + pst->statics_offset; |
b039ac3a JK |
707 | for (psym = start; psym < start + length; psym++) |
708 | { | |
709 | if (SYMBOL_NAME (psym)[0] == inc | |
710 | && SYMBOL_NAMESPACE (psym) == VAR_NAMESPACE) | |
711 | { | |
712 | char *demangled = cplus_demangle(SYMBOL_NAME (psym), -1); | |
713 | if (demangled != NULL) | |
714 | { | |
715 | int cond = strcmp (demangled, name); | |
716 | free (demangled); | |
717 | if (!cond) | |
718 | return psym; | |
719 | } | |
720 | } | |
721 | } | |
722 | ||
723 | return (struct partial_symbol *) 0; | |
724 | } | |
725 | ||
bd5635a1 RP |
726 | /* Look, in partial_symtab PST, for symbol NAME. Check the global |
727 | symbols if GLOBAL, the static symbols if not */ | |
728 | ||
729 | static struct partial_symbol * | |
730 | lookup_partial_symbol (pst, name, global, namespace) | |
731 | struct partial_symtab *pst; | |
cba0d141 | 732 | const char *name; |
bd5635a1 RP |
733 | int global; |
734 | enum namespace namespace; | |
735 | { | |
736 | struct partial_symbol *start, *psym; | |
737 | int length = (global ? pst->n_global_syms : pst->n_static_syms); | |
738 | ||
739 | if (!length) | |
740 | return (struct partial_symbol *) 0; | |
741 | ||
742 | start = (global ? | |
cba0d141 JG |
743 | pst->objfile->global_psymbols.list + pst->globals_offset : |
744 | pst->objfile->static_psymbols.list + pst->statics_offset ); | |
bd5635a1 RP |
745 | |
746 | if (global) /* This means we can use a binary */ | |
747 | /* search. */ | |
748 | { | |
749 | struct partial_symbol *top, *bottom, *center; | |
750 | ||
751 | /* Binary search. This search is guaranteed to end with center | |
752 | pointing at the earliest partial symbol with the correct | |
753 | name. At that point *all* partial symbols with that name | |
754 | will be checked against the correct namespace. */ | |
755 | bottom = start; | |
756 | top = start + length - 1; | |
757 | while (top > bottom) | |
758 | { | |
759 | center = bottom + (top - bottom) / 2; | |
760 | ||
761 | assert (center < top); | |
762 | ||
763 | if (strcmp (SYMBOL_NAME (center), name) >= 0) | |
764 | top = center; | |
765 | else | |
766 | bottom = center + 1; | |
767 | } | |
768 | assert (top == bottom); | |
769 | ||
770 | while (!strcmp (SYMBOL_NAME (top), name)) | |
771 | { | |
772 | if (SYMBOL_NAMESPACE (top) == namespace) | |
773 | return top; | |
774 | top ++; | |
775 | } | |
776 | } | |
777 | else | |
778 | { | |
779 | /* Can't use a binary search */ | |
780 | for (psym = start; psym < start + length; psym++) | |
781 | if (namespace == SYMBOL_NAMESPACE (psym) | |
782 | && !strcmp (name, SYMBOL_NAME (psym))) | |
783 | return psym; | |
784 | } | |
785 | ||
786 | return (struct partial_symbol *) 0; | |
787 | } | |
788 | ||
0e2a896c PB |
789 | /* Find the psymtab containing main(). */ |
790 | ||
791 | struct partial_symtab * | |
792 | find_main_psymtab () | |
793 | { | |
794 | register struct partial_symtab *pst; | |
cba0d141 JG |
795 | register struct objfile *objfile; |
796 | ||
797 | for (objfile = object_files; objfile != NULL; objfile = objfile -> next) | |
798 | { | |
799 | for (pst = objfile -> psymtabs; pst; pst = pst->next) | |
800 | { | |
801 | if (lookup_partial_symbol (pst, "main", 1, VAR_NAMESPACE)) | |
802 | { | |
803 | return (pst); | |
804 | } | |
805 | } | |
806 | } | |
807 | return (NULL); | |
0e2a896c PB |
808 | } |
809 | ||
bd5635a1 RP |
810 | /* Look for a symbol in block BLOCK. */ |
811 | ||
812 | struct symbol * | |
813 | lookup_block_symbol (block, name, namespace) | |
cba0d141 JG |
814 | register const struct block *block; |
815 | const char *name; | |
816 | const enum namespace namespace; | |
bd5635a1 RP |
817 | { |
818 | register int bot, top, inc; | |
819 | register struct symbol *sym, *parameter_sym; | |
820 | ||
821 | top = BLOCK_NSYMS (block); | |
822 | bot = 0; | |
823 | ||
824 | /* If the blocks's symbols were sorted, start with a binary search. */ | |
825 | ||
826 | if (BLOCK_SHOULD_SORT (block)) | |
827 | { | |
828 | /* First, advance BOT to not far before | |
829 | the first symbol whose name is NAME. */ | |
830 | ||
831 | while (1) | |
832 | { | |
833 | inc = (top - bot + 1); | |
834 | /* No need to keep binary searching for the last few bits worth. */ | |
835 | if (inc < 4) | |
836 | break; | |
837 | inc = (inc >> 1) + bot; | |
838 | sym = BLOCK_SYM (block, inc); | |
839 | if (SYMBOL_NAME (sym)[0] < name[0]) | |
840 | bot = inc; | |
841 | else if (SYMBOL_NAME (sym)[0] > name[0]) | |
842 | top = inc; | |
843 | else if (strcmp (SYMBOL_NAME (sym), name) < 0) | |
844 | bot = inc; | |
845 | else | |
846 | top = inc; | |
847 | } | |
848 | ||
849 | /* Now scan forward until we run out of symbols, | |
850 | find one whose name is greater than NAME, | |
851 | or find one we want. | |
852 | If there is more than one symbol with the right name and namespace, | |
853 | we return the first one. dbxread.c is careful to make sure | |
854 | that if one is a register then it comes first. */ | |
855 | ||
856 | top = BLOCK_NSYMS (block); | |
857 | while (bot < top) | |
858 | { | |
859 | sym = BLOCK_SYM (block, bot); | |
860 | inc = SYMBOL_NAME (sym)[0] - name[0]; | |
861 | if (inc == 0) | |
862 | inc = strcmp (SYMBOL_NAME (sym), name); | |
863 | if (inc == 0 && SYMBOL_NAMESPACE (sym) == namespace) | |
864 | return sym; | |
865 | if (inc > 0) | |
866 | return 0; | |
867 | bot++; | |
868 | } | |
869 | return 0; | |
870 | } | |
871 | ||
872 | /* Here if block isn't sorted. | |
873 | This loop is equivalent to the loop above, | |
874 | but hacked greatly for speed. | |
875 | ||
876 | Note that parameter symbols do not always show up last in the | |
877 | list; this loop makes sure to take anything else other than | |
878 | parameter symbols first; it only uses parameter symbols as a | |
879 | last resort. Note that this only takes up extra computation | |
880 | time on a match. */ | |
881 | ||
882 | parameter_sym = (struct symbol *) 0; | |
883 | top = BLOCK_NSYMS (block); | |
884 | inc = name[0]; | |
885 | while (bot < top) | |
886 | { | |
887 | sym = BLOCK_SYM (block, bot); | |
888 | if (SYMBOL_NAME (sym)[0] == inc | |
889 | && !strcmp (SYMBOL_NAME (sym), name) | |
890 | && SYMBOL_NAMESPACE (sym) == namespace) | |
891 | { | |
892 | if (SYMBOL_CLASS (sym) == LOC_ARG | |
893 | || SYMBOL_CLASS (sym) == LOC_LOCAL_ARG | |
894 | || SYMBOL_CLASS (sym) == LOC_REF_ARG | |
895 | || SYMBOL_CLASS (sym) == LOC_REGPARM) | |
896 | parameter_sym = sym; | |
897 | else | |
898 | return sym; | |
899 | } | |
900 | bot++; | |
901 | } | |
902 | return parameter_sym; /* Will be 0 if not found. */ | |
903 | } | |
904 | \f | |
905 | /* Return the symbol for the function which contains a specified | |
906 | lexical block, described by a struct block BL. */ | |
907 | ||
908 | struct symbol * | |
909 | block_function (bl) | |
910 | struct block *bl; | |
911 | { | |
912 | while (BLOCK_FUNCTION (bl) == 0 && BLOCK_SUPERBLOCK (bl) != 0) | |
913 | bl = BLOCK_SUPERBLOCK (bl); | |
914 | ||
915 | return BLOCK_FUNCTION (bl); | |
916 | } | |
917 | ||
918 | /* Subroutine of find_pc_line */ | |
919 | ||
920 | struct symtab * | |
921 | find_pc_symtab (pc) | |
922 | register CORE_ADDR pc; | |
923 | { | |
924 | register struct block *b; | |
925 | struct blockvector *bv; | |
cba0d141 | 926 | register struct symtab *s = 0; |
bd5635a1 | 927 | register struct partial_symtab *ps; |
cba0d141 JG |
928 | register struct objfile *objfile; |
929 | register int found; | |
bd5635a1 RP |
930 | |
931 | /* Search all symtabs for one whose file contains our pc */ | |
932 | ||
cba0d141 JG |
933 | for (found = 0, objfile = object_files; |
934 | !found && objfile != NULL; | |
935 | objfile = objfile -> next) | |
bd5635a1 | 936 | { |
cba0d141 JG |
937 | for (s = objfile -> symtabs; s != NULL; s = s -> next) |
938 | { | |
939 | bv = BLOCKVECTOR (s); | |
940 | b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
941 | if (BLOCK_START (b) <= pc | |
942 | && BLOCK_END (b) > pc) | |
943 | { | |
944 | found++; | |
945 | break; | |
946 | } | |
947 | } | |
bd5635a1 RP |
948 | } |
949 | ||
950 | if (!s) | |
951 | { | |
952 | ps = find_pc_psymtab (pc); | |
953 | if (ps && ps->readin) | |
cba0d141 JG |
954 | { |
955 | printf_filtered ("(Internal error: pc 0x%x in read in psymtab, but not in symtab.)\n", pc); | |
956 | } | |
bd5635a1 | 957 | if (ps) |
cba0d141 JG |
958 | { |
959 | s = PSYMTAB_TO_SYMTAB (ps); | |
960 | } | |
bd5635a1 RP |
961 | } |
962 | ||
cba0d141 | 963 | return (s); |
bd5635a1 RP |
964 | } |
965 | ||
966 | /* Find the source file and line number for a given PC value. | |
967 | Return a structure containing a symtab pointer, a line number, | |
968 | and a pc range for the entire source line. | |
969 | The value's .pc field is NOT the specified pc. | |
970 | NOTCURRENT nonzero means, if specified pc is on a line boundary, | |
971 | use the line that ends there. Otherwise, in that case, the line | |
972 | that begins there is used. */ | |
973 | ||
974 | struct symtab_and_line | |
975 | find_pc_line (pc, notcurrent) | |
976 | CORE_ADDR pc; | |
977 | int notcurrent; | |
978 | { | |
979 | struct symtab *s; | |
980 | register struct linetable *l; | |
981 | register int len; | |
982 | register int i; | |
983 | register struct linetable_entry *item; | |
984 | struct symtab_and_line val; | |
985 | struct blockvector *bv; | |
986 | ||
987 | /* Info on best line seen so far, and where it starts, and its file. */ | |
988 | ||
989 | int best_line = 0; | |
990 | CORE_ADDR best_pc = 0; | |
991 | CORE_ADDR best_end = 0; | |
992 | struct symtab *best_symtab = 0; | |
993 | ||
994 | /* Store here the first line number | |
995 | of a file which contains the line at the smallest pc after PC. | |
996 | If we don't find a line whose range contains PC, | |
997 | we will use a line one less than this, | |
998 | with a range from the start of that file to the first line's pc. */ | |
999 | int alt_line = 0; | |
1000 | CORE_ADDR alt_pc = 0; | |
1001 | struct symtab *alt_symtab = 0; | |
1002 | ||
1003 | /* Info on best line seen in this file. */ | |
1004 | ||
1005 | int prev_line; | |
1006 | CORE_ADDR prev_pc; | |
1007 | ||
1008 | /* Info on first line of this file. */ | |
1009 | ||
1010 | int first_line; | |
1011 | CORE_ADDR first_pc; | |
1012 | ||
1013 | /* If this pc is not from the current frame, | |
1014 | it is the address of the end of a call instruction. | |
1015 | Quite likely that is the start of the following statement. | |
1016 | But what we want is the statement containing the instruction. | |
1017 | Fudge the pc to make sure we get that. */ | |
1018 | ||
1019 | if (notcurrent) pc -= 1; | |
1020 | ||
1021 | s = find_pc_symtab (pc); | |
1022 | if (s == 0) | |
1023 | { | |
1024 | val.symtab = 0; | |
1025 | val.line = 0; | |
1026 | val.pc = pc; | |
1027 | val.end = 0; | |
1028 | return val; | |
1029 | } | |
1030 | ||
1031 | bv = BLOCKVECTOR (s); | |
1032 | ||
1033 | /* Look at all the symtabs that share this blockvector. | |
1034 | They all have the same apriori range, that we found was right; | |
1035 | but they have different line tables. */ | |
1036 | ||
1037 | for (; s && BLOCKVECTOR (s) == bv; s = s->next) | |
1038 | { | |
1039 | /* Find the best line in this symtab. */ | |
1040 | l = LINETABLE (s); | |
4137c5fc JG |
1041 | if (!l) |
1042 | continue; | |
bd5635a1 RP |
1043 | len = l->nitems; |
1044 | prev_line = -1; | |
1045 | first_line = -1; | |
1046 | for (i = 0; i < len; i++) | |
1047 | { | |
1048 | item = &(l->item[i]); | |
1049 | ||
1050 | if (first_line < 0) | |
1051 | { | |
1052 | first_line = item->line; | |
1053 | first_pc = item->pc; | |
1054 | } | |
1055 | /* Return the last line that did not start after PC. */ | |
1056 | if (pc >= item->pc) | |
1057 | { | |
1058 | prev_line = item->line; | |
1059 | prev_pc = item->pc; | |
1060 | } | |
1061 | else | |
1062 | break; | |
1063 | } | |
1064 | ||
1065 | /* Is this file's best line closer than the best in the other files? | |
1066 | If so, record this file, and its best line, as best so far. */ | |
1067 | if (prev_line >= 0 && prev_pc > best_pc) | |
1068 | { | |
1069 | best_pc = prev_pc; | |
1070 | best_line = prev_line; | |
1071 | best_symtab = s; | |
cba0d141 JG |
1072 | /* If another line is in the linetable, and its PC is closer |
1073 | than the best_end we currently have, take it as best_end. */ | |
1074 | if (i < len && (best_end == 0 || best_end > item->pc)) | |
bd5635a1 | 1075 | best_end = item->pc; |
bd5635a1 RP |
1076 | } |
1077 | /* Is this file's first line closer than the first lines of other files? | |
1078 | If so, record this file, and its first line, as best alternate. */ | |
1079 | if (first_line >= 0 && first_pc > pc | |
1080 | && (alt_pc == 0 || first_pc < alt_pc)) | |
1081 | { | |
1082 | alt_pc = first_pc; | |
1083 | alt_line = first_line; | |
1084 | alt_symtab = s; | |
1085 | } | |
1086 | } | |
1087 | if (best_symtab == 0) | |
1088 | { | |
1089 | val.symtab = alt_symtab; | |
1090 | val.line = alt_line - 1; | |
3ba6a043 | 1091 | val.pc = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)); |
bd5635a1 RP |
1092 | val.end = alt_pc; |
1093 | } | |
1094 | else | |
1095 | { | |
1096 | val.symtab = best_symtab; | |
1097 | val.line = best_line; | |
1098 | val.pc = best_pc; | |
cba0d141 JG |
1099 | if (best_end && (alt_pc == 0 || best_end < alt_pc)) |
1100 | val.end = best_end; | |
1101 | else if (alt_pc) | |
1102 | val.end = alt_pc; | |
1103 | else | |
1104 | val.end = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)); | |
bd5635a1 RP |
1105 | } |
1106 | return val; | |
1107 | } | |
1108 | \f | |
1109 | /* Find the PC value for a given source file and line number. | |
1110 | Returns zero for invalid line number. | |
1111 | The source file is specified with a struct symtab. */ | |
1112 | ||
1113 | CORE_ADDR | |
1114 | find_line_pc (symtab, line) | |
1115 | struct symtab *symtab; | |
1116 | int line; | |
1117 | { | |
1118 | register struct linetable *l; | |
1119 | register int ind; | |
1120 | int dummy; | |
1121 | ||
1122 | if (symtab == 0) | |
1123 | return 0; | |
1124 | l = LINETABLE (symtab); | |
1125 | ind = find_line_common(l, line, &dummy); | |
b203fc18 | 1126 | return (ind >= 0) ? l->item[ind].pc : 0; |
bd5635a1 RP |
1127 | } |
1128 | ||
1129 | /* Find the range of pc values in a line. | |
1130 | Store the starting pc of the line into *STARTPTR | |
1131 | and the ending pc (start of next line) into *ENDPTR. | |
1132 | Returns 1 to indicate success. | |
1133 | Returns 0 if could not find the specified line. */ | |
1134 | ||
1135 | int | |
1136 | find_line_pc_range (symtab, thisline, startptr, endptr) | |
1137 | struct symtab *symtab; | |
1138 | int thisline; | |
1139 | CORE_ADDR *startptr, *endptr; | |
1140 | { | |
1141 | register struct linetable *l; | |
1142 | register int ind; | |
1143 | int exact_match; /* did we get an exact linenumber match */ | |
1144 | ||
1145 | if (symtab == 0) | |
1146 | return 0; | |
1147 | ||
1148 | l = LINETABLE (symtab); | |
1149 | ind = find_line_common (l, thisline, &exact_match); | |
b203fc18 | 1150 | if (ind >= 0) |
bd5635a1 RP |
1151 | { |
1152 | *startptr = l->item[ind].pc; | |
1153 | /* If we have not seen an entry for the specified line, | |
1154 | assume that means the specified line has zero bytes. */ | |
1155 | if (!exact_match || ind == l->nitems-1) | |
1156 | *endptr = *startptr; | |
1157 | else | |
1158 | /* Perhaps the following entry is for the following line. | |
1159 | It's worth a try. */ | |
1160 | if (ind+1 < l->nitems | |
1161 | && l->item[ind+1].line == thisline + 1) | |
1162 | *endptr = l->item[ind+1].pc; | |
1163 | else | |
1164 | *endptr = find_line_pc (symtab, thisline+1); | |
1165 | return 1; | |
1166 | } | |
1167 | ||
1168 | return 0; | |
1169 | } | |
1170 | ||
1171 | /* Given a line table and a line number, return the index into the line | |
1172 | table for the pc of the nearest line whose number is >= the specified one. | |
b203fc18 | 1173 | Return -1 if none is found. The value is >= 0 if it is an index. |
bd5635a1 RP |
1174 | |
1175 | Set *EXACT_MATCH nonzero if the value returned is an exact match. */ | |
1176 | ||
1177 | static int | |
1178 | find_line_common (l, lineno, exact_match) | |
1179 | register struct linetable *l; | |
1180 | register int lineno; | |
1181 | int *exact_match; | |
1182 | { | |
1183 | register int i; | |
1184 | register int len; | |
1185 | ||
1186 | /* BEST is the smallest linenumber > LINENO so far seen, | |
1187 | or 0 if none has been seen so far. | |
1188 | BEST_INDEX identifies the item for it. */ | |
1189 | ||
b203fc18 | 1190 | int best_index = -1; |
bd5635a1 RP |
1191 | int best = 0; |
1192 | ||
1193 | if (lineno <= 0) | |
b203fc18 | 1194 | return -1; |
4137c5fc JG |
1195 | if (l == 0) |
1196 | return -1; | |
bd5635a1 RP |
1197 | |
1198 | len = l->nitems; | |
1199 | for (i = 0; i < len; i++) | |
1200 | { | |
1201 | register struct linetable_entry *item = &(l->item[i]); | |
1202 | ||
1203 | if (item->line == lineno) | |
1204 | { | |
1205 | *exact_match = 1; | |
1206 | return i; | |
1207 | } | |
1208 | ||
1209 | if (item->line > lineno && (best == 0 || item->line < best)) | |
1210 | { | |
1211 | best = item->line; | |
1212 | best_index = i; | |
1213 | } | |
1214 | } | |
1215 | ||
1216 | /* If we got here, we didn't get an exact match. */ | |
1217 | ||
1218 | *exact_match = 0; | |
1219 | return best_index; | |
1220 | } | |
1221 | ||
1222 | int | |
1223 | find_pc_line_pc_range (pc, startptr, endptr) | |
1224 | CORE_ADDR pc; | |
1225 | CORE_ADDR *startptr, *endptr; | |
1226 | { | |
1227 | struct symtab_and_line sal; | |
1228 | sal = find_pc_line (pc, 0); | |
1229 | *startptr = sal.pc; | |
1230 | *endptr = sal.end; | |
1231 | return sal.symtab != 0; | |
1232 | } | |
1233 | \f | |
d96b54ea JK |
1234 | /* If P is of the form "operator[ \t]+..." where `...' is |
1235 | some legitimate operator text, return a pointer to the | |
1236 | beginning of the substring of the operator text. | |
1237 | Otherwise, return "". */ | |
1238 | static char * | |
1239 | operator_chars (p, end) | |
1240 | char *p; | |
1241 | char **end; | |
1242 | { | |
1243 | *end = ""; | |
1244 | if (strncmp (p, "operator", 8)) | |
1245 | return *end; | |
1246 | p += 8; | |
1247 | ||
1248 | /* Don't get faked out by `operator' being part of a longer | |
1249 | identifier. */ | |
1250 | if ((*p >= 'A' && *p <= 'Z') || (*p >= 'a' && *p <= 'z') | |
1251 | || *p == '_' || *p == '$' || *p == '\0') | |
1252 | return *end; | |
1253 | ||
1254 | /* Allow some whitespace between `operator' and the operator symbol. */ | |
1255 | while (*p == ' ' || *p == '\t') | |
1256 | p++; | |
1257 | ||
1258 | switch (*p) | |
1259 | { | |
1260 | case '!': | |
1261 | case '=': | |
1262 | case '*': | |
1263 | case '/': | |
1264 | case '%': | |
1265 | case '^': | |
1266 | if (p[1] == '=') | |
1267 | *end = p+2; | |
1268 | else | |
1269 | *end = p+1; | |
1270 | return p; | |
1271 | case '<': | |
1272 | case '>': | |
1273 | case '+': | |
1274 | case '-': | |
1275 | case '&': | |
1276 | case '|': | |
1277 | if (p[1] == '=' || p[1] == p[0]) | |
1278 | *end = p+2; | |
1279 | else | |
1280 | *end = p+1; | |
1281 | return p; | |
1282 | case '~': | |
1283 | case ',': | |
1284 | *end = p+1; | |
1285 | return p; | |
1286 | case '(': | |
1287 | if (p[1] != ')') | |
1288 | error ("`operator ()' must be specified without whitespace in `()'"); | |
1289 | *end = p+2; | |
1290 | return p; | |
1291 | case '?': | |
1292 | if (p[1] != ':') | |
1293 | error ("`operator ?:' must be specified without whitespace in `?:'"); | |
1294 | *end = p+2; | |
1295 | return p; | |
1296 | case '[': | |
1297 | if (p[1] != ']') | |
1298 | error ("`operator []' must be specified without whitespace in `[]'"); | |
1299 | *end = p+2; | |
1300 | return p; | |
1301 | default: | |
1302 | error ("`operator %s' not supported", p); | |
1303 | break; | |
1304 | } | |
1305 | *end = ""; | |
1306 | return *end; | |
1307 | } | |
1308 | ||
bd5635a1 RP |
1309 | /* Recursive helper function for decode_line_1. |
1310 | * Look for methods named NAME in type T. | |
1311 | * Return number of matches. | |
1312 | * Put matches in PHYSNAMES and SYM_ARR (which better be big enough!). | |
1313 | * These allocations seem to define "big enough": | |
1314 | * sym_arr = (struct symbol **) alloca(TYPE_NFN_FIELDS_TOTAL (t) * sizeof(struct symbol*)); | |
1315 | * physnames = (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t) * sizeof(char*)); | |
1316 | */ | |
1317 | ||
cba0d141 | 1318 | static int |
7e258d18 | 1319 | find_methods (t, name, physnames, sym_arr) |
bd5635a1 RP |
1320 | struct type *t; |
1321 | char *name; | |
1322 | char **physnames; | |
1323 | struct symbol **sym_arr; | |
1324 | { | |
1325 | int i1 = 0; | |
1326 | int ibase; | |
1327 | struct symbol *sym_class; | |
1328 | char *class_name = type_name_no_tag (t); | |
1329 | /* Ignore this class if it doesn't have a name. | |
1330 | This prevents core dumps, but is just a workaround | |
1331 | because we might not find the function in | |
1332 | certain cases, such as | |
1333 | struct D {virtual int f();} | |
1334 | struct C : D {virtual int g();} | |
1335 | (in this case g++ 1.35.1- does not put out a name | |
1336 | for D as such, it defines type 19 (for example) in | |
1337 | the same stab as C, and then does a | |
1338 | .stabs "D:T19" and a .stabs "D:t19". | |
1339 | Thus | |
1340 | "break C::f" should not be looking for field f in | |
1341 | the class named D, | |
1342 | but just for the field f in the baseclasses of C | |
1343 | (no matter what their names). | |
1344 | ||
1345 | However, I don't know how to replace the code below | |
1346 | that depends on knowing the name of D. */ | |
1347 | if (class_name | |
1348 | && (sym_class = lookup_symbol (class_name, | |
1349 | (struct block *)NULL, | |
1350 | STRUCT_NAMESPACE, | |
1351 | (int *)NULL, | |
1352 | (struct symtab **)NULL))) | |
1353 | { | |
1354 | int method_counter; | |
1355 | t = SYMBOL_TYPE (sym_class); | |
1356 | for (method_counter = TYPE_NFN_FIELDS (t) - 1; | |
1357 | method_counter >= 0; | |
1358 | --method_counter) | |
1359 | { | |
1360 | int field_counter; | |
1361 | struct fn_field *f = TYPE_FN_FIELDLIST1 (t, method_counter); | |
1362 | ||
1363 | char *method_name = TYPE_FN_FIELDLIST_NAME (t, method_counter); | |
1364 | if (!strcmp (name, method_name)) | |
1365 | /* Find all the fields with that name. */ | |
1366 | for (field_counter = TYPE_FN_FIELDLIST_LENGTH (t, method_counter) - 1; | |
1367 | field_counter >= 0; | |
1368 | --field_counter) | |
1369 | { | |
1370 | char *phys_name; | |
7e258d18 | 1371 | if (TYPE_FN_FIELD_STUB (f, field_counter)) |
bd5635a1 RP |
1372 | check_stub_method (t, method_counter, field_counter); |
1373 | phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter); | |
1374 | physnames[i1] = (char*) alloca (strlen (phys_name) + 1); | |
1375 | strcpy (physnames[i1], phys_name); | |
1376 | sym_arr[i1] = lookup_symbol (phys_name, | |
1377 | SYMBOL_BLOCK_VALUE (sym_class), | |
1378 | VAR_NAMESPACE, | |
1379 | (int *) NULL, | |
1380 | (struct symtab **) NULL); | |
1381 | if (sym_arr[i1]) i1++; | |
1382 | } | |
1383 | } | |
1384 | } | |
1385 | /* Only search baseclasses if there is no match yet, | |
1386 | * since names in derived classes override those in baseclasses. | |
1387 | */ | |
1388 | if (i1) | |
1389 | return i1; | |
1390 | for (ibase = 0; ibase < TYPE_N_BASECLASSES (t); ibase++) | |
1391 | i1 += find_methods(TYPE_BASECLASS(t, ibase), name, | |
1392 | physnames + i1, sym_arr + i1); | |
1393 | return i1; | |
1394 | } | |
1395 | ||
1396 | /* Parse a string that specifies a line number. | |
1397 | Pass the address of a char * variable; that variable will be | |
1398 | advanced over the characters actually parsed. | |
1399 | ||
1400 | The string can be: | |
1401 | ||
1402 | LINENUM -- that line number in current file. PC returned is 0. | |
1403 | FILE:LINENUM -- that line in that file. PC returned is 0. | |
1404 | FUNCTION -- line number of openbrace of that function. | |
1405 | PC returned is the start of the function. | |
1406 | VARIABLE -- line number of definition of that variable. | |
1407 | PC returned is 0. | |
1408 | FILE:FUNCTION -- likewise, but prefer functions in that file. | |
1409 | *EXPR -- line in which address EXPR appears. | |
1410 | ||
cba0d141 | 1411 | FUNCTION may be an undebuggable function found in minimal symbol table. |
bd5635a1 RP |
1412 | |
1413 | If the argument FUNFIRSTLINE is nonzero, we want the first line | |
1414 | of real code inside a function when a function is specified. | |
1415 | ||
1416 | DEFAULT_SYMTAB specifies the file to use if none is specified. | |
1417 | It defaults to current_source_symtab. | |
1418 | DEFAULT_LINE specifies the line number to use for relative | |
1419 | line numbers (that start with signs). Defaults to current_source_line. | |
1420 | ||
1421 | Note that it is possible to return zero for the symtab | |
1422 | if no file is validly specified. Callers must check that. | |
1423 | Also, the line number returned may be invalid. */ | |
1424 | ||
1425 | struct symtabs_and_lines | |
1426 | decode_line_1 (argptr, funfirstline, default_symtab, default_line) | |
1427 | char **argptr; | |
1428 | int funfirstline; | |
1429 | struct symtab *default_symtab; | |
1430 | int default_line; | |
1431 | { | |
bd5635a1 RP |
1432 | struct symtabs_and_lines values; |
1433 | struct symtab_and_line val; | |
1434 | register char *p, *p1; | |
d96b54ea | 1435 | char *q, *q1; |
bd5635a1 RP |
1436 | register struct symtab *s; |
1437 | ||
1438 | register struct symbol *sym; | |
1439 | /* The symtab that SYM was found in. */ | |
1440 | struct symtab *sym_symtab; | |
1441 | ||
1442 | register CORE_ADDR pc; | |
cba0d141 | 1443 | register struct minimal_symbol *msymbol; |
bd5635a1 RP |
1444 | char *copy; |
1445 | struct symbol *sym_class; | |
1446 | int i1; | |
1447 | struct symbol **sym_arr; | |
1448 | struct type *t; | |
1449 | char **physnames; | |
1450 | ||
1451 | /* Defaults have defaults. */ | |
1452 | ||
1453 | if (default_symtab == 0) | |
1454 | { | |
1455 | default_symtab = current_source_symtab; | |
1456 | default_line = current_source_line; | |
1457 | } | |
1458 | ||
1459 | /* See if arg is *PC */ | |
1460 | ||
1461 | if (**argptr == '*') | |
1462 | { | |
1463 | (*argptr)++; | |
1464 | pc = parse_and_eval_address_1 (argptr); | |
1465 | values.sals = (struct symtab_and_line *) | |
1466 | xmalloc (sizeof (struct symtab_and_line)); | |
1467 | values.nelts = 1; | |
1468 | values.sals[0] = find_pc_line (pc, 0); | |
1469 | values.sals[0].pc = pc; | |
1470 | return values; | |
1471 | } | |
1472 | ||
1473 | /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */ | |
1474 | ||
1475 | s = 0; | |
1476 | ||
1477 | for (p = *argptr; *p; p++) | |
1478 | { | |
1479 | if (p[0] == ':' || p[0] == ' ' || p[0] == '\t') | |
1480 | break; | |
1481 | } | |
1482 | while (p[0] == ' ' || p[0] == '\t') p++; | |
1483 | ||
1484 | if (p[0] == ':') | |
1485 | { | |
1486 | ||
1487 | /* C++ */ | |
1488 | if (p[1] ==':') | |
1489 | { | |
1490 | /* Extract the class name. */ | |
1491 | p1 = p; | |
1492 | while (p != *argptr && p[-1] == ' ') --p; | |
1493 | copy = (char *) alloca (p - *argptr + 1); | |
1494 | bcopy (*argptr, copy, p - *argptr); | |
1495 | copy[p - *argptr] = 0; | |
1496 | ||
1497 | /* Discard the class name from the arg. */ | |
1498 | p = p1 + 2; | |
1499 | while (*p == ' ' || *p == '\t') p++; | |
1500 | *argptr = p; | |
1501 | ||
1502 | sym_class = lookup_symbol (copy, 0, STRUCT_NAMESPACE, 0, | |
1503 | (struct symtab **)NULL); | |
1504 | ||
1505 | if (sym_class && | |
f1d77e90 | 1506 | ( TYPE_CODE (SYMBOL_TYPE (sym_class)) == TYPE_CODE_STRUCT |
bd5635a1 RP |
1507 | || TYPE_CODE (SYMBOL_TYPE (sym_class)) == TYPE_CODE_UNION)) |
1508 | { | |
1509 | /* Arg token is not digits => try it as a function name | |
1510 | Find the next token (everything up to end or next whitespace). */ | |
1511 | p = *argptr; | |
1512 | while (*p && *p != ' ' && *p != '\t' && *p != ',' && *p !=':') p++; | |
d96b54ea | 1513 | q = operator_chars (*argptr, &q1); |
aec4cb91 | 1514 | |
d96b54ea JK |
1515 | copy = (char *) alloca (p - *argptr + 1 + (q1 - q)); |
1516 | if (q1 - q) | |
1517 | { | |
1518 | copy[0] = 'o'; | |
1519 | copy[1] = 'p'; | |
1520 | copy[2] = CPLUS_MARKER; | |
1521 | bcopy (q, copy + 3, q1 - q); | |
1522 | copy[3 + (q1 - q)] = '\0'; | |
1523 | p = q1; | |
1524 | } | |
1525 | else | |
1526 | { | |
1527 | bcopy (*argptr, copy, p - *argptr); | |
1528 | copy[p - *argptr] = '\0'; | |
1529 | } | |
bd5635a1 RP |
1530 | |
1531 | /* no line number may be specified */ | |
1532 | while (*p == ' ' || *p == '\t') p++; | |
1533 | *argptr = p; | |
1534 | ||
1535 | sym = 0; | |
1536 | i1 = 0; /* counter for the symbol array */ | |
1537 | t = SYMBOL_TYPE (sym_class); | |
1538 | sym_arr = (struct symbol **) alloca(TYPE_NFN_FIELDS_TOTAL (t) * sizeof(struct symbol*)); | |
1539 | physnames = (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t) * sizeof(char*)); | |
1540 | ||
1541 | if (destructor_name_p (copy, t)) | |
1542 | { | |
1543 | /* destructors are a special case. */ | |
1544 | struct fn_field *f = TYPE_FN_FIELDLIST1 (t, 0); | |
1545 | int len = TYPE_FN_FIELDLIST_LENGTH (t, 0) - 1; | |
1546 | char *phys_name = TYPE_FN_FIELD_PHYSNAME (f, len); | |
1547 | physnames[i1] = (char *)alloca (strlen (phys_name) + 1); | |
1548 | strcpy (physnames[i1], phys_name); | |
1549 | sym_arr[i1] = | |
1550 | lookup_symbol (phys_name, SYMBOL_BLOCK_VALUE (sym_class), | |
1551 | VAR_NAMESPACE, 0, (struct symtab **)NULL); | |
1552 | if (sym_arr[i1]) i1++; | |
1553 | } | |
1554 | else | |
1555 | i1 = find_methods (t, copy, physnames, sym_arr); | |
1556 | if (i1 == 1) | |
1557 | { | |
1558 | /* There is exactly one field with that name. */ | |
1559 | sym = sym_arr[0]; | |
1560 | ||
1561 | if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK) | |
1562 | { | |
1563 | /* Arg is the name of a function */ | |
1564 | pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) + FUNCTION_START_OFFSET; | |
1565 | if (funfirstline) | |
1566 | SKIP_PROLOGUE (pc); | |
1567 | values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line)); | |
1568 | values.nelts = 1; | |
1569 | values.sals[0] = find_pc_line (pc, 0); | |
1570 | values.sals[0].pc = (values.sals[0].end && values.sals[0].pc != pc) ? values.sals[0].end : pc; | |
1571 | } | |
1572 | else | |
1573 | { | |
1574 | values.nelts = 0; | |
1575 | } | |
1576 | return values; | |
1577 | } | |
1578 | if (i1 > 0) | |
1579 | { | |
1580 | /* There is more than one field with that name | |
1581 | (overloaded). Ask the user which one to use. */ | |
1582 | return decode_line_2 (sym_arr, i1, funfirstline); | |
1583 | } | |
1584 | else | |
d96b54ea JK |
1585 | { |
1586 | char *tmp; | |
1587 | ||
1588 | if (OPNAME_PREFIX_P (copy)) | |
1589 | { | |
1590 | tmp = (char *)alloca (strlen (copy+3) + 9); | |
1591 | strcpy (tmp, "operator "); | |
1592 | strcat (tmp, copy+3); | |
1593 | } | |
1594 | else | |
1595 | tmp = copy; | |
0e2a896c PB |
1596 | if (tmp[0] == '~') |
1597 | error ("The class `%s' does not have destructor defined", | |
1598 | sym_class->name); | |
1599 | else | |
1600 | error ("The class %s does not have any method named %s", | |
1601 | sym_class->name, tmp); | |
d96b54ea | 1602 | } |
bd5635a1 RP |
1603 | } |
1604 | else | |
1605 | /* The quotes are important if copy is empty. */ | |
1606 | error("No class, struct, or union named \"%s\"", copy ); | |
1607 | } | |
1608 | /* end of C++ */ | |
1609 | ||
1610 | ||
1611 | /* Extract the file name. */ | |
1612 | p1 = p; | |
1613 | while (p != *argptr && p[-1] == ' ') --p; | |
58050209 DHW |
1614 | copy = (char *) alloca (p - *argptr + 1); |
1615 | bcopy (*argptr, copy, p - *argptr); | |
1616 | copy[p - *argptr] = 0; | |
bd5635a1 RP |
1617 | |
1618 | /* Find that file's data. */ | |
1619 | s = lookup_symtab (copy); | |
1620 | if (s == 0) | |
1621 | { | |
cba0d141 | 1622 | if (!have_full_symbols () && !have_partial_symbols ()) |
bd5635a1 RP |
1623 | error (no_symtab_msg); |
1624 | error ("No source file named %s.", copy); | |
1625 | } | |
1626 | ||
1627 | /* Discard the file name from the arg. */ | |
1628 | p = p1 + 1; | |
1629 | while (*p == ' ' || *p == '\t') p++; | |
1630 | *argptr = p; | |
1631 | } | |
1632 | ||
1633 | /* S is specified file's symtab, or 0 if no file specified. | |
1634 | arg no longer contains the file name. */ | |
1635 | ||
1636 | /* Check whether arg is all digits (and sign) */ | |
1637 | ||
1638 | p = *argptr; | |
1639 | if (*p == '-' || *p == '+') p++; | |
1640 | while (*p >= '0' && *p <= '9') | |
1641 | p++; | |
1642 | ||
1643 | if (p != *argptr && (*p == 0 || *p == ' ' || *p == '\t' || *p == ',')) | |
1644 | { | |
1645 | /* We found a token consisting of all digits -- at least one digit. */ | |
1646 | enum sign {none, plus, minus} sign = none; | |
1647 | ||
1648 | /* This is where we need to make sure that we have good defaults. | |
1649 | We must guarantee that this section of code is never executed | |
1650 | when we are called with just a function name, since | |
1651 | select_source_symtab calls us with such an argument */ | |
1652 | ||
1653 | if (s == 0 && default_symtab == 0) | |
1654 | { | |
bd5635a1 RP |
1655 | select_source_symtab (0); |
1656 | default_symtab = current_source_symtab; | |
1657 | default_line = current_source_line; | |
1658 | } | |
1659 | ||
1660 | if (**argptr == '+') | |
1661 | sign = plus, (*argptr)++; | |
1662 | else if (**argptr == '-') | |
1663 | sign = minus, (*argptr)++; | |
1664 | val.line = atoi (*argptr); | |
1665 | switch (sign) | |
1666 | { | |
1667 | case plus: | |
1668 | if (p == *argptr) | |
1669 | val.line = 5; | |
1670 | if (s == 0) | |
1671 | val.line = default_line + val.line; | |
1672 | break; | |
1673 | case minus: | |
1674 | if (p == *argptr) | |
1675 | val.line = 15; | |
1676 | if (s == 0) | |
1677 | val.line = default_line - val.line; | |
1678 | else | |
1679 | val.line = 1; | |
1680 | break; | |
1681 | case none: | |
1682 | break; /* No need to adjust val.line. */ | |
1683 | } | |
1684 | ||
1685 | while (*p == ' ' || *p == '\t') p++; | |
1686 | *argptr = p; | |
1687 | if (s == 0) | |
1688 | s = default_symtab; | |
1689 | val.symtab = s; | |
1690 | val.pc = 0; | |
1691 | values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line)); | |
1692 | values.sals[0] = val; | |
1693 | values.nelts = 1; | |
1694 | return values; | |
1695 | } | |
1696 | ||
1697 | /* Arg token is not digits => try it as a variable name | |
1698 | Find the next token (everything up to end or next whitespace). */ | |
1699 | p = *argptr; | |
1700 | while (*p && *p != ' ' && *p != '\t' && *p != ',') p++; | |
1701 | copy = (char *) alloca (p - *argptr + 1); | |
1702 | bcopy (*argptr, copy, p - *argptr); | |
1703 | copy[p - *argptr] = 0; | |
1704 | while (*p == ' ' || *p == '\t') p++; | |
1705 | *argptr = p; | |
1706 | ||
1707 | /* Look up that token as a variable. | |
1708 | If file specified, use that file's per-file block to start with. */ | |
1709 | ||
1710 | sym = lookup_symbol (copy, | |
3ba6a043 | 1711 | (s ? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK) |
bd5635a1 RP |
1712 | : get_selected_block ()), |
1713 | VAR_NAMESPACE, 0, &sym_symtab); | |
1714 | ||
1715 | if (sym != NULL) | |
1716 | { | |
1717 | if (SYMBOL_CLASS (sym) == LOC_BLOCK) | |
1718 | { | |
1719 | /* Arg is the name of a function */ | |
1720 | pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) + FUNCTION_START_OFFSET; | |
1721 | if (funfirstline) | |
1722 | SKIP_PROLOGUE (pc); | |
1723 | val = find_pc_line (pc, 0); | |
1724 | #ifdef PROLOGUE_FIRSTLINE_OVERLAP | |
1725 | /* Convex: no need to suppress code on first line, if any */ | |
1726 | val.pc = pc; | |
1727 | #else | |
7b2a87ca JG |
1728 | /* If SKIP_PROLOGUE left us in mid-line, and the next line is still |
1729 | part of the same function: | |
1730 | advance to next line, | |
1731 | recalculate its line number (might not be N+1). */ | |
1732 | if (val.pc != pc && val.end && | |
cba0d141 | 1733 | lookup_minimal_symbol_by_pc (pc) == lookup_minimal_symbol_by_pc (val.end)) { |
7b2a87ca JG |
1734 | pc = val.end; /* First pc of next line */ |
1735 | val = find_pc_line (pc, 0); | |
1736 | } | |
1737 | val.pc = pc; | |
bd5635a1 RP |
1738 | #endif |
1739 | values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line)); | |
1740 | values.sals[0] = val; | |
1741 | values.nelts = 1; | |
1742 | ||
1743 | /* I think this is always the same as the line that | |
1744 | we calculate above, but the general principle is | |
1745 | "trust the symbols more than stuff like | |
1746 | SKIP_PROLOGUE". */ | |
1747 | if (SYMBOL_LINE (sym) != 0) | |
1748 | values.sals[0].line = SYMBOL_LINE (sym); | |
1749 | ||
1750 | return values; | |
1751 | } | |
1752 | else if (SYMBOL_LINE (sym) != 0) | |
1753 | { | |
1754 | /* We know its line number. */ | |
1755 | values.sals = (struct symtab_and_line *) | |
1756 | xmalloc (sizeof (struct symtab_and_line)); | |
1757 | values.nelts = 1; | |
1758 | bzero (&values.sals[0], sizeof (values.sals[0])); | |
1759 | values.sals[0].symtab = sym_symtab; | |
1760 | values.sals[0].line = SYMBOL_LINE (sym); | |
1761 | return values; | |
1762 | } | |
1763 | else | |
1764 | /* This can happen if it is compiled with a compiler which doesn't | |
1765 | put out line numbers for variables. */ | |
1766 | error ("Line number not known for symbol \"%s\"", copy); | |
1767 | } | |
1768 | ||
cba0d141 JG |
1769 | msymbol = lookup_minimal_symbol (copy, (struct objfile *) NULL); |
1770 | if (msymbol != NULL) | |
bd5635a1 RP |
1771 | { |
1772 | val.symtab = 0; | |
1773 | val.line = 0; | |
cba0d141 | 1774 | val.pc = msymbol -> address + FUNCTION_START_OFFSET; |
bd5635a1 RP |
1775 | if (funfirstline) |
1776 | SKIP_PROLOGUE (val.pc); | |
1777 | values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line)); | |
1778 | values.sals[0] = val; | |
1779 | values.nelts = 1; | |
1780 | return values; | |
1781 | } | |
1782 | ||
cba0d141 JG |
1783 | if (!have_full_symbols () && |
1784 | !have_partial_symbols () && !have_minimal_symbols ()) | |
997a978c JG |
1785 | error (no_symtab_msg); |
1786 | ||
bd5635a1 RP |
1787 | error ("Function %s not defined.", copy); |
1788 | return values; /* for lint */ | |
1789 | } | |
1790 | ||
1791 | struct symtabs_and_lines | |
1792 | decode_line_spec (string, funfirstline) | |
1793 | char *string; | |
1794 | int funfirstline; | |
1795 | { | |
1796 | struct symtabs_and_lines sals; | |
1797 | if (string == 0) | |
1798 | error ("Empty line specification."); | |
1799 | sals = decode_line_1 (&string, funfirstline, | |
1800 | current_source_symtab, current_source_line); | |
1801 | if (*string) | |
1802 | error ("Junk at end of line specification: %s", string); | |
1803 | return sals; | |
1804 | } | |
1805 | ||
1806 | /* Given a list of NELTS symbols in sym_arr (with corresponding | |
1807 | mangled names in physnames), return a list of lines to operate on | |
1808 | (ask user if necessary). */ | |
cba0d141 | 1809 | static struct symtabs_and_lines |
bd5635a1 RP |
1810 | decode_line_2 (sym_arr, nelts, funfirstline) |
1811 | struct symbol *sym_arr[]; | |
1812 | int nelts; | |
1813 | int funfirstline; | |
1814 | { | |
bd5635a1 RP |
1815 | struct symtabs_and_lines values, return_values; |
1816 | register CORE_ADDR pc; | |
cba0d141 | 1817 | char *args, *arg1; |
bd5635a1 RP |
1818 | int i; |
1819 | char *prompt; | |
1820 | ||
1821 | values.sals = (struct symtab_and_line *) alloca (nelts * sizeof(struct symtab_and_line)); | |
1822 | return_values.sals = (struct symtab_and_line *) xmalloc (nelts * sizeof(struct symtab_and_line)); | |
1823 | ||
1824 | i = 0; | |
1825 | printf("[0] cancel\n[1] all\n"); | |
1826 | while (i < nelts) | |
1827 | { | |
1828 | if (sym_arr[i] && SYMBOL_CLASS (sym_arr[i]) == LOC_BLOCK) | |
1829 | { | |
1830 | /* Arg is the name of a function */ | |
1831 | pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym_arr[i])) | |
1832 | + FUNCTION_START_OFFSET; | |
1833 | if (funfirstline) | |
1834 | SKIP_PROLOGUE (pc); | |
1835 | values.sals[i] = find_pc_line (pc, 0); | |
1836 | values.sals[i].pc = (values.sals[i].end && values.sals[i].pc != pc) ? | |
1837 | values.sals[i].end : pc; | |
1838 | printf("[%d] file:%s; line number:%d\n", | |
1839 | (i+2), values.sals[i].symtab->filename, values.sals[i].line); | |
1840 | } | |
1841 | else printf ("?HERE\n"); | |
1842 | i++; | |
1843 | } | |
1844 | ||
1845 | if ((prompt = getenv ("PS2")) == NULL) | |
1846 | { | |
1847 | prompt = ">"; | |
1848 | } | |
1849 | printf("%s ",prompt); | |
1850 | fflush(stdout); | |
1851 | ||
cba0d141 | 1852 | args = command_line_input ((char *) NULL, 0); |
bd5635a1 RP |
1853 | |
1854 | if (args == 0) | |
1855 | error_no_arg ("one or more choice numbers"); | |
1856 | ||
1857 | i = 0; | |
1858 | while (*args) | |
1859 | { | |
1860 | int num; | |
1861 | ||
1862 | arg1 = args; | |
1863 | while (*arg1 >= '0' && *arg1 <= '9') arg1++; | |
1864 | if (*arg1 && *arg1 != ' ' && *arg1 != '\t') | |
1865 | error ("Arguments must be choice numbers."); | |
1866 | ||
1867 | num = atoi (args); | |
1868 | ||
1869 | if (num == 0) | |
1870 | error ("cancelled"); | |
1871 | else if (num == 1) | |
1872 | { | |
1873 | bcopy (values.sals, return_values.sals, (nelts * sizeof(struct symtab_and_line))); | |
1874 | return_values.nelts = nelts; | |
1875 | return return_values; | |
1876 | } | |
1877 | ||
1878 | if (num > nelts + 2) | |
1879 | { | |
1880 | printf ("No choice number %d.\n", num); | |
1881 | } | |
1882 | else | |
1883 | { | |
1884 | num -= 2; | |
1885 | if (values.sals[num].pc) | |
1886 | { | |
1887 | return_values.sals[i++] = values.sals[num]; | |
1888 | values.sals[num].pc = 0; | |
1889 | } | |
1890 | else | |
1891 | { | |
1892 | printf ("duplicate request for %d ignored.\n", num); | |
1893 | } | |
1894 | } | |
1895 | ||
1896 | args = arg1; | |
1897 | while (*args == ' ' || *args == '\t') args++; | |
1898 | } | |
1899 | return_values.nelts = i; | |
1900 | return return_values; | |
1901 | } | |
1902 | ||
bd5635a1 RP |
1903 | \f |
1904 | /* Slave routine for sources_info. Force line breaks at ,'s. | |
1905 | NAME is the name to print and *FIRST is nonzero if this is the first | |
1906 | name printed. Set *FIRST to zero. */ | |
1907 | static void | |
1908 | output_source_filename (name, first) | |
1909 | char *name; | |
1910 | int *first; | |
1911 | { | |
cba0d141 | 1912 | static unsigned int column; |
bd5635a1 RP |
1913 | /* Table of files printed so far. Since a single source file can |
1914 | result in several partial symbol tables, we need to avoid printing | |
1915 | it more than once. Note: if some of the psymtabs are read in and | |
1916 | some are not, it gets printed both under "Source files for which | |
1917 | symbols have been read" and "Source files for which symbols will | |
1918 | be read in on demand". I consider this a reasonable way to deal | |
1919 | with the situation. I'm not sure whether this can also happen for | |
1920 | symtabs; it doesn't hurt to check. */ | |
1921 | static char **tab = NULL; | |
1922 | /* Allocated size of tab in elements. | |
1923 | Start with one 256-byte block (when using GNU malloc.c). | |
1924 | 24 is the malloc overhead when range checking is in effect. */ | |
1925 | static int tab_alloc_size = (256 - 24) / sizeof (char *); | |
1926 | /* Current size of tab in elements. */ | |
1927 | static int tab_cur_size; | |
1928 | ||
1929 | char **p; | |
1930 | ||
1931 | if (*first) | |
1932 | { | |
1933 | if (tab == NULL) | |
1934 | tab = (char **) xmalloc (tab_alloc_size * sizeof (*tab)); | |
1935 | tab_cur_size = 0; | |
1936 | } | |
1937 | ||
1938 | /* Is NAME in tab? */ | |
1939 | for (p = tab; p < tab + tab_cur_size; p++) | |
1940 | if (strcmp (*p, name) == 0) | |
1941 | /* Yes; don't print it again. */ | |
1942 | return; | |
1943 | /* No; add it to tab. */ | |
1944 | if (tab_cur_size == tab_alloc_size) | |
1945 | { | |
1946 | tab_alloc_size *= 2; | |
cba0d141 | 1947 | tab = (char **) xrealloc ((char *) tab, tab_alloc_size * sizeof (*tab)); |
bd5635a1 RP |
1948 | } |
1949 | tab[tab_cur_size++] = name; | |
1950 | ||
1951 | if (*first) | |
1952 | { | |
1953 | column = 0; | |
1954 | *first = 0; | |
1955 | } | |
1956 | else | |
1957 | { | |
1958 | printf_filtered (","); | |
1959 | column++; | |
1960 | } | |
1961 | ||
1962 | if (column != 0 && column + strlen (name) >= 70) | |
1963 | { | |
1964 | printf_filtered ("\n"); | |
1965 | column = 0; | |
1966 | } | |
1967 | else if (column != 0) | |
1968 | { | |
1969 | printf_filtered (" "); | |
1970 | column++; | |
1971 | } | |
1972 | fputs_filtered (name, stdout); | |
1973 | column += strlen (name); | |
1974 | } | |
1975 | ||
1976 | static void | |
1977 | sources_info () | |
1978 | { | |
1979 | register struct symtab *s; | |
1980 | register struct partial_symtab *ps; | |
cba0d141 | 1981 | register struct objfile *objfile; |
bd5635a1 RP |
1982 | int first; |
1983 | ||
cba0d141 | 1984 | if (!have_full_symbols () && !have_partial_symbols ()) |
bd5635a1 | 1985 | { |
3053b9f2 | 1986 | error (no_symtab_msg); |
bd5635a1 RP |
1987 | } |
1988 | ||
1989 | printf_filtered ("Source files for which symbols have been read in:\n\n"); | |
1990 | ||
1991 | first = 1; | |
cba0d141 JG |
1992 | for (objfile = object_files; objfile != NULL; objfile = objfile -> next) |
1993 | { | |
1994 | for (s = objfile -> symtabs; s != NULL; s = s -> next) | |
1995 | { | |
1996 | output_source_filename (s -> filename, &first); | |
1997 | } | |
1998 | } | |
bd5635a1 RP |
1999 | printf_filtered ("\n\n"); |
2000 | ||
2001 | printf_filtered ("Source files for which symbols will be read in on demand:\n\n"); | |
2002 | ||
2003 | first = 1; | |
cba0d141 JG |
2004 | for (objfile = object_files; objfile != NULL; objfile = objfile -> next) |
2005 | { | |
2006 | for (ps = objfile -> psymtabs; ps != NULL; ps = ps -> next) | |
2007 | { | |
2008 | if (!ps->readin) | |
2009 | { | |
2010 | output_source_filename (ps -> filename, &first); | |
2011 | } | |
2012 | } | |
2013 | } | |
bd5635a1 RP |
2014 | printf_filtered ("\n"); |
2015 | } | |
2016 | ||
2017 | /* List all symbols (if REGEXP is 0) or all symbols matching REGEXP. | |
2018 | If CLASS is zero, list all symbols except functions and type names. | |
2019 | If CLASS is 1, list only functions. | |
2020 | If CLASS is 2, list only type names. | |
997a978c | 2021 | If CLASS is 3, list only method names. |
bd5635a1 RP |
2022 | |
2023 | BPT is non-zero if we should set a breakpoint at the functions | |
2024 | we find. */ | |
2025 | ||
2026 | static void | |
2027 | list_symbols (regexp, class, bpt) | |
2028 | char *regexp; | |
2029 | int class; | |
2030 | int bpt; | |
2031 | { | |
2032 | register struct symtab *s; | |
2033 | register struct partial_symtab *ps; | |
2034 | register struct blockvector *bv; | |
2035 | struct blockvector *prev_bv = 0; | |
2036 | register struct block *b; | |
2037 | register int i, j; | |
2038 | register struct symbol *sym; | |
2039 | struct partial_symbol *psym; | |
cba0d141 JG |
2040 | struct objfile *objfile; |
2041 | struct minimal_symbol *msymbol; | |
bd5635a1 RP |
2042 | char *val; |
2043 | static char *classnames[] | |
2044 | = {"variable", "function", "type", "method"}; | |
2045 | int found_in_file = 0; | |
997a978c | 2046 | int found_misc = 0; |
cba0d141 JG |
2047 | static enum minimal_symbol_type types[] |
2048 | = {mst_data, mst_text, mst_abs, mst_unknown}; | |
2049 | static enum minimal_symbol_type types2[] | |
2050 | = {mst_bss, mst_text, mst_abs, mst_unknown}; | |
2051 | enum minimal_symbol_type ourtype = types[class]; | |
2052 | enum minimal_symbol_type ourtype2 = types2[class]; | |
bd5635a1 RP |
2053 | |
2054 | if (regexp) | |
d11c44f1 | 2055 | if (0 != (val = re_comp (regexp))) |
bd5635a1 RP |
2056 | error ("Invalid regexp (%s): %s", val, regexp); |
2057 | ||
cba0d141 | 2058 | /* Search through the partial symtabs *first* for all symbols |
bd5635a1 RP |
2059 | matching the regexp. That way we don't have to reproduce all of |
2060 | the machinery below. */ | |
bd5635a1 | 2061 | |
cba0d141 JG |
2062 | for (objfile = object_files; objfile != NULL; objfile = objfile -> next) |
2063 | { | |
2064 | for (ps = objfile -> psymtabs; ps != NULL; ps = ps -> next) | |
bd5635a1 | 2065 | { |
cba0d141 JG |
2066 | struct partial_symbol *bound, *gbound, *sbound; |
2067 | int keep_going = 1; | |
2068 | ||
2069 | if (ps->readin) continue; | |
2070 | ||
2071 | gbound = objfile->global_psymbols.list + ps->globals_offset + ps->n_global_syms; | |
2072 | sbound = objfile->static_psymbols.list + ps->statics_offset + ps->n_static_syms; | |
2073 | bound = gbound; | |
2074 | ||
2075 | /* Go through all of the symbols stored in a partial | |
2076 | symtab in one loop. */ | |
2077 | psym = objfile->global_psymbols.list + ps->globals_offset; | |
2078 | while (keep_going) | |
bd5635a1 | 2079 | { |
cba0d141 | 2080 | if (psym >= bound) |
bd5635a1 | 2081 | { |
cba0d141 JG |
2082 | if (bound == gbound && ps->n_static_syms != 0) |
2083 | { | |
2084 | psym = objfile->static_psymbols.list + ps->statics_offset; | |
2085 | bound = sbound; | |
2086 | } | |
2087 | else | |
2088 | keep_going = 0; | |
2089 | continue; | |
bd5635a1 RP |
2090 | } |
2091 | else | |
bd5635a1 | 2092 | { |
cba0d141 JG |
2093 | QUIT; |
2094 | ||
2095 | /* If it would match (logic taken from loop below) | |
2096 | load the file and go on to the next one */ | |
2097 | if ((regexp == 0 || re_exec (SYMBOL_NAME (psym))) | |
2098 | && ((class == 0 && SYMBOL_CLASS (psym) != LOC_TYPEDEF | |
2099 | && SYMBOL_CLASS (psym) != LOC_BLOCK) | |
2100 | || (class == 1 && SYMBOL_CLASS (psym) == LOC_BLOCK) | |
2101 | || (class == 2 && SYMBOL_CLASS (psym) == LOC_TYPEDEF) | |
2102 | || (class == 3 && SYMBOL_CLASS (psym) == LOC_BLOCK))) | |
2103 | { | |
2104 | (void) PSYMTAB_TO_SYMTAB(ps); | |
2105 | keep_going = 0; | |
2106 | } | |
bd5635a1 | 2107 | } |
cba0d141 | 2108 | psym++; |
bd5635a1 | 2109 | } |
bd5635a1 RP |
2110 | } |
2111 | } | |
2112 | ||
cba0d141 | 2113 | /* Here, we search through the minimal symbol tables for functions that |
bd5635a1 RP |
2114 | match, and call find_pc_symtab on them to force their symbols to |
2115 | be read. The symbol will then be found during the scan of symtabs | |
997a978c JG |
2116 | below. If find_pc_symtab fails, set found_misc so that we will |
2117 | rescan to print any matching symbols without debug info. */ | |
2118 | ||
cba0d141 JG |
2119 | if (class == 1) |
2120 | { | |
2121 | for (objfile = object_files; objfile != NULL; objfile = objfile -> next) | |
2122 | { | |
2123 | for (msymbol = objfile -> msymbols; | |
2124 | msymbol -> name != NULL; msymbol++) | |
2125 | { | |
2126 | if (msymbol -> type == ourtype || msymbol -> type == ourtype2) | |
2127 | { | |
2128 | if (regexp == 0 || re_exec (msymbol -> name)) | |
2129 | { | |
2130 | if (0 == find_pc_symtab (msymbol -> address)) | |
2131 | { | |
2132 | found_misc = 1; | |
2133 | } | |
2134 | } | |
2135 | } | |
2136 | } | |
2137 | } | |
bd5635a1 RP |
2138 | } |
2139 | ||
2140 | /* Printout here so as to get after the "Reading in symbols" | |
2141 | messages which will be generated above. */ | |
2142 | if (!bpt) | |
2143 | printf_filtered (regexp | |
2144 | ? "All %ss matching regular expression \"%s\":\n" | |
2145 | : "All defined %ss:\n", | |
2146 | classnames[class], | |
2147 | regexp); | |
2148 | ||
cba0d141 | 2149 | for (objfile = object_files; objfile != NULL; objfile = objfile -> next) |
bd5635a1 | 2150 | { |
cba0d141 JG |
2151 | for (s = objfile -> symtabs; s != NULL; s = s -> next) |
2152 | { | |
2153 | found_in_file = 0; | |
2154 | bv = BLOCKVECTOR (s); | |
2155 | /* Often many files share a blockvector. | |
2156 | Scan each blockvector only once so that | |
2157 | we don't get every symbol many times. | |
2158 | It happens that the first symtab in the list | |
2159 | for any given blockvector is the main file. */ | |
2160 | if (bv != prev_bv) | |
2161 | for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++) | |
bd5635a1 | 2162 | { |
cba0d141 JG |
2163 | b = BLOCKVECTOR_BLOCK (bv, i); |
2164 | /* Skip the sort if this block is always sorted. */ | |
2165 | if (!BLOCK_SHOULD_SORT (b)) | |
2166 | sort_block_syms (b); | |
2167 | for (j = 0; j < BLOCK_NSYMS (b); j++) | |
bd5635a1 | 2168 | { |
cba0d141 JG |
2169 | QUIT; |
2170 | sym = BLOCK_SYM (b, j); | |
2171 | if ((regexp == 0 || re_exec (SYMBOL_NAME (sym))) | |
2172 | && ((class == 0 && SYMBOL_CLASS (sym) != LOC_TYPEDEF | |
2173 | && SYMBOL_CLASS (sym) != LOC_BLOCK) | |
2174 | || (class == 1 && SYMBOL_CLASS (sym) == LOC_BLOCK) | |
2175 | || (class == 2 && SYMBOL_CLASS (sym) == LOC_TYPEDEF) | |
2176 | || (class == 3 && SYMBOL_CLASS (sym) == LOC_BLOCK))) | |
bd5635a1 | 2177 | { |
cba0d141 JG |
2178 | if (bpt) |
2179 | { | |
2180 | /* Set a breakpoint here, if it's a function */ | |
2181 | if (class == 1) | |
2182 | break_command (SYMBOL_NAME(sym), 0); | |
2183 | } | |
2184 | else if (!found_in_file) | |
2185 | { | |
2186 | fputs_filtered ("\nFile ", stdout); | |
2187 | fputs_filtered (s->filename, stdout); | |
2188 | fputs_filtered (":\n", stdout); | |
2189 | } | |
2190 | found_in_file = 1; | |
2191 | ||
2192 | if (class != 2 && i == STATIC_BLOCK) | |
2193 | printf_filtered ("static "); | |
2194 | ||
2195 | /* Typedef that is not a C++ class */ | |
2196 | if (class == 2 | |
2197 | && SYMBOL_NAMESPACE (sym) != STRUCT_NAMESPACE) | |
2198 | typedef_print (SYMBOL_TYPE(sym), sym, stdout); | |
2199 | /* variable, func, or typedef-that-is-c++-class */ | |
2200 | else if (class < 2 || | |
2201 | (class == 2 && | |
2202 | SYMBOL_NAMESPACE(sym) == STRUCT_NAMESPACE)) | |
2203 | { | |
2204 | type_print (SYMBOL_TYPE (sym), | |
2205 | (SYMBOL_CLASS (sym) == LOC_TYPEDEF | |
2206 | ? "" : SYMBOL_NAME (sym)), | |
2207 | stdout, 0); | |
2208 | ||
2209 | printf_filtered (";\n"); | |
2210 | } | |
2211 | else | |
2212 | { | |
bd5635a1 | 2213 | # if 0 |
cba0d141 JG |
2214 | char buf[1024]; |
2215 | type_print_base (TYPE_FN_FIELD_TYPE(t, i), stdout, 0, 0); | |
2216 | type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t, i), stdout, 0); | |
2217 | sprintf (buf, " %s::", type_name_no_tag (t)); | |
2218 | type_print_method_args (TYPE_FN_FIELD_ARGS (t, i), buf, name, stdout); | |
bd5635a1 | 2219 | # endif |
cba0d141 | 2220 | } |
bd5635a1 RP |
2221 | } |
2222 | } | |
2223 | } | |
cba0d141 JG |
2224 | prev_bv = bv; |
2225 | } | |
bd5635a1 | 2226 | } |
997a978c | 2227 | |
997a978c | 2228 | /* If there are no eyes, avoid all contact. I mean, if there are |
cba0d141 JG |
2229 | no debug symbols, then print directly from the msymbol_vector. */ |
2230 | ||
2231 | if (found_misc || class != 1) | |
2232 | { | |
2233 | found_in_file = 0; | |
2234 | for (objfile = object_files; objfile != NULL; objfile = objfile -> next) | |
2235 | { | |
2236 | for (msymbol = objfile -> msymbols; | |
2237 | msymbol -> name != NULL; msymbol++) | |
2238 | { | |
2239 | if (msymbol -> type == ourtype || msymbol -> type == ourtype2) | |
2240 | { | |
2241 | if (regexp == 0 || re_exec (msymbol -> name)) | |
2242 | { | |
2243 | /* Functions: Look up by address. */ | |
2244 | if (class != 1 && | |
2245 | (find_pc_symtab (msymbol -> address) != NULL)) | |
2246 | { | |
2247 | /* Variables/Absolutes: Look up by name */ | |
2248 | if (lookup_symbol (msymbol -> name, | |
2249 | (struct block *) 0, VAR_NAMESPACE, 0, | |
2250 | (struct symtab **) 0) == NULL) | |
2251 | { | |
2252 | if (!found_in_file) | |
2253 | { | |
2254 | printf_filtered ("\nNon-debugging symbols:\n"); | |
2255 | found_in_file = 1; | |
2256 | } | |
2257 | printf_filtered (" %08x %s\n", | |
2258 | msymbol -> address, | |
2259 | msymbol -> name); | |
2260 | } | |
2261 | } | |
2262 | } | |
2263 | } | |
2264 | } | |
997a978c | 2265 | } |
997a978c | 2266 | } |
bd5635a1 RP |
2267 | } |
2268 | ||
2269 | static void | |
2270 | variables_info (regexp) | |
2271 | char *regexp; | |
2272 | { | |
2273 | list_symbols (regexp, 0, 0); | |
2274 | } | |
2275 | ||
2276 | static void | |
2277 | functions_info (regexp) | |
2278 | char *regexp; | |
2279 | { | |
2280 | list_symbols (regexp, 1, 0); | |
2281 | } | |
2282 | ||
bd5635a1 RP |
2283 | static void |
2284 | types_info (regexp) | |
2285 | char *regexp; | |
2286 | { | |
2287 | list_symbols (regexp, 2, 0); | |
2288 | } | |
bd5635a1 RP |
2289 | |
2290 | #if 0 | |
2291 | /* Tiemann says: "info methods was never implemented." */ | |
2292 | static void | |
2293 | methods_info (regexp) | |
2294 | char *regexp; | |
2295 | { | |
2296 | list_symbols (regexp, 3, 0); | |
2297 | } | |
2298 | #endif /* 0 */ | |
2299 | ||
2300 | /* Breakpoint all functions matching regular expression. */ | |
2301 | static void | |
2302 | rbreak_command (regexp) | |
2303 | char *regexp; | |
2304 | { | |
2305 | list_symbols (regexp, 1, 1); | |
2306 | } | |
2307 | \f | |
bd5635a1 RP |
2308 | |
2309 | /* Return Nonzero if block a is lexically nested within block b, | |
2310 | or if a and b have the same pc range. | |
2311 | Return zero otherwise. */ | |
2312 | int | |
2313 | contained_in (a, b) | |
2314 | struct block *a, *b; | |
2315 | { | |
2316 | if (!a || !b) | |
2317 | return 0; | |
2318 | return BLOCK_START (a) >= BLOCK_START (b) | |
2319 | && BLOCK_END (a) <= BLOCK_END (b); | |
2320 | } | |
2321 | ||
2322 | \f | |
2323 | /* Helper routine for make_symbol_completion_list. */ | |
2324 | ||
2325 | int return_val_size, return_val_index; | |
2326 | char **return_val; | |
2327 | ||
cba0d141 | 2328 | static void |
bd5635a1 RP |
2329 | completion_list_add_symbol (symname) |
2330 | char *symname; | |
2331 | { | |
2332 | if (return_val_index + 3 > return_val_size) | |
cba0d141 JG |
2333 | return_val = (char **) xrealloc ((char *) return_val, |
2334 | (return_val_size *= 2) * sizeof (char *)); | |
bd5635a1 RP |
2335 | |
2336 | return_val[return_val_index] = | |
2337 | (char *)xmalloc (1 + strlen (symname)); | |
2338 | ||
2339 | strcpy (return_val[return_val_index], symname); | |
2340 | ||
2341 | return_val[++return_val_index] = (char *)NULL; | |
2342 | } | |
2343 | ||
2344 | /* Return a NULL terminated array of all symbols (regardless of class) which | |
2345 | begin by matching TEXT. If the answer is no symbols, then the return value | |
2346 | is an array which contains only a NULL pointer. | |
2347 | ||
2348 | Problem: All of the symbols have to be copied because readline | |
2349 | frees them. I'm not going to worry about this; hopefully there | |
2350 | won't be that many. */ | |
2351 | ||
2352 | char ** | |
2353 | make_symbol_completion_list (text) | |
2354 | char *text; | |
2355 | { | |
2356 | register struct symtab *s; | |
2357 | register struct partial_symtab *ps; | |
cba0d141 JG |
2358 | register struct minimal_symbol *msymbol; |
2359 | register struct objfile *objfile; | |
bd5635a1 | 2360 | register struct block *b, *surrounding_static_block = 0; |
bd5635a1 RP |
2361 | register int i, j; |
2362 | struct partial_symbol *psym; | |
2363 | ||
2364 | int text_len = strlen (text); | |
2365 | return_val_size = 100; | |
2366 | return_val_index = 0; | |
2367 | return_val = | |
2368 | (char **)xmalloc ((1 + return_val_size) *sizeof (char *)); | |
2369 | return_val[0] = (char *)NULL; | |
2370 | ||
2371 | /* Look through the partial symtabs for all symbols which begin | |
2372 | by matching TEXT. Add each one that you find to the list. */ | |
2373 | ||
cba0d141 | 2374 | for (objfile = object_files; objfile != NULL; objfile = objfile -> next) |
bd5635a1 | 2375 | { |
cba0d141 | 2376 | for (ps = objfile -> psymtabs; ps != NULL; ps = ps -> next) |
bd5635a1 | 2377 | { |
cba0d141 JG |
2378 | /* If the psymtab's been read in we'll get it when we search |
2379 | through the blockvector. */ | |
2380 | if (ps->readin) continue; | |
2381 | ||
2382 | for (psym = objfile->global_psymbols.list + ps->globals_offset; | |
2383 | psym < (objfile->global_psymbols.list + ps->globals_offset | |
2384 | + ps->n_global_syms); | |
2385 | psym++) | |
2386 | { | |
2387 | QUIT; /* If interrupted, then quit. */ | |
2388 | if ((strncmp (SYMBOL_NAME (psym), text, text_len) == 0)) | |
2389 | completion_list_add_symbol (SYMBOL_NAME (psym)); | |
2390 | } | |
2391 | ||
2392 | for (psym = objfile->static_psymbols.list + ps->statics_offset; | |
2393 | psym < (objfile->static_psymbols.list + ps->statics_offset | |
2394 | + ps->n_static_syms); | |
2395 | psym++) | |
2396 | { | |
2397 | QUIT; | |
2398 | if ((strncmp (SYMBOL_NAME (psym), text, text_len) == 0)) | |
2399 | completion_list_add_symbol (SYMBOL_NAME (psym)); | |
2400 | } | |
bd5635a1 RP |
2401 | } |
2402 | } | |
2403 | ||
cba0d141 | 2404 | /* At this point scan through the misc symbol vectors and add each |
bd5635a1 RP |
2405 | symbol you find to the list. Eventually we want to ignore |
2406 | anything that isn't a text symbol (everything else will be | |
2407 | handled by the psymtab code above). */ | |
2408 | ||
cba0d141 JG |
2409 | for (objfile = object_files; objfile != NULL; objfile = objfile -> next) |
2410 | { | |
2411 | for (msymbol = objfile -> msymbols; | |
2412 | msymbol ->name != NULL; msymbol++) | |
2413 | { | |
2414 | if (strncmp (text, msymbol -> name, text_len) == 0) | |
2415 | { | |
2416 | completion_list_add_symbol (msymbol -> name); | |
2417 | } | |
2418 | } | |
2419 | } | |
bd5635a1 RP |
2420 | |
2421 | /* Search upwards from currently selected frame (so that we can | |
2422 | complete on local vars. */ | |
2423 | for (b = get_selected_block (); b; b = BLOCK_SUPERBLOCK (b)) | |
2424 | { | |
2425 | if (!BLOCK_SUPERBLOCK (b)) | |
2426 | surrounding_static_block = b; /* For elmin of dups */ | |
2427 | ||
2428 | /* Also catch fields of types defined in this places which | |
2429 | match our text string. Only complete on types visible | |
2430 | from current context. */ | |
2431 | for (i = 0; i < BLOCK_NSYMS (b); i++) | |
2432 | { | |
2433 | register struct symbol *sym = BLOCK_SYM (b, i); | |
2434 | ||
2435 | if (!strncmp (SYMBOL_NAME (sym), text, text_len)) | |
2436 | completion_list_add_symbol (SYMBOL_NAME (sym)); | |
2437 | ||
2438 | if (SYMBOL_CLASS (sym) == LOC_TYPEDEF) | |
2439 | { | |
2440 | struct type *t = SYMBOL_TYPE (sym); | |
2441 | enum type_code c = TYPE_CODE (t); | |
2442 | ||
2443 | if (c == TYPE_CODE_UNION || c == TYPE_CODE_STRUCT) | |
2444 | for (j = TYPE_N_BASECLASSES (t); j < TYPE_NFIELDS (t); j++) | |
2445 | if (TYPE_FIELD_NAME (t, j) && | |
2446 | !strncmp (TYPE_FIELD_NAME (t, j), text, text_len)) | |
2447 | completion_list_add_symbol (TYPE_FIELD_NAME (t, j)); | |
2448 | } | |
2449 | } | |
2450 | } | |
2451 | ||
2452 | /* Go through the symtabs and check the externs and statics for | |
2453 | symbols which match. */ | |
2454 | ||
cba0d141 | 2455 | for (objfile = object_files; objfile != NULL; objfile = objfile -> next) |
bd5635a1 | 2456 | { |
cba0d141 JG |
2457 | for (s = objfile ->symtabs; s != NULL; s = s -> next) |
2458 | { | |
2459 | b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK); | |
2460 | ||
2461 | for (i = 0; i < BLOCK_NSYMS (b); i++) | |
2462 | if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b, i)), text, text_len)) | |
2463 | completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b, i))); | |
2464 | } | |
bd5635a1 RP |
2465 | } |
2466 | ||
cba0d141 | 2467 | for (objfile = object_files; objfile != NULL; objfile = objfile -> next) |
bd5635a1 | 2468 | { |
cba0d141 JG |
2469 | for (s = objfile -> symtabs; s != NULL; s = s -> next) |
2470 | { | |
2471 | b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK); | |
2472 | ||
2473 | /* Don't do this block twice. */ | |
2474 | if (b == surrounding_static_block) continue; | |
2475 | ||
2476 | for (i = 0; i < BLOCK_NSYMS (b); i++) | |
2477 | if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b, i)), text, text_len)) | |
2478 | completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b, i))); | |
2479 | } | |
bd5635a1 RP |
2480 | } |
2481 | ||
2482 | return (return_val); | |
2483 | } | |
2484 | \f | |
997a978c JG |
2485 | #if 0 |
2486 | /* Add the type of the symbol sym to the type of the current | |
2487 | function whose block we are in (assumed). The type of | |
2488 | this current function is contained in *TYPE. | |
2489 | ||
2490 | This basically works as follows: When we find a function | |
2491 | symbol (N_FUNC with a 'f' or 'F' in the symbol name), we record | |
2492 | a pointer to its type in the global in_function_type. Every | |
2493 | time we come across a parameter symbol ('p' in its name), then | |
2494 | this procedure adds the name and type of that parameter | |
2495 | to the function type pointed to by *TYPE. (Which should correspond | |
2496 | to in_function_type if it was called correctly). | |
2497 | ||
2498 | Note that since we are modifying a type, the result of | |
2499 | lookup_function_type() should be bcopy()ed before calling | |
2500 | this. When not in strict typing mode, the expression | |
2501 | evaluator can choose to ignore this. | |
2502 | ||
2503 | Assumption: All of a function's parameter symbols will | |
2504 | appear before another function symbol is found. The parameters | |
2505 | appear in the same order in the argument list as they do in the | |
2506 | symbol table. */ | |
2507 | ||
2508 | void | |
2509 | add_param_to_type (type,sym) | |
2510 | struct type **type; | |
2511 | struct symbol *sym; | |
2512 | { | |
2513 | int num = ++(TYPE_NFIELDS(*type)); | |
2514 | ||
2515 | if(TYPE_NFIELDS(*type)-1) | |
cba0d141 JG |
2516 | TYPE_FIELDS(*type) = (struct field *) |
2517 | (*current_objfile->xrealloc) ((char *)(TYPE_FIELDS(*type)), | |
2518 | num*sizeof(struct field)); | |
997a978c | 2519 | else |
cba0d141 JG |
2520 | TYPE_FIELDS(*type) = (struct field *) |
2521 | (*current_objfile->xmalloc) (num*sizeof(struct field)); | |
997a978c JG |
2522 | |
2523 | TYPE_FIELD_BITPOS(*type,num-1) = num-1; | |
2524 | TYPE_FIELD_BITSIZE(*type,num-1) = 0; | |
2525 | TYPE_FIELD_TYPE(*type,num-1) = SYMBOL_TYPE(sym); | |
2526 | TYPE_FIELD_NAME(*type,num-1) = SYMBOL_NAME(sym); | |
2527 | } | |
2528 | #endif | |
2529 | \f | |
bd5635a1 RP |
2530 | void |
2531 | _initialize_symtab () | |
2532 | { | |
2533 | add_info ("variables", variables_info, | |
2534 | "All global and static variable names, or those matching REGEXP."); | |
2535 | add_info ("functions", functions_info, | |
2536 | "All function names, or those matching REGEXP."); | |
3ba6a043 JG |
2537 | |
2538 | /* FIXME: This command has at least the following problems: | |
bd5635a1 RP |
2539 | 1. It prints builtin types (in a very strange and confusing fashion). |
2540 | 2. It doesn't print right, e.g. with | |
2541 | typedef struct foo *FOO | |
2542 | type_print prints "FOO" when we want to make it (in this situation) | |
2543 | print "struct foo *". | |
2544 | I also think "ptype" or "whatis" is more likely to be useful (but if | |
2545 | there is much disagreement "info types" can be fixed). */ | |
2546 | add_info ("types", types_info, | |
a0a6174a | 2547 | "All type names, or those matching REGEXP."); |
3ba6a043 | 2548 | |
bd5635a1 RP |
2549 | #if 0 |
2550 | add_info ("methods", methods_info, | |
2551 | "All method names, or those matching REGEXP::REGEXP.\n\ | |
2552 | If the class qualifier is ommited, it is assumed to be the current scope.\n\ | |
cba0d141 | 2553 | If the first REGEXP is omitted, then all methods matching the second REGEXP\n\ |
bd5635a1 RP |
2554 | are listed."); |
2555 | #endif | |
2556 | add_info ("sources", sources_info, | |
2557 | "Source files in the program."); | |
2558 | ||
2559 | add_com ("rbreak", no_class, rbreak_command, | |
2560 | "Set a breakpoint for all functions matching REGEXP."); | |
2561 | ||
997a978c | 2562 | /* Initialize the one built-in type that isn't language dependent... */ |
cba0d141 JG |
2563 | builtin_type_error = init_type (TYPE_CODE_ERROR, 0, 0, |
2564 | "<unknown type>", (struct objfile *) NULL); | |
bd5635a1 | 2565 | } |