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