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