* remote.c (remote_wait): Fix cast on signal() call.
[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);
1497 bcopy (*argptr, copy, p - *argptr);
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));
d96b54ea
JK
1538 bcopy (*argptr, copy, p - *argptr);
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
DHW
1632 copy = (char *) alloca (p - *argptr + 1);
1633 bcopy (*argptr, copy, p - *argptr);
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
RP
1719 copy = (char *) alloca (p - *argptr + 1);
1720 bcopy (*argptr, copy, 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;
1787 bzero (&values.sals[0], sizeof (values.sals[0]));
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 {
1902 bcopy (values.sals, return_values.sals, (nelts * sizeof(struct symtab_and_line)));
1903 return_values.nelts = nelts;
1904 return return_values;
1905 }
1906
1907 if (num > nelts + 2)
1908 {
1909 printf ("No choice number %d.\n", num);
1910 }
1911 else
1912 {
1913 num -= 2;
1914 if (values.sals[num].pc)
1915 {
1916 return_values.sals[i++] = values.sals[num];
1917 values.sals[num].pc = 0;
1918 }
1919 else
1920 {
1921 printf ("duplicate request for %d ignored.\n", num);
1922 }
1923 }
1924
1925 args = arg1;
1926 while (*args == ' ' || *args == '\t') args++;
1927 }
1928 return_values.nelts = i;
1929 return return_values;
1930}
1931
bd5635a1
RP
1932\f
1933/* Slave routine for sources_info. Force line breaks at ,'s.
1934 NAME is the name to print and *FIRST is nonzero if this is the first
1935 name printed. Set *FIRST to zero. */
1936static void
1937output_source_filename (name, first)
1938 char *name;
1939 int *first;
1940{
bd5635a1
RP
1941 /* Table of files printed so far. Since a single source file can
1942 result in several partial symbol tables, we need to avoid printing
1943 it more than once. Note: if some of the psymtabs are read in and
1944 some are not, it gets printed both under "Source files for which
1945 symbols have been read" and "Source files for which symbols will
1946 be read in on demand". I consider this a reasonable way to deal
1947 with the situation. I'm not sure whether this can also happen for
1948 symtabs; it doesn't hurt to check. */
1949 static char **tab = NULL;
1950 /* Allocated size of tab in elements.
1951 Start with one 256-byte block (when using GNU malloc.c).
1952 24 is the malloc overhead when range checking is in effect. */
1953 static int tab_alloc_size = (256 - 24) / sizeof (char *);
1954 /* Current size of tab in elements. */
1955 static int tab_cur_size;
1956
1957 char **p;
1958
1959 if (*first)
1960 {
1961 if (tab == NULL)
1962 tab = (char **) xmalloc (tab_alloc_size * sizeof (*tab));
1963 tab_cur_size = 0;
1964 }
1965
1966 /* Is NAME in tab? */
1967 for (p = tab; p < tab + tab_cur_size; p++)
1968 if (strcmp (*p, name) == 0)
1969 /* Yes; don't print it again. */
1970 return;
1971 /* No; add it to tab. */
1972 if (tab_cur_size == tab_alloc_size)
1973 {
1974 tab_alloc_size *= 2;
cba0d141 1975 tab = (char **) xrealloc ((char *) tab, tab_alloc_size * sizeof (*tab));
bd5635a1
RP
1976 }
1977 tab[tab_cur_size++] = name;
1978
1979 if (*first)
1980 {
bd5635a1
RP
1981 *first = 0;
1982 }
1983 else
1984 {
f70be3e4 1985 printf_filtered (", ");
bd5635a1
RP
1986 }
1987
f70be3e4 1988 wrap_here ("");
bd5635a1 1989 fputs_filtered (name, stdout);
bd5635a1
RP
1990}
1991
1992static void
35a25840
SG
1993sources_info (ignore, from_tty)
1994 char *ignore;
1995 int from_tty;
bd5635a1
RP
1996{
1997 register struct symtab *s;
1998 register struct partial_symtab *ps;
cba0d141 1999 register struct objfile *objfile;
bd5635a1
RP
2000 int first;
2001
cba0d141 2002 if (!have_full_symbols () && !have_partial_symbols ())
bd5635a1 2003 {
3053b9f2 2004 error (no_symtab_msg);
bd5635a1
RP
2005 }
2006
2007 printf_filtered ("Source files for which symbols have been read in:\n\n");
2008
2009 first = 1;
35a25840 2010 ALL_SYMTABS (objfile, s)
cba0d141 2011 {
35a25840 2012 output_source_filename (s -> filename, &first);
cba0d141 2013 }
bd5635a1
RP
2014 printf_filtered ("\n\n");
2015
2016 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2017
2018 first = 1;
35a25840 2019 ALL_PSYMTABS (objfile, ps)
cba0d141 2020 {
35a25840 2021 if (!ps->readin)
cba0d141 2022 {
35a25840 2023 output_source_filename (ps -> filename, &first);
cba0d141
JG
2024 }
2025 }
bd5635a1
RP
2026 printf_filtered ("\n");
2027}
2028
2cd99985 2029static int
f70be3e4 2030name_match (name)
2cd99985
PB
2031 char *name;
2032{
f70be3e4 2033 char *demangled = cplus_demangle (name, 0);
2cd99985
PB
2034 if (demangled != NULL)
2035 {
2036 int cond = re_exec (demangled);
2037 free (demangled);
f70be3e4 2038 return (cond);
2cd99985 2039 }
f70be3e4 2040 return (re_exec (name));
2cd99985
PB
2041}
2042#define NAME_MATCH(NAME) name_match(NAME)
2043
bd5635a1
RP
2044/* List all symbols (if REGEXP is 0) or all symbols matching REGEXP.
2045 If CLASS is zero, list all symbols except functions and type names.
2046 If CLASS is 1, list only functions.
2047 If CLASS is 2, list only type names.
997a978c 2048 If CLASS is 3, list only method names.
bd5635a1
RP
2049
2050 BPT is non-zero if we should set a breakpoint at the functions
2051 we find. */
2052
2053static void
2054list_symbols (regexp, class, bpt)
2055 char *regexp;
2056 int class;
2057 int bpt;
2058{
2059 register struct symtab *s;
2060 register struct partial_symtab *ps;
2061 register struct blockvector *bv;
2062 struct blockvector *prev_bv = 0;
2063 register struct block *b;
2064 register int i, j;
2065 register struct symbol *sym;
2066 struct partial_symbol *psym;
cba0d141
JG
2067 struct objfile *objfile;
2068 struct minimal_symbol *msymbol;
35a25840 2069 char *val;
bd5635a1
RP
2070 static char *classnames[]
2071 = {"variable", "function", "type", "method"};
2072 int found_in_file = 0;
997a978c 2073 int found_misc = 0;
cba0d141
JG
2074 static enum minimal_symbol_type types[]
2075 = {mst_data, mst_text, mst_abs, mst_unknown};
2076 static enum minimal_symbol_type types2[]
2077 = {mst_bss, mst_text, mst_abs, mst_unknown};
2078 enum minimal_symbol_type ourtype = types[class];
2079 enum minimal_symbol_type ourtype2 = types2[class];
bd5635a1
RP
2080
2081 if (regexp)
2cd99985
PB
2082 {
2083 /* Make sure spacing is right for C++ operators.
2084 This is just a courtesy to make the matching less sensitive
2085 to how many spaces the user leaves between 'operator'
2086 and <TYPENAME> or <OPERATOR>. */
2087 char *opend;
2088 char *opname = operator_chars (regexp, &opend);
2089 if (*opname)
2090 {
2091 int fix = -1; /* -1 means ok; otherwise number of spaces needed. */
2092 if (isalpha(*opname) || *opname == '_' || *opname == '$')
2093 {
2094 /* There should 1 space between 'operator' and 'TYPENAME'. */
2095 if (opname[-1] != ' ' || opname[-2] == ' ')
2096 fix = 1;
2097 }
2098 else
2099 {
2100 /* There should 0 spaces between 'operator' and 'OPERATOR'. */
2101 if (opname[-1] == ' ')
2102 fix = 0;
2103 }
2104 /* If wrong number of spaces, fix it. */
2105 if (fix >= 0)
2106 {
2107 char *tmp = (char*) alloca(opend-opname+10);
2108 sprintf(tmp, "operator%.*s%s", fix, " ", opname);
2109 regexp = tmp;
2110 }
2111 }
2112
2113 if (0 != (val = re_comp (regexp)))
2114 error ("Invalid regexp (%s): %s", val, regexp);
2115 }
bd5635a1 2116
cba0d141 2117 /* Search through the partial symtabs *first* for all symbols
bd5635a1
RP
2118 matching the regexp. That way we don't have to reproduce all of
2119 the machinery below. */
bd5635a1 2120
35a25840 2121 ALL_PSYMTABS (objfile, ps)
cba0d141 2122 {
35a25840
SG
2123 struct partial_symbol *bound, *gbound, *sbound;
2124 int keep_going = 1;
2125
2126 if (ps->readin) continue;
2127
2128 gbound = objfile->global_psymbols.list + ps->globals_offset + ps->n_global_syms;
2129 sbound = objfile->static_psymbols.list + ps->statics_offset + ps->n_static_syms;
2130 bound = gbound;
2131
2132 /* Go through all of the symbols stored in a partial
2133 symtab in one loop. */
2134 psym = objfile->global_psymbols.list + ps->globals_offset;
2135 while (keep_going)
bd5635a1 2136 {
35a25840 2137 if (psym >= bound)
bd5635a1 2138 {
35a25840 2139 if (bound == gbound && ps->n_static_syms != 0)
bd5635a1 2140 {
35a25840
SG
2141 psym = objfile->static_psymbols.list + ps->statics_offset;
2142 bound = sbound;
bd5635a1
RP
2143 }
2144 else
35a25840
SG
2145 keep_going = 0;
2146 continue;
2147 }
2148 else
2149 {
2150 QUIT;
2151
2152 /* If it would match (logic taken from loop below)
2153 load the file and go on to the next one */
2154 if ((regexp == 0 || NAME_MATCH (SYMBOL_NAME (psym)))
2155 && ((class == 0 && SYMBOL_CLASS (psym) != LOC_TYPEDEF
2156 && SYMBOL_CLASS (psym) != LOC_BLOCK)
2157 || (class == 1 && SYMBOL_CLASS (psym) == LOC_BLOCK)
2158 || (class == 2 && SYMBOL_CLASS (psym) == LOC_TYPEDEF)
2159 || (class == 3 && SYMBOL_CLASS (psym) == LOC_BLOCK)))
bd5635a1 2160 {
35a25840
SG
2161 (void) PSYMTAB_TO_SYMTAB(ps);
2162 keep_going = 0;
bd5635a1
RP
2163 }
2164 }
35a25840 2165 psym++;
bd5635a1
RP
2166 }
2167 }
2168
cba0d141 2169 /* Here, we search through the minimal symbol tables for functions that
bd5635a1
RP
2170 match, and call find_pc_symtab on them to force their symbols to
2171 be read. The symbol will then be found during the scan of symtabs
997a978c
JG
2172 below. If find_pc_symtab fails, set found_misc so that we will
2173 rescan to print any matching symbols without debug info. */
2174
cba0d141
JG
2175 if (class == 1)
2176 {
35a25840 2177 ALL_MSYMBOLS (objfile, msymbol)
cba0d141 2178 {
35a25840 2179 if (msymbol -> type == ourtype || msymbol -> type == ourtype2)
cba0d141 2180 {
35a25840 2181 if (regexp == 0 || NAME_MATCH (msymbol -> name))
cba0d141 2182 {
35a25840 2183 if (0 == find_pc_symtab (msymbol -> address))
cba0d141 2184 {
35a25840 2185 found_misc = 1;
cba0d141
JG
2186 }
2187 }
2188 }
2189 }
bd5635a1
RP
2190 }
2191
2192 /* Printout here so as to get after the "Reading in symbols"
2193 messages which will be generated above. */
2194 if (!bpt)
2195 printf_filtered (regexp
2196 ? "All %ss matching regular expression \"%s\":\n"
2197 : "All defined %ss:\n",
2198 classnames[class],
2199 regexp);
2200
35a25840 2201 ALL_SYMTABS (objfile, s)
bd5635a1 2202 {
35a25840
SG
2203 found_in_file = 0;
2204 bv = BLOCKVECTOR (s);
2205 /* Often many files share a blockvector.
2206 Scan each blockvector only once so that
2207 we don't get every symbol many times.
2208 It happens that the first symtab in the list
2209 for any given blockvector is the main file. */
2210 if (bv != prev_bv)
2211 for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
2212 {
2213 b = BLOCKVECTOR_BLOCK (bv, i);
2214 /* Skip the sort if this block is always sorted. */
2215 if (!BLOCK_SHOULD_SORT (b))
2216 sort_block_syms (b);
2217 for (j = 0; j < BLOCK_NSYMS (b); j++)
bd5635a1 2218 {
35a25840
SG
2219 QUIT;
2220 sym = BLOCK_SYM (b, j);
2221 if ((regexp == 0 || NAME_MATCH (SYMBOL_NAME (sym)))
2222 && ((class == 0 && SYMBOL_CLASS (sym) != LOC_TYPEDEF
2223 && SYMBOL_CLASS (sym) != LOC_BLOCK)
2224 || (class == 1 && SYMBOL_CLASS (sym) == LOC_BLOCK)
2225 || (class == 2 && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
2226 || (class == 3 && SYMBOL_CLASS (sym) == LOC_BLOCK)))
bd5635a1 2227 {
35a25840 2228 if (bpt)
bd5635a1 2229 {
35a25840
SG
2230 /* Set a breakpoint here, if it's a function */
2231 if (class == 1)
2232 break_command (SYMBOL_NAME(sym), 0);
2233 }
2234 else if (!found_in_file)
2235 {
2236 fputs_filtered ("\nFile ", stdout);
2237 fputs_filtered (s->filename, stdout);
2238 fputs_filtered (":\n", stdout);
2239 }
2240 found_in_file = 1;
2241
2242 if (class != 2 && i == STATIC_BLOCK)
2243 printf_filtered ("static ");
2244
2245 /* Typedef that is not a C++ class */
2246 if (class == 2
2247 && SYMBOL_NAMESPACE (sym) != STRUCT_NAMESPACE)
2248 typedef_print (SYMBOL_TYPE(sym), sym, stdout);
2249 /* variable, func, or typedef-that-is-c++-class */
2250 else if (class < 2 ||
2251 (class == 2 &&
2252 SYMBOL_NAMESPACE(sym) == STRUCT_NAMESPACE))
2253 {
2254 type_print (SYMBOL_TYPE (sym),
2255 (SYMBOL_CLASS (sym) == LOC_TYPEDEF
2256 ? "" : SYMBOL_NAME (sym)),
2257 stdout, 0);
cba0d141 2258
35a25840
SG
2259 printf_filtered (";\n");
2260 }
2261 else
2262 {
bd5635a1 2263# if 0
35a25840
SG
2264/* FIXME, why is this zapped out? */
2265 char buf[1024];
2266 type_print_base (TYPE_FN_FIELD_TYPE(t, i), stdout, 0, 0);
2267 type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t, i), stdout, 0);
2268 sprintf (buf, " %s::", type_name_no_tag (t));
2269 type_print_method_args (TYPE_FN_FIELD_ARGS (t, i), buf, name, stdout);
bd5635a1
RP
2270# endif
2271 }
2272 }
2273 }
35a25840
SG
2274 }
2275 prev_bv = bv;
bd5635a1 2276 }
997a978c 2277
997a978c 2278 /* If there are no eyes, avoid all contact. I mean, if there are
cba0d141
JG
2279 no debug symbols, then print directly from the msymbol_vector. */
2280
2281 if (found_misc || class != 1)
2282 {
2283 found_in_file = 0;
35a25840 2284 ALL_MSYMBOLS (objfile, msymbol)
cba0d141 2285 {
35a25840 2286 if (msymbol -> type == ourtype || msymbol -> type == ourtype2)
cba0d141 2287 {
35a25840 2288 if (regexp == 0 || NAME_MATCH (msymbol -> name))
cba0d141 2289 {
35a25840 2290 /* Functions: Look up by address. */
f70be3e4
JG
2291 if (class != 1 ||
2292 (0 == find_pc_symtab (msymbol -> address)))
cba0d141 2293 {
35a25840
SG
2294 /* Variables/Absolutes: Look up by name */
2295 if (lookup_symbol (msymbol -> name,
2296 (struct block *) 0, VAR_NAMESPACE, 0,
2297 (struct symtab **) 0) == NULL)
cba0d141 2298 {
35a25840 2299 if (!found_in_file)
cba0d141 2300 {
35a25840
SG
2301 printf_filtered ("\nNon-debugging symbols:\n");
2302 found_in_file = 1;
cba0d141 2303 }
35a25840
SG
2304 printf_filtered (" %08x %s\n",
2305 msymbol -> address,
2306 msymbol -> name);
cba0d141
JG
2307 }
2308 }
2309 }
2310 }
997a978c 2311 }
997a978c 2312 }
bd5635a1
RP
2313}
2314
2315static void
35a25840 2316variables_info (regexp, from_tty)
bd5635a1 2317 char *regexp;
35a25840 2318 int from_tty;
bd5635a1
RP
2319{
2320 list_symbols (regexp, 0, 0);
2321}
2322
2323static void
35a25840 2324functions_info (regexp, from_tty)
bd5635a1 2325 char *regexp;
35a25840 2326 int from_tty;
bd5635a1
RP
2327{
2328 list_symbols (regexp, 1, 0);
2329}
2330
bd5635a1 2331static void
35a25840 2332types_info (regexp, from_tty)
bd5635a1 2333 char *regexp;
35a25840 2334 int from_tty;
bd5635a1
RP
2335{
2336 list_symbols (regexp, 2, 0);
2337}
bd5635a1
RP
2338
2339#if 0
2340/* Tiemann says: "info methods was never implemented." */
2341static void
2342methods_info (regexp)
2343 char *regexp;
2344{
2345 list_symbols (regexp, 3, 0);
2346}
2347#endif /* 0 */
2348
2349/* Breakpoint all functions matching regular expression. */
2350static void
35a25840 2351rbreak_command (regexp, from_tty)
bd5635a1 2352 char *regexp;
35a25840 2353 int from_tty;
bd5635a1
RP
2354{
2355 list_symbols (regexp, 1, 1);
2356}
2357\f
bd5635a1
RP
2358
2359/* Return Nonzero if block a is lexically nested within block b,
2360 or if a and b have the same pc range.
2361 Return zero otherwise. */
2362int
2363contained_in (a, b)
2364 struct block *a, *b;
2365{
2366 if (!a || !b)
2367 return 0;
2368 return BLOCK_START (a) >= BLOCK_START (b)
2369 && BLOCK_END (a) <= BLOCK_END (b);
2370}
2371
2372\f
2373/* Helper routine for make_symbol_completion_list. */
2374
f70be3e4
JG
2375static int return_val_size;
2376static int return_val_index;
2377static char **return_val;
2378
2379/* Test to see if the symbol specified by SYMNAME (or it's demangled
2380 equivalent) matches TEXT in the first TEXT_LEN characters. If so,
2381 add it to the current completion list. */
bd5635a1 2382
cba0d141 2383static void
f70be3e4 2384completion_list_add_symbol (symname, text, text_len)
bd5635a1 2385 char *symname;
f70be3e4
JG
2386 char *text;
2387 int text_len;
bd5635a1 2388{
f70be3e4
JG
2389 char *demangled;
2390 int newsize;
2391
2392 /* First see if SYMNAME is a C++ mangled name, and if so, use the
2393 demangled name instead, including any parameters. */
2394
2395 if ((demangled = cplus_demangle (symname, DMGL_PARAMS | DMGL_ANSI)) != NULL)
2396 {
2397 symname = demangled;
2398 }
2399
2400 /* If we have a match for a completion, then add SYMNAME to the current
2401 list of matches. Note that we always make a copy of the string, even
2402 if it is one that was returned from cplus_demangle and is already
2403 in malloc'd memory. */
2404
2405 if (strncmp (symname, text, text_len) == 0)
2406 {
2407 if (return_val_index + 3 > return_val_size)
2408 {
2409 newsize = (return_val_size *= 2) * sizeof (char *);
2410 return_val = (char **) xrealloc ((char *) return_val, newsize);
2411 }
2412 return_val[return_val_index++] = savestring (symname, strlen (symname));
2413 return_val[return_val_index] = NULL;
2414 }
2415
2416 if (demangled != NULL)
2417 {
2418 free (demangled);
2419 }
bd5635a1
RP
2420}
2421
2422/* Return a NULL terminated array of all symbols (regardless of class) which
2423 begin by matching TEXT. If the answer is no symbols, then the return value
2424 is an array which contains only a NULL pointer.
2425
f70be3e4
JG
2426 Problem: All of the symbols have to be copied because readline frees them.
2427 I'm not going to worry about this; hopefully there won't be that many. */
bd5635a1
RP
2428
2429char **
2430make_symbol_completion_list (text)
2431 char *text;
2432{
f70be3e4 2433 register struct symbol *sym;
bd5635a1
RP
2434 register struct symtab *s;
2435 register struct partial_symtab *ps;
cba0d141
JG
2436 register struct minimal_symbol *msymbol;
2437 register struct objfile *objfile;
bd5635a1 2438 register struct block *b, *surrounding_static_block = 0;
bd5635a1 2439 register int i, j;
f70be3e4 2440 int text_len;
bd5635a1
RP
2441 struct partial_symbol *psym;
2442
f70be3e4 2443 text_len = strlen (text);
bd5635a1
RP
2444 return_val_size = 100;
2445 return_val_index = 0;
f70be3e4
JG
2446 return_val = (char **) xmalloc ((return_val_size + 1) * sizeof (char *));
2447 return_val[0] = NULL;
bd5635a1
RP
2448
2449 /* Look through the partial symtabs for all symbols which begin
2450 by matching TEXT. Add each one that you find to the list. */
2451
35a25840 2452 ALL_PSYMTABS (objfile, ps)
bd5635a1 2453 {
35a25840
SG
2454 /* If the psymtab's been read in we'll get it when we search
2455 through the blockvector. */
2456 if (ps->readin) continue;
2457
2458 for (psym = objfile->global_psymbols.list + ps->globals_offset;
2459 psym < (objfile->global_psymbols.list + ps->globals_offset
2460 + ps->n_global_syms);
2461 psym++)
bd5635a1 2462 {
f70be3e4
JG
2463 /* If interrupted, then quit. */
2464 QUIT;
2465 completion_list_add_symbol (SYMBOL_NAME (psym), text, text_len);
35a25840
SG
2466 }
2467
2468 for (psym = objfile->static_psymbols.list + ps->statics_offset;
2469 psym < (objfile->static_psymbols.list + ps->statics_offset
2470 + ps->n_static_syms);
2471 psym++)
2472 {
2473 QUIT;
f70be3e4 2474 completion_list_add_symbol (SYMBOL_NAME (psym), text, text_len);
bd5635a1
RP
2475 }
2476 }
2477
cba0d141 2478 /* At this point scan through the misc symbol vectors and add each
bd5635a1
RP
2479 symbol you find to the list. Eventually we want to ignore
2480 anything that isn't a text symbol (everything else will be
2481 handled by the psymtab code above). */
2482
35a25840 2483 ALL_MSYMBOLS (objfile, msymbol)
cba0d141 2484 {
f70be3e4
JG
2485 QUIT;
2486 completion_list_add_symbol (msymbol -> name, text, text_len);
cba0d141 2487 }
bd5635a1
RP
2488
2489 /* Search upwards from currently selected frame (so that we can
2490 complete on local vars. */
f70be3e4
JG
2491
2492 for (b = get_selected_block (); b != NULL; b = BLOCK_SUPERBLOCK (b))
2493 {
2494 if (!BLOCK_SUPERBLOCK (b))
2495 {
2496 surrounding_static_block = b; /* For elmin of dups */
2497 }
2498
2499 /* Also catch fields of types defined in this places which match our
2500 text string. Only complete on types visible from current context. */
2501
2502 for (i = 0; i < BLOCK_NSYMS (b); i++)
2503 {
2504 sym = BLOCK_SYM (b, i);
2505 completion_list_add_symbol (SYMBOL_NAME (sym), text, text_len);
2506 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF)
2507 {
2508 struct type *t = SYMBOL_TYPE (sym);
2509 enum type_code c = TYPE_CODE (t);
2510
2511 if (c == TYPE_CODE_UNION || c == TYPE_CODE_STRUCT)
2512 {
2513 for (j = TYPE_N_BASECLASSES (t); j < TYPE_NFIELDS (t); j++)
2514 {
2515 if (TYPE_FIELD_NAME (t, j))
2516 {
2517 completion_list_add_symbol (TYPE_FIELD_NAME (t, j),
2518 text, text_len);
2519 }
2520 }
2521 }
2522 }
2523 }
2524 }
2525
2526 /* Go through the symtabs and check the externs and statics for
2527 symbols which match. */
2528
2529 ALL_SYMTABS (objfile, s)
2530 {
2531 QUIT;
2532 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
2533 for (i = 0; i < BLOCK_NSYMS (b); i++)
2534 {
2535 sym = BLOCK_SYM (b, i);
2536 completion_list_add_symbol (SYMBOL_NAME (sym), text, text_len);
2537 }
2538 }
2539
2540 ALL_SYMTABS (objfile, s)
2541 {
2542 QUIT;
2543 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
2544 /* Don't do this block twice. */
2545 if (b == surrounding_static_block) continue;
2546 for (i = 0; i < BLOCK_NSYMS (b); i++)
2547 {
2548 sym = BLOCK_SYM (b, i);
2549 completion_list_add_symbol (SYMBOL_NAME (sym), text, text_len);
2550 }
2551 }
2552
2553 return (return_val);
2554}
2555
2556\f
2557/* Find a mangled symbol that corresponds to LOOKFOR using brute force.
2558 Basically we go munging through available symbols, demangling each one,
2559 looking for a match on the demangled result. */
2560
2561static char *
2562expensive_mangler (lookfor)
2563 const char *lookfor;
2564{
2565 register struct symbol *sym;
2566 register struct symtab *s;
2567 register struct partial_symtab *ps;
2568 register struct minimal_symbol *msymbol;
2569 register struct objfile *objfile;
2570 register struct block *b, *surrounding_static_block = 0;
2571 register int i, j;
2572 struct partial_symbol *psym;
2573 char *demangled;
2574
2575 /* Look through the partial symtabs for a symbol that matches */
2576
2577 ALL_PSYMTABS (objfile, ps)
2578 {
2579 /* If the psymtab's been read in we'll get it when we search
2580 through the blockvector. */
2581 if (ps->readin) continue;
2582
2583 for (psym = objfile->global_psymbols.list + ps->globals_offset;
2584 psym < (objfile->global_psymbols.list + ps->globals_offset
2585 + ps->n_global_syms);
2586 psym++)
2587 {
2588 QUIT; /* If interrupted, then quit. */
2589 demangled = demangle_and_match (SYMBOL_NAME (psym), lookfor,
2590 DMGL_PARAMS | DMGL_ANSI);
2591 if (demangled != NULL)
2592 {
2593 free (demangled);
2594 return (SYMBOL_NAME (psym));
2595 }
2596 }
2597
2598 for (psym = objfile->static_psymbols.list + ps->statics_offset;
2599 psym < (objfile->static_psymbols.list + ps->statics_offset
2600 + ps->n_static_syms);
2601 psym++)
2602 {
2603 QUIT;
2604 demangled = demangle_and_match (SYMBOL_NAME (psym), lookfor,
2605 DMGL_PARAMS | DMGL_ANSI);
2606 if (demangled != NULL)
2607 {
2608 free (demangled);
2609 return (SYMBOL_NAME (psym));
2610 }
2611 }
2612 }
2613
2614 /* Scan through the misc symbol vectors looking for a match. */
2615
2616 ALL_MSYMBOLS (objfile, msymbol)
2617 {
2618 QUIT;
2619 demangled = demangle_and_match (msymbol -> name, lookfor,
2620 DMGL_PARAMS | DMGL_ANSI);
2621 if (demangled != NULL)
2622 {
2623 free (demangled);
2624 return (msymbol -> name);
2625 }
2626 }
2627
2628 /* Search upwards from currently selected frame looking for a match */
2629
bd5635a1
RP
2630 for (b = get_selected_block (); b; b = BLOCK_SUPERBLOCK (b))
2631 {
2632 if (!BLOCK_SUPERBLOCK (b))
2633 surrounding_static_block = b; /* For elmin of dups */
2634
2635 /* Also catch fields of types defined in this places which
2636 match our text string. Only complete on types visible
2637 from current context. */
2638 for (i = 0; i < BLOCK_NSYMS (b); i++)
2639 {
f70be3e4
JG
2640 sym = BLOCK_SYM (b, i);
2641 demangled = demangle_and_match (SYMBOL_NAME (sym), lookfor,
2642 DMGL_PARAMS | DMGL_ANSI);
2643 if (demangled != NULL)
2644 {
2645 free (demangled);
2646 return (SYMBOL_NAME (sym));
2647 }
bd5635a1
RP
2648 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF)
2649 {
2650 struct type *t = SYMBOL_TYPE (sym);
2651 enum type_code c = TYPE_CODE (t);
2652
2653 if (c == TYPE_CODE_UNION || c == TYPE_CODE_STRUCT)
f70be3e4
JG
2654 {
2655 for (j = TYPE_N_BASECLASSES (t); j < TYPE_NFIELDS (t); j++)
2656 {
2657 if (TYPE_FIELD_NAME (t, j))
2658 {
2659 demangled =
2660 demangle_and_match (TYPE_FIELD_NAME (t, j),
2661 lookfor,
2662 DMGL_PARAMS | DMGL_ANSI);
2663 if (demangled != NULL)
2664 {
2665 free (demangled);
2666 return (TYPE_FIELD_NAME (t, j));
2667 }
2668 }
2669 }
2670 }
bd5635a1
RP
2671 }
2672 }
2673 }
2674
2675 /* Go through the symtabs and check the externs and statics for
2676 symbols which match. */
2677
35a25840 2678 ALL_SYMTABS (objfile, s)
bd5635a1 2679 {
f70be3e4 2680 QUIT;
35a25840 2681 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
35a25840 2682 for (i = 0; i < BLOCK_NSYMS (b); i++)
f70be3e4
JG
2683 {
2684 sym = BLOCK_SYM (b, i);
2685 demangled = demangle_and_match (SYMBOL_NAME (sym), lookfor,
2686 DMGL_PARAMS | DMGL_ANSI);
2687 if (demangled != NULL)
2688 {
2689 free (demangled);
2690 return (SYMBOL_NAME (sym));
2691 }
2692 }
bd5635a1
RP
2693 }
2694
35a25840 2695 ALL_SYMTABS (objfile, s)
bd5635a1 2696 {
f70be3e4 2697 QUIT;
35a25840 2698 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
35a25840
SG
2699 /* Don't do this block twice. */
2700 if (b == surrounding_static_block) continue;
35a25840 2701 for (i = 0; i < BLOCK_NSYMS (b); i++)
f70be3e4
JG
2702 {
2703 sym = BLOCK_SYM (b, i);
2704 demangled = demangle_and_match (SYMBOL_NAME (sym), lookfor,
2705 DMGL_PARAMS | DMGL_ANSI);
2706 if (demangled != NULL)
2707 {
2708 free (demangled);
2709 return (SYMBOL_NAME (sym));
2710 }
2711 }
bd5635a1
RP
2712 }
2713
f70be3e4 2714 return (NULL);
bd5635a1 2715}
f70be3e4 2716
bd5635a1 2717\f
997a978c
JG
2718#if 0
2719/* Add the type of the symbol sym to the type of the current
2720 function whose block we are in (assumed). The type of
2721 this current function is contained in *TYPE.
2722
2723 This basically works as follows: When we find a function
2724 symbol (N_FUNC with a 'f' or 'F' in the symbol name), we record
2725 a pointer to its type in the global in_function_type. Every
2726 time we come across a parameter symbol ('p' in its name), then
2727 this procedure adds the name and type of that parameter
2728 to the function type pointed to by *TYPE. (Which should correspond
2729 to in_function_type if it was called correctly).
2730
2731 Note that since we are modifying a type, the result of
2732 lookup_function_type() should be bcopy()ed before calling
2733 this. When not in strict typing mode, the expression
2734 evaluator can choose to ignore this.
2735
2736 Assumption: All of a function's parameter symbols will
2737 appear before another function symbol is found. The parameters
2738 appear in the same order in the argument list as they do in the
2739 symbol table. */
2740
2741void
2742add_param_to_type (type,sym)
2743 struct type **type;
2744 struct symbol *sym;
2745{
2746 int num = ++(TYPE_NFIELDS(*type));
2747
2748 if(TYPE_NFIELDS(*type)-1)
cba0d141
JG
2749 TYPE_FIELDS(*type) = (struct field *)
2750 (*current_objfile->xrealloc) ((char *)(TYPE_FIELDS(*type)),
2751 num*sizeof(struct field));
997a978c 2752 else
cba0d141
JG
2753 TYPE_FIELDS(*type) = (struct field *)
2754 (*current_objfile->xmalloc) (num*sizeof(struct field));
997a978c
JG
2755
2756 TYPE_FIELD_BITPOS(*type,num-1) = num-1;
2757 TYPE_FIELD_BITSIZE(*type,num-1) = 0;
2758 TYPE_FIELD_TYPE(*type,num-1) = SYMBOL_TYPE(sym);
2759 TYPE_FIELD_NAME(*type,num-1) = SYMBOL_NAME(sym);
2760}
2761#endif
2762\f
bd5635a1
RP
2763void
2764_initialize_symtab ()
2765{
2766 add_info ("variables", variables_info,
2767 "All global and static variable names, or those matching REGEXP.");
2768 add_info ("functions", functions_info,
2769 "All function names, or those matching REGEXP.");
3ba6a043
JG
2770
2771 /* FIXME: This command has at least the following problems:
bd5635a1
RP
2772 1. It prints builtin types (in a very strange and confusing fashion).
2773 2. It doesn't print right, e.g. with
2774 typedef struct foo *FOO
2775 type_print prints "FOO" when we want to make it (in this situation)
2776 print "struct foo *".
2777 I also think "ptype" or "whatis" is more likely to be useful (but if
2778 there is much disagreement "info types" can be fixed). */
2779 add_info ("types", types_info,
a0a6174a 2780 "All type names, or those matching REGEXP.");
3ba6a043 2781
bd5635a1
RP
2782#if 0
2783 add_info ("methods", methods_info,
2784 "All method names, or those matching REGEXP::REGEXP.\n\
50e0dc41 2785If the class qualifier is omitted, it is assumed to be the current scope.\n\
cba0d141 2786If the first REGEXP is omitted, then all methods matching the second REGEXP\n\
bd5635a1
RP
2787are listed.");
2788#endif
2789 add_info ("sources", sources_info,
2790 "Source files in the program.");
2791
2792 add_com ("rbreak", no_class, rbreak_command,
2793 "Set a breakpoint for all functions matching REGEXP.");
2794
997a978c 2795 /* Initialize the one built-in type that isn't language dependent... */
cba0d141
JG
2796 builtin_type_error = init_type (TYPE_CODE_ERROR, 0, 0,
2797 "<unknown type>", (struct objfile *) NULL);
bd5635a1 2798}
This page took 0.185967 seconds and 4 git commands to generate.