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