1 /* Symbol table lookup for the GNU debugger, GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
35 #include <sys/types.h>
40 extern char *getenv ();
42 extern char *cplus_demangle ();
43 extern char *cplus_mangle_opname ();
44 extern struct value *value_of_this ();
45 extern void break_command ();
46 extern void select_source_symtab ();
48 /* Functions this file defines */
49 static int find_line_common ();
50 struct partial_symtab *lookup_partial_symtab ();
51 static struct partial_symbol *lookup_partial_symbol ();
52 static struct partial_symbol *lookup_demangled_partial_symbol ();
53 static struct symbol *lookup_demangled_block_symbol ();
55 /* The single non-language-specific builtin type */
56 struct type *builtin_type_error;
58 /* Block in which the most recently searched-for symbol was found.
59 Might be better to make this a parameter to lookup_symbol and
61 struct block *block_found;
63 char no_symtab_msg[] = "No symbol table is loaded. Use the \"file\" command.";
65 /* Check for a symtab of a specific name; first in symtabs, then in
66 psymtabs. *If* there is no '/' in the name, a match after a '/'
67 in the symtab filename will also work. */
69 static struct symtab *
70 lookup_symtab_1 (name)
73 register struct symtab *s;
74 register struct partial_symtab *ps;
75 register char *slash = strchr (name, '/');
76 register int len = strlen (name);
78 for (s = symtab_list; s; s = s->next)
79 if (!strcmp (name, s->filename))
82 for (ps = partial_symtab_list; ps; ps = ps->next)
83 if (!strcmp (name, ps->filename))
86 error ("Internal: readin pst for `%s' found when no symtab found.", name);
87 return PSYMTAB_TO_SYMTAB (ps);
92 for (s = symtab_list; s; s = s->next)
94 int l = strlen (s->filename);
96 if (s->filename[l - len -1] == '/'
97 && !strcmp (s->filename + l - len, name))
101 for (ps = partial_symtab_list; ps; ps = ps->next)
103 int l = strlen (ps->filename);
105 if (ps->filename[l - len - 1] == '/'
106 && !strcmp (ps->filename + l - len, name))
109 error ("Internal: readin pst for `%s' found when no symtab found.", name);
110 return PSYMTAB_TO_SYMTAB (ps);
117 /* Lookup the symbol table of a source file named NAME. Try a couple
118 of variations if the first lookup doesn't work. */
124 register struct symtab *s;
127 s = lookup_symtab_1 (name);
130 /* If name not found as specified, see if adding ".c" helps. */
132 copy = (char *) alloca (strlen (name) + 3);
135 s = lookup_symtab_1 (copy);
138 /* We didn't find anything; die. */
142 /* Lookup the partial symbol table of a source file named NAME. This
143 only returns true on an exact match (ie. this semantics are
144 different from lookup_symtab. */
146 struct partial_symtab *
147 lookup_partial_symtab (name)
150 register struct partial_symtab *s;
152 for (s = partial_symtab_list; s; s = s->next)
153 if (!strcmp (name, s->filename))
159 /* Return a typename for a struct/union/enum type
160 without the tag qualifier. If the type has a NULL name,
163 type_name_no_tag (type)
164 register struct type *type;
166 register char *name = TYPE_NAME (type);
171 switch (TYPE_CODE (type))
173 case TYPE_CODE_STRUCT:
174 if(!strncmp(name,"struct ",7))
177 case TYPE_CODE_UNION:
178 if(!strncmp(name,"union ",6))
182 if(!strncmp(name,"enum ",5))
190 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
192 If this is a stubbed struct (i.e. declared as struct foo *), see if
193 we can find a full definition in some other file. If so, copy this
194 definition, so we can use it in future. If not, set a flag so we
195 don't waste too much time in future. (FIXME, this doesn't seem
198 This used to be coded as a macro, but I don't think it is called
199 often enough to merit such treatment.
202 struct complaint stub_noname_complaint =
203 {"stub type has NULL name", 0, 0};
206 check_stub_type(type)
209 if (TYPE_FLAGS(type) & TYPE_FLAG_STUB)
211 char* name= type_name_no_tag (type);
215 complain (&stub_noname_complaint, 0);
218 sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0,
219 (struct symtab **)NULL);
221 memcpy (type, SYMBOL_TYPE(sym), sizeof (struct type));
225 /* Demangle a GDB method stub type. */
227 gdb_mangle_name (type, i, j)
231 int mangled_name_len;
233 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
234 struct fn_field *method = &f[j];
235 char *field_name = TYPE_FN_FIELDLIST_NAME (type, i);
236 int is_constructor = strcmp(field_name, TYPE_NAME (type)) == 0;
238 /* Need a new type prefix. */
240 char *const_prefix = method->is_const ? "C" : "";
241 char *volatile_prefix = method->is_volatile ? "V" : "";
242 char *newname = type_name_no_tag (type);
244 int len = strlen (newname);
246 sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len);
247 mangled_name_len = ((is_constructor ? 0 : strlen (field_name))
249 + strlen (TYPE_FN_FIELD_PHYSNAME (f, j))
252 /* Only needed for GNU-mangled names. ANSI-mangled names
253 work with the normal mechanisms. */
254 if (OPNAME_PREFIX_P (field_name))
256 char *opname = cplus_mangle_opname (field_name + 3, 0);
258 error ("No mangling for \"%s\"", field_name);
259 mangled_name_len += strlen (opname);
260 mangled_name = (char *)xmalloc (mangled_name_len);
262 strncpy (mangled_name, field_name, 3);
263 mangled_name[3] = '\0';
264 strcat (mangled_name, opname);
268 mangled_name = (char *)xmalloc (mangled_name_len);
270 mangled_name[0] = '\0';
272 strcpy (mangled_name, field_name);
274 strcat (mangled_name, buf);
275 strcat (mangled_name, newname);
276 strcat (mangled_name, TYPE_FN_FIELD_PHYSNAME (f, j));
281 /* Lookup a primitive type named NAME.
282 Return zero if NAME is not a primitive type.*/
285 lookup_primitive_typename (name)
288 struct type ** const *p;
290 for (p = current_language->la_builtin_type_vector; *p; p++)
291 if(!strcmp((**p)->name, name))
296 /* Lookup a typedef or primitive type named NAME,
297 visible in lexical block BLOCK.
298 If NOERR is nonzero, return zero if NAME is not suitably defined. */
301 lookup_typename (name, block, noerr)
306 register struct symbol *sym =
307 lookup_symbol (name, block, VAR_NAMESPACE, 0, (struct symtab **)NULL);
308 if (sym == 0 || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
311 tmp = lookup_primitive_typename (name);
314 else if (!tmp && noerr)
317 error ("No type named %s.", name);
319 return SYMBOL_TYPE (sym);
323 lookup_unsigned_typename (name)
326 char *uns = alloca (strlen(name) + 10);
328 strcpy (uns, "unsigned ");
329 strcpy (uns+9, name);
330 return lookup_typename (uns, (struct block *)0, 0);
333 /* Lookup a structure type named "struct NAME",
334 visible in lexical block BLOCK. */
337 lookup_struct (name, block)
341 register struct symbol *sym
342 = lookup_symbol (name, block, STRUCT_NAMESPACE, 0, (struct symtab **)NULL);
345 error ("No struct type named %s.", name);
346 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
347 error ("This context has class, union or enum %s, not a struct.", name);
348 return SYMBOL_TYPE (sym);
351 /* Lookup a union type named "union NAME",
352 visible in lexical block BLOCK. */
355 lookup_union (name, block)
359 register struct symbol *sym
360 = lookup_symbol (name, block, STRUCT_NAMESPACE, 0, (struct symtab **)NULL);
363 error ("No union type named %s.", name);
364 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_UNION)
365 error ("This context has class, struct or enum %s, not a union.", name);
366 return SYMBOL_TYPE (sym);
369 /* Lookup an enum type named "enum NAME",
370 visible in lexical block BLOCK. */
373 lookup_enum (name, block)
377 register struct symbol *sym
378 = lookup_symbol (name, block, STRUCT_NAMESPACE, 0, (struct symtab **)NULL);
380 error ("No enum type named %s.", name);
381 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
382 error ("This context has class, struct or union %s, not an enum.", name);
383 return SYMBOL_TYPE (sym);
386 /* Lookup a template type named "template NAME<TYPE>",
387 visible in lexical block BLOCK. */
390 lookup_template_type (name, type, block)
396 char *nam = (char*) alloca(strlen(name) + strlen(type->name) + 4);
399 strcat(nam, type->name);
400 strcat(nam, " >"); /* FIXME, extra space still introduced in gcc? */
402 sym = lookup_symbol (nam, block, VAR_NAMESPACE, 0, (struct symtab **)NULL);
405 error ("No template type named %s.", name);
406 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
407 error ("This context has class, union or enum %s, not a struct.", name);
408 return SYMBOL_TYPE (sym);
411 /* Given a type TYPE, lookup the type of the component of type named
413 If NOERR is nonzero, return zero if NAME is not suitably defined. */
416 lookup_struct_elt_type (type, name, noerr)
423 if ( TYPE_CODE (type) != TYPE_CODE_STRUCT
424 && TYPE_CODE (type) != TYPE_CODE_UNION)
426 target_terminal_ours ();
428 fprintf (stderr, "Type ");
429 type_print (type, "", stderr, -1);
430 error (" is not a structure or union type.");
433 check_stub_type (type);
435 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
437 char *t_field_name = TYPE_FIELD_NAME (type, i);
439 if (t_field_name && !strcmp (t_field_name, name))
440 return TYPE_FIELD_TYPE (type, i);
442 /* OK, it's not in this class. Recursively check the baseclasses. */
443 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
445 struct type *t = lookup_struct_elt_type (TYPE_BASECLASS (type, i),
454 target_terminal_ours ();
456 fprintf (stderr, "Type ");
457 type_print (type, "", stderr, -1);
458 fprintf (stderr, " has no component named ");
459 fputs_filtered (name, stderr);
461 return (struct type *)-1; /* For lint */
464 /* Given a type TYPE, return a type of pointers to that type.
465 May need to construct such a type if this is the first use. */
468 lookup_pointer_type (type)
471 register struct type *ptype = TYPE_POINTER_TYPE (type);
472 if (ptype) return ptype;
474 /* This is the first time anyone wanted a pointer to a TYPE. */
475 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
476 ptype = (struct type *) xmalloc (sizeof (struct type));
478 ptype = (struct type *) obstack_alloc (symbol_obstack,
479 sizeof (struct type));
481 bzero (ptype, sizeof (struct type));
482 TYPE_TARGET_TYPE (ptype) = type;
483 TYPE_POINTER_TYPE (type) = ptype;
484 /* New type is permanent if type pointed to is permanent. */
485 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
486 TYPE_FLAGS (ptype) |= TYPE_FLAG_PERM;
487 /* We assume the machine has only one representation for pointers! */
488 /* FIXME: This confuses host<->target data representations, and is a
489 poor assumption besides. */
490 TYPE_LENGTH (ptype) = sizeof (char *);
491 TYPE_CODE (ptype) = TYPE_CODE_PTR;
496 lookup_reference_type (type)
499 register struct type *rtype = TYPE_REFERENCE_TYPE (type);
500 if (rtype) return rtype;
502 /* This is the first time anyone wanted a pointer to a TYPE. */
503 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
504 rtype = (struct type *) xmalloc (sizeof (struct type));
506 rtype = (struct type *) obstack_alloc (symbol_obstack,
507 sizeof (struct type));
509 bzero (rtype, sizeof (struct type));
510 TYPE_TARGET_TYPE (rtype) = type;
511 TYPE_REFERENCE_TYPE (type) = rtype;
512 /* New type is permanent if type pointed to is permanent. */
513 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
514 TYPE_FLAGS (rtype) |= TYPE_FLAG_PERM;
515 /* We assume the machine has only one representation for pointers! */
516 TYPE_LENGTH (rtype) = sizeof (char *);
517 TYPE_CODE (rtype) = TYPE_CODE_REF;
522 /* Implement direct support for MEMBER_TYPE in GNU C++.
523 May need to construct such a type if this is the first use.
524 The TYPE is the type of the member. The DOMAIN is the type
525 of the aggregate that the member belongs to. */
528 lookup_member_type (type, domain)
529 struct type *type, *domain;
531 register struct type *mtype;
533 mtype = (struct type *) obstack_alloc (symbol_obstack,
534 sizeof (struct type));
535 smash_to_member_type (mtype, domain, type);
539 /* Allocate a stub method whose return type is TYPE.
540 This apparently happens for speed of symbol reading, since parsing
541 out the arguments to the method is cpu-intensive, the way we are doing
542 it. So, we will fill in arguments later.
543 This always returns a fresh type. */
546 allocate_stub_method (type)
549 struct type *mtype = (struct type *) obstack_alloc (symbol_obstack,
550 sizeof (struct type));
551 bzero (mtype, sizeof (struct type));
552 TYPE_TARGET_TYPE (mtype) = type;
553 /* _DOMAIN_TYPE (mtype) = unknown yet */
554 /* _ARG_TYPES (mtype) = unknown yet */
555 TYPE_FLAGS (mtype) = TYPE_FLAG_STUB;
556 TYPE_CODE (mtype) = TYPE_CODE_METHOD;
557 TYPE_LENGTH (mtype) = 1;
561 /* Ugly hack to convert method stubs into method types.
563 He ain't kiddin'. This demangles the name of the method into a string
564 including argument types, parses out each argument type, generates
565 a string casting a zero to that type, evaluates the string, and stuffs
566 the resulting type into an argtype vector!!! Then it knows the type
567 of the whole function (including argument types for overloading),
568 which info used to be in the stab's but was removed to hack back
569 the space required for them. */
571 check_stub_method (type, i, j)
575 extern char *gdb_mangle_name (), *strchr ();
577 char *mangled_name = gdb_mangle_name (type, i, j);
578 char *demangled_name = cplus_demangle (mangled_name, 0);
579 char *argtypetext, *p;
580 int depth = 0, argcount = 1;
581 struct type **argtypes;
584 if (demangled_name == NULL)
585 error ("Internal: Cannot demangle mangled name `%s'.", mangled_name);
587 /* Now, read in the parameters that define this type. */
588 argtypetext = strchr (demangled_name, '(') + 1;
596 else if (*p == ',' && depth == 0)
601 /* We need two more slots: one for the THIS pointer, and one for the
602 NULL [...] or void [end of arglist]. */
603 argtypes = (struct type **) obstack_alloc (symbol_obstack,
604 (argcount+2) * sizeof (struct type *));
606 argtypes[0] = lookup_pointer_type (type);
609 if (*p != ')') /* () means no args, skip while */
614 if (depth <= 0 && (*p == ',' || *p == ')'))
617 parse_and_eval_type (argtypetext, p - argtypetext);
631 if (p[-2] != '.') /* ... */
632 argtypes[argcount] = builtin_type_void; /* Ellist terminator */
634 argtypes[argcount] = NULL; /* List terminator */
636 free (demangled_name);
638 f = TYPE_FN_FIELDLIST1 (type, i);
639 TYPE_FN_FIELD_PHYSNAME (f, j) = mangled_name;
641 /* Now update the old "stub" type into a real type. */
642 mtype = TYPE_FN_FIELD_TYPE (f, j);
643 TYPE_DOMAIN_TYPE (mtype) = type;
644 TYPE_ARG_TYPES (mtype) = argtypes;
645 TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB;
646 TYPE_FN_FIELD_STUB (f, j) = 0;
649 /* Given a type TYPE, return a type of functions that return that type.
650 May need to construct such a type if this is the first use. */
653 lookup_function_type (type)
656 register struct type *ptype = TYPE_FUNCTION_TYPE (type);
657 if (ptype) return ptype;
659 /* This is the first time anyone wanted a function returning a TYPE. */
660 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
661 ptype = (struct type *) xmalloc (sizeof (struct type));
663 ptype = (struct type *) obstack_alloc (symbol_obstack,
664 sizeof (struct type));
666 bzero (ptype, sizeof (struct type));
667 TYPE_TARGET_TYPE (ptype) = type;
668 TYPE_FUNCTION_TYPE (type) = ptype;
669 /* New type is permanent if type returned is permanent. */
670 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
671 TYPE_FLAGS (ptype) |= TYPE_FLAG_PERM;
672 TYPE_LENGTH (ptype) = 1;
673 TYPE_CODE (ptype) = TYPE_CODE_FUNC;
674 TYPE_NFIELDS (ptype) = 0;
678 /* Create an array type. Elements will be of type TYPE, and there will
681 Eventually this should be extended to take two more arguments which
682 specify the bounds of the array and the type of the index.
683 It should also be changed to be a "lookup" function, with the
684 appropriate data structures added to the type field.
685 Then read array type should call here. */
688 create_array_type (element_type, number)
689 struct type *element_type;
692 struct type *result_type = (struct type *)
693 obstack_alloc (symbol_obstack, sizeof (struct type));
694 struct type *range_type;
696 bzero (result_type, sizeof (struct type));
698 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
699 TYPE_TARGET_TYPE (result_type) = element_type;
700 TYPE_LENGTH (result_type) = number * TYPE_LENGTH (element_type);
701 TYPE_NFIELDS (result_type) = 1;
702 TYPE_FIELDS (result_type) =
703 (struct field *) obstack_alloc (symbol_obstack, sizeof (struct field));
706 /* Create range type. */
707 range_type = (struct type *) obstack_alloc (symbol_obstack,
708 sizeof (struct type));
709 TYPE_CODE (range_type) = TYPE_CODE_RANGE;
710 TYPE_TARGET_TYPE (range_type) = builtin_type_int; /* FIXME */
712 /* This should never be needed. */
713 TYPE_LENGTH (range_type) = sizeof (int);
715 TYPE_NFIELDS (range_type) = 2;
716 TYPE_FIELDS (range_type) =
717 (struct field *) obstack_alloc (symbol_obstack,
718 2 * sizeof (struct field));
719 TYPE_FIELD_BITPOS (range_type, 0) = 0; /* FIXME */
720 TYPE_FIELD_BITPOS (range_type, 1) = number-1; /* FIXME */
721 TYPE_FIELD_TYPE (range_type, 0) = builtin_type_int; /* FIXME */
722 TYPE_FIELD_TYPE (range_type, 1) = builtin_type_int; /* FIXME */
724 TYPE_FIELD_TYPE(result_type,0)=range_type;
725 TYPE_VPTR_FIELDNO (result_type) = -1;
731 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
732 A MEMBER is a wierd thing -- it amounts to a typed offset into
733 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
734 include the offset (that's the value of the MEMBER itself), but does
735 include the structure type into which it points (for some reason). */
738 smash_to_member_type (type, domain, to_type)
739 struct type *type, *domain, *to_type;
741 bzero (type, sizeof (struct type));
742 TYPE_TARGET_TYPE (type) = to_type;
743 TYPE_DOMAIN_TYPE (type) = domain;
744 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
745 TYPE_CODE (type) = TYPE_CODE_MEMBER;
748 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
749 METHOD just means `function that gets an extra "this" argument'. */
752 smash_to_method_type (type, domain, to_type, args)
753 struct type *type, *domain, *to_type, **args;
755 bzero (type, sizeof (struct type));
756 TYPE_TARGET_TYPE (type) = to_type;
757 TYPE_DOMAIN_TYPE (type) = domain;
758 TYPE_ARG_TYPES (type) = args;
759 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
760 TYPE_CODE (type) = TYPE_CODE_METHOD;
763 /* Find which partial symtab on the partial_symtab_list contains
764 PC. Return 0 if none. */
766 struct partial_symtab *
768 register CORE_ADDR pc;
770 register struct partial_symtab *ps;
772 for (ps = partial_symtab_list; ps; ps = ps->next)
773 if (pc >= ps->textlow && pc < ps->texthigh)
779 /* Find which partial symbol within a psymtab contains PC. Return 0
780 if none. Check all psymtabs if PSYMTAB is 0. */
781 struct partial_symbol *
782 find_pc_psymbol (psymtab, pc)
783 struct partial_symtab *psymtab;
786 struct partial_symbol *best, *p;
790 psymtab = find_pc_psymtab (pc);
794 best_pc = psymtab->textlow - 1;
796 for (p = static_psymbols.list + psymtab->statics_offset;
797 (p - (static_psymbols.list + psymtab->statics_offset)
798 < psymtab->n_static_syms);
800 if (SYMBOL_NAMESPACE (p) == VAR_NAMESPACE
801 && SYMBOL_CLASS (p) == LOC_BLOCK
802 && pc >= SYMBOL_VALUE_ADDRESS (p)
803 && SYMBOL_VALUE_ADDRESS (p) > best_pc)
805 best_pc = SYMBOL_VALUE_ADDRESS (p);
808 if (best_pc == psymtab->textlow - 1)
814 /* Find the definition for a specified symbol name NAME
815 in namespace NAMESPACE, visible from lexical block BLOCK.
816 Returns the struct symbol pointer, or zero if no symbol is found.
817 If SYMTAB is non-NULL, store the symbol table in which the
818 symbol was found there, or NULL if not found.
819 C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
820 NAME is a field of the current implied argument `this'. If so set
821 *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
822 BLOCK_FOUND is set to the block in which NAME is found (in the case of
823 a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
826 lookup_symbol (name, block, namespace, is_a_field_of_this, symtab)
828 register struct block *block;
829 enum namespace namespace;
830 int *is_a_field_of_this;
831 struct symtab **symtab;
833 register struct symbol *sym;
834 register struct symtab *s;
835 register struct partial_symtab *ps;
836 struct blockvector *bv;
838 /* Search specified block and its superiors. */
842 sym = lookup_block_symbol (block, name, namespace);
848 /* Search the list of symtabs for one which contains the
849 address of the start of this block. */
851 for (s = symtab_list; s; s = s->next)
853 bv = BLOCKVECTOR (s);
854 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
855 if (BLOCK_START (b) <= BLOCK_START (block)
856 && BLOCK_END (b) > BLOCK_START (block))
864 block = BLOCK_SUPERBLOCK (block);
867 /* But that doesn't do any demangling for the STATIC_BLOCK.
868 I'm not sure whether demangling is needed in the case of
869 nested function in inner blocks; if so this needs to be changed.
871 Don't need to mess with the psymtabs; if we have a block,
872 that file is read in. If we don't, then we deal later with
873 all the psymtab stuff that needs checking. */
874 if (namespace == VAR_NAMESPACE && block != NULL)
877 /* Find the right symtab. */
878 for (s = symtab_list; s; s = s->next)
880 bv = BLOCKVECTOR (s);
881 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
882 if (BLOCK_START (b) <= BLOCK_START (block)
883 && BLOCK_END (b) > BLOCK_START (block))
885 sym = lookup_demangled_block_symbol (b, name);
898 /* C++: If requested to do so by the caller,
899 check to see if NAME is a field of `this'. */
900 if (is_a_field_of_this)
902 struct value *v = value_of_this (0);
904 *is_a_field_of_this = 0;
905 if (v && check_field (v, name))
907 *is_a_field_of_this = 1;
914 /* Now search all global blocks. Do the symtab's first, then
915 check the psymtab's */
917 for (s = symtab_list; s; s = s->next)
919 bv = BLOCKVECTOR (s);
920 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
921 sym = lookup_block_symbol (block, name, namespace);
931 /* Check for the possibility of the symbol being a global function
932 that is stored on the misc function vector. Eventually, all
933 global symbols might be resolved in this way. */
935 if (namespace == VAR_NAMESPACE)
937 int ind = lookup_misc_func (name);
939 /* Look for a mangled C++ name for NAME. */
942 int name_len = strlen (name);
944 for (ind = misc_function_count; --ind >= 0; )
945 /* Assume orginal name is prefix of mangled name. */
946 if (!strncmp (misc_function_vector[ind].name, name, name_len))
949 cplus_demangle(misc_function_vector[ind].name, -1);
950 if (demangled != NULL)
952 int cond = strcmp (demangled, name);
958 /* Loop terminates on no match with ind == -1. */
963 s = find_pc_symtab (misc_function_vector[ind].address);
964 /* If S is zero, there are no debug symbols for this file.
965 Skip this stuff and check for matching static symbols below. */
968 bv = BLOCKVECTOR (s);
969 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
970 sym = lookup_block_symbol (block, misc_function_vector[ind].name,
972 /* sym == 0 if symbol was found in the misc_function_vector
973 but not in the symtab.
974 Return 0 to use the misc_function definition of "foo_".
976 This happens for Fortran "foo_" symbols,
977 which are "foo" in the symtab.
979 This can also happen if "asm" is used to make a
980 regular symbol but not a debugging symbol, e.g.
992 for (ps = partial_symtab_list; ps; ps = ps->next)
993 if (!ps->readin && lookup_partial_symbol (ps, name, 1, namespace))
995 s = PSYMTAB_TO_SYMTAB(ps);
996 bv = BLOCKVECTOR (s);
997 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
998 sym = lookup_block_symbol (block, name, namespace);
1000 error ("Internal: global symbol `%s' found in psymtab but not in symtab", name);
1006 /* Now search all per-file blocks.
1007 Not strictly correct, but more useful than an error.
1008 Do the symtabs first, then check the psymtabs */
1010 for (s = symtab_list; s; s = s->next)
1012 bv = BLOCKVECTOR (s);
1013 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1014 sym = lookup_block_symbol (block, name, namespace);
1017 block_found = block;
1024 for (ps = partial_symtab_list; ps; ps = ps->next)
1025 if (!ps->readin && lookup_partial_symbol (ps, name, 0, namespace))
1027 s = PSYMTAB_TO_SYMTAB(ps);
1028 bv = BLOCKVECTOR (s);
1029 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1030 sym = lookup_block_symbol (block, name, namespace);
1032 error ("Internal: static symbol `%s' found in psymtab but not in symtab", name);
1038 /* Now search all per-file blocks for static mangled symbols.
1039 Do the symtabs first, then check the psymtabs. */
1041 if (namespace == VAR_NAMESPACE)
1043 for (s = symtab_list; s; s = s->next)
1045 bv = BLOCKVECTOR (s);
1046 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1047 sym = lookup_demangled_block_symbol (block, name);
1050 block_found = block;
1057 for (ps = partial_symtab_list; ps; ps = ps->next)
1058 if (!ps->readin && lookup_demangled_partial_symbol (ps, name))
1060 s = PSYMTAB_TO_SYMTAB(ps);
1061 bv = BLOCKVECTOR (s);
1062 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1063 sym = lookup_demangled_block_symbol (block, name);
1065 error ("Internal: mangled static symbol `%s' found in psymtab but not in symtab", name);
1077 /* Look for a static demangled symbol in block BLOCK. */
1079 static struct symbol *
1080 lookup_demangled_block_symbol (block, name)
1081 register struct block *block;
1084 register int bot, top, inc;
1085 register struct symbol *sym;
1088 top = BLOCK_NSYMS (block);
1093 sym = BLOCK_SYM (block, bot);
1094 if (SYMBOL_NAME (sym)[0] == inc
1095 && SYMBOL_NAMESPACE (sym) == VAR_NAMESPACE)
1097 char *demangled = cplus_demangle(SYMBOL_NAME (sym), -1);
1098 if (demangled != NULL)
1100 int cond = strcmp (demangled, name);
1112 /* Look, in partial_symtab PST, for static mangled symbol NAME. */
1114 static struct partial_symbol *
1115 lookup_demangled_partial_symbol (pst, name)
1116 struct partial_symtab *pst;
1119 struct partial_symbol *start, *psym;
1120 int length = pst->n_static_syms;
1121 register int inc = name[0];
1124 return (struct partial_symbol *) 0;
1126 start = static_psymbols.list + pst->statics_offset;
1127 for (psym = start; psym < start + length; psym++)
1129 if (SYMBOL_NAME (psym)[0] == inc
1130 && SYMBOL_NAMESPACE (psym) == VAR_NAMESPACE)
1132 char *demangled = cplus_demangle(SYMBOL_NAME (psym), -1);
1133 if (demangled != NULL)
1135 int cond = strcmp (demangled, name);
1143 return (struct partial_symbol *) 0;
1146 /* Look, in partial_symtab PST, for symbol NAME. Check the global
1147 symbols if GLOBAL, the static symbols if not */
1149 static struct partial_symbol *
1150 lookup_partial_symbol (pst, name, global, namespace)
1151 struct partial_symtab *pst;
1154 enum namespace namespace;
1156 struct partial_symbol *start, *psym;
1157 int length = (global ? pst->n_global_syms : pst->n_static_syms);
1160 return (struct partial_symbol *) 0;
1163 global_psymbols.list + pst->globals_offset :
1164 static_psymbols.list + pst->statics_offset );
1166 if (global) /* This means we can use a binary */
1169 struct partial_symbol *top, *bottom, *center;
1171 /* Binary search. This search is guaranteed to end with center
1172 pointing at the earliest partial symbol with the correct
1173 name. At that point *all* partial symbols with that name
1174 will be checked against the correct namespace. */
1176 top = start + length - 1;
1177 while (top > bottom)
1179 center = bottom + (top - bottom) / 2;
1181 assert (center < top);
1183 if (strcmp (SYMBOL_NAME (center), name) >= 0)
1186 bottom = center + 1;
1188 assert (top == bottom);
1190 while (!strcmp (SYMBOL_NAME (top), name))
1192 if (SYMBOL_NAMESPACE (top) == namespace)
1199 /* Can't use a binary search */
1200 for (psym = start; psym < start + length; psym++)
1201 if (namespace == SYMBOL_NAMESPACE (psym)
1202 && !strcmp (name, SYMBOL_NAME (psym)))
1206 return (struct partial_symbol *) 0;
1209 /* Find the psymtab containing main(). */
1211 struct partial_symtab *
1212 find_main_psymtab ()
1214 register struct partial_symtab *pst;
1215 for (pst = partial_symtab_list; pst; pst = pst->next)
1216 if (lookup_partial_symbol (pst, "main", 1, VAR_NAMESPACE))
1221 /* Look for a symbol in block BLOCK. */
1224 lookup_block_symbol (block, name, namespace)
1225 register struct block *block;
1227 enum namespace namespace;
1229 register int bot, top, inc;
1230 register struct symbol *sym, *parameter_sym;
1232 top = BLOCK_NSYMS (block);
1235 /* If the blocks's symbols were sorted, start with a binary search. */
1237 if (BLOCK_SHOULD_SORT (block))
1239 /* First, advance BOT to not far before
1240 the first symbol whose name is NAME. */
1244 inc = (top - bot + 1);
1245 /* No need to keep binary searching for the last few bits worth. */
1248 inc = (inc >> 1) + bot;
1249 sym = BLOCK_SYM (block, inc);
1250 if (SYMBOL_NAME (sym)[0] < name[0])
1252 else if (SYMBOL_NAME (sym)[0] > name[0])
1254 else if (strcmp (SYMBOL_NAME (sym), name) < 0)
1260 /* Now scan forward until we run out of symbols,
1261 find one whose name is greater than NAME,
1262 or find one we want.
1263 If there is more than one symbol with the right name and namespace,
1264 we return the first one. dbxread.c is careful to make sure
1265 that if one is a register then it comes first. */
1267 top = BLOCK_NSYMS (block);
1270 sym = BLOCK_SYM (block, bot);
1271 inc = SYMBOL_NAME (sym)[0] - name[0];
1273 inc = strcmp (SYMBOL_NAME (sym), name);
1274 if (inc == 0 && SYMBOL_NAMESPACE (sym) == namespace)
1283 /* Here if block isn't sorted.
1284 This loop is equivalent to the loop above,
1285 but hacked greatly for speed.
1287 Note that parameter symbols do not always show up last in the
1288 list; this loop makes sure to take anything else other than
1289 parameter symbols first; it only uses parameter symbols as a
1290 last resort. Note that this only takes up extra computation
1293 parameter_sym = (struct symbol *) 0;
1294 top = BLOCK_NSYMS (block);
1298 sym = BLOCK_SYM (block, bot);
1299 if (SYMBOL_NAME (sym)[0] == inc
1300 && !strcmp (SYMBOL_NAME (sym), name)
1301 && SYMBOL_NAMESPACE (sym) == namespace)
1303 if (SYMBOL_CLASS (sym) == LOC_ARG
1304 || SYMBOL_CLASS (sym) == LOC_LOCAL_ARG
1305 || SYMBOL_CLASS (sym) == LOC_REF_ARG
1306 || SYMBOL_CLASS (sym) == LOC_REGPARM)
1307 parameter_sym = sym;
1313 return parameter_sym; /* Will be 0 if not found. */
1316 /* Return the symbol for the function which contains a specified
1317 lexical block, described by a struct block BL. */
1323 while (BLOCK_FUNCTION (bl) == 0 && BLOCK_SUPERBLOCK (bl) != 0)
1324 bl = BLOCK_SUPERBLOCK (bl);
1326 return BLOCK_FUNCTION (bl);
1329 /* Subroutine of find_pc_line */
1333 register CORE_ADDR pc;
1335 register struct block *b;
1336 struct blockvector *bv;
1337 register struct symtab *s;
1338 register struct partial_symtab *ps;
1340 /* Search all symtabs for one whose file contains our pc */
1342 for (s = symtab_list; s; s = s->next)
1344 bv = BLOCKVECTOR (s);
1345 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1346 if (BLOCK_START (b) <= pc
1347 && BLOCK_END (b) > pc)
1353 ps = find_pc_psymtab (pc);
1354 if (ps && ps->readin)
1356 "(Internal error: pc 0x%x in read in psymtab, but not in symtab.)\n", pc);
1359 s = PSYMTAB_TO_SYMTAB (ps);
1365 /* Find the source file and line number for a given PC value.
1366 Return a structure containing a symtab pointer, a line number,
1367 and a pc range for the entire source line.
1368 The value's .pc field is NOT the specified pc.
1369 NOTCURRENT nonzero means, if specified pc is on a line boundary,
1370 use the line that ends there. Otherwise, in that case, the line
1371 that begins there is used. */
1373 struct symtab_and_line
1374 find_pc_line (pc, notcurrent)
1379 register struct linetable *l;
1382 register struct linetable_entry *item;
1383 struct symtab_and_line val;
1384 struct blockvector *bv;
1386 /* Info on best line seen so far, and where it starts, and its file. */
1389 CORE_ADDR best_pc = 0;
1390 CORE_ADDR best_end = 0;
1391 struct symtab *best_symtab = 0;
1393 /* Store here the first line number
1394 of a file which contains the line at the smallest pc after PC.
1395 If we don't find a line whose range contains PC,
1396 we will use a line one less than this,
1397 with a range from the start of that file to the first line's pc. */
1399 CORE_ADDR alt_pc = 0;
1400 struct symtab *alt_symtab = 0;
1402 /* Info on best line seen in this file. */
1407 /* Info on first line of this file. */
1412 /* If this pc is not from the current frame,
1413 it is the address of the end of a call instruction.
1414 Quite likely that is the start of the following statement.
1415 But what we want is the statement containing the instruction.
1416 Fudge the pc to make sure we get that. */
1418 if (notcurrent) pc -= 1;
1420 s = find_pc_symtab (pc);
1430 bv = BLOCKVECTOR (s);
1432 /* Look at all the symtabs that share this blockvector.
1433 They all have the same apriori range, that we found was right;
1434 but they have different line tables. */
1436 for (; s && BLOCKVECTOR (s) == bv; s = s->next)
1438 /* Find the best line in this symtab. */
1445 for (i = 0; i < len; i++)
1447 item = &(l->item[i]);
1451 first_line = item->line;
1452 first_pc = item->pc;
1454 /* Return the last line that did not start after PC. */
1457 prev_line = item->line;
1464 /* Is this file's best line closer than the best in the other files?
1465 If so, record this file, and its best line, as best so far. */
1466 if (prev_line >= 0 && prev_pc > best_pc)
1469 best_line = prev_line;
1472 best_end = item->pc;
1476 /* Is this file's first line closer than the first lines of other files?
1477 If so, record this file, and its first line, as best alternate. */
1478 if (first_line >= 0 && first_pc > pc
1479 && (alt_pc == 0 || first_pc < alt_pc))
1482 alt_line = first_line;
1486 if (best_symtab == 0)
1488 val.symtab = alt_symtab;
1489 val.line = alt_line - 1;
1490 val.pc = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
1495 val.symtab = best_symtab;
1496 val.line = best_line;
1498 val.end = (best_end ? best_end
1500 : BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK))));
1505 /* Find the PC value for a given source file and line number.
1506 Returns zero for invalid line number.
1507 The source file is specified with a struct symtab. */
1510 find_line_pc (symtab, line)
1511 struct symtab *symtab;
1514 register struct linetable *l;
1520 l = LINETABLE (symtab);
1521 ind = find_line_common(l, line, &dummy);
1522 return (ind >= 0) ? l->item[ind].pc : 0;
1525 /* Find the range of pc values in a line.
1526 Store the starting pc of the line into *STARTPTR
1527 and the ending pc (start of next line) into *ENDPTR.
1528 Returns 1 to indicate success.
1529 Returns 0 if could not find the specified line. */
1532 find_line_pc_range (symtab, thisline, startptr, endptr)
1533 struct symtab *symtab;
1535 CORE_ADDR *startptr, *endptr;
1537 register struct linetable *l;
1539 int exact_match; /* did we get an exact linenumber match */
1544 l = LINETABLE (symtab);
1545 ind = find_line_common (l, thisline, &exact_match);
1548 *startptr = l->item[ind].pc;
1549 /* If we have not seen an entry for the specified line,
1550 assume that means the specified line has zero bytes. */
1551 if (!exact_match || ind == l->nitems-1)
1552 *endptr = *startptr;
1554 /* Perhaps the following entry is for the following line.
1555 It's worth a try. */
1556 if (ind+1 < l->nitems
1557 && l->item[ind+1].line == thisline + 1)
1558 *endptr = l->item[ind+1].pc;
1560 *endptr = find_line_pc (symtab, thisline+1);
1567 /* Given a line table and a line number, return the index into the line
1568 table for the pc of the nearest line whose number is >= the specified one.
1569 Return -1 if none is found. The value is >= 0 if it is an index.
1571 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
1574 find_line_common (l, lineno, exact_match)
1575 register struct linetable *l;
1576 register int lineno;
1582 /* BEST is the smallest linenumber > LINENO so far seen,
1583 or 0 if none has been seen so far.
1584 BEST_INDEX identifies the item for it. */
1586 int best_index = -1;
1595 for (i = 0; i < len; i++)
1597 register struct linetable_entry *item = &(l->item[i]);
1599 if (item->line == lineno)
1605 if (item->line > lineno && (best == 0 || item->line < best))
1612 /* If we got here, we didn't get an exact match. */
1619 find_pc_line_pc_range (pc, startptr, endptr)
1621 CORE_ADDR *startptr, *endptr;
1623 struct symtab_and_line sal;
1624 sal = find_pc_line (pc, 0);
1627 return sal.symtab != 0;
1630 /* If P is of the form "operator[ \t]+..." where `...' is
1631 some legitimate operator text, return a pointer to the
1632 beginning of the substring of the operator text.
1633 Otherwise, return "". */
1635 operator_chars (p, end)
1640 if (strncmp (p, "operator", 8))
1644 /* Don't get faked out by `operator' being part of a longer
1646 if ((*p >= 'A' && *p <= 'Z') || (*p >= 'a' && *p <= 'z')
1647 || *p == '_' || *p == '$' || *p == '\0')
1650 /* Allow some whitespace between `operator' and the operator symbol. */
1651 while (*p == ' ' || *p == '\t')
1673 if (p[1] == '=' || p[1] == p[0])
1684 error ("`operator ()' must be specified without whitespace in `()'");
1689 error ("`operator ?:' must be specified without whitespace in `?:'");
1694 error ("`operator []' must be specified without whitespace in `[]'");
1698 error ("`operator %s' not supported", p);
1705 /* Recursive helper function for decode_line_1.
1706 * Look for methods named NAME in type T.
1707 * Return number of matches.
1708 * Put matches in PHYSNAMES and SYM_ARR (which better be big enough!).
1709 * These allocations seem to define "big enough":
1710 * sym_arr = (struct symbol **) alloca(TYPE_NFN_FIELDS_TOTAL (t) * sizeof(struct symbol*));
1711 * physnames = (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t) * sizeof(char*));
1715 find_methods (t, name, physnames, sym_arr)
1719 struct symbol **sym_arr;
1723 struct symbol *sym_class;
1724 char *class_name = type_name_no_tag (t);
1725 /* Ignore this class if it doesn't have a name.
1726 This prevents core dumps, but is just a workaround
1727 because we might not find the function in
1728 certain cases, such as
1729 struct D {virtual int f();}
1730 struct C : D {virtual int g();}
1731 (in this case g++ 1.35.1- does not put out a name
1732 for D as such, it defines type 19 (for example) in
1733 the same stab as C, and then does a
1734 .stabs "D:T19" and a .stabs "D:t19".
1736 "break C::f" should not be looking for field f in
1738 but just for the field f in the baseclasses of C
1739 (no matter what their names).
1741 However, I don't know how to replace the code below
1742 that depends on knowing the name of D. */
1744 && (sym_class = lookup_symbol (class_name,
1745 (struct block *)NULL,
1748 (struct symtab **)NULL)))
1751 t = SYMBOL_TYPE (sym_class);
1752 for (method_counter = TYPE_NFN_FIELDS (t) - 1;
1753 method_counter >= 0;
1757 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, method_counter);
1759 char *method_name = TYPE_FN_FIELDLIST_NAME (t, method_counter);
1760 if (!strcmp (name, method_name))
1761 /* Find all the fields with that name. */
1762 for (field_counter = TYPE_FN_FIELDLIST_LENGTH (t, method_counter) - 1;
1767 if (TYPE_FN_FIELD_STUB (f, field_counter))
1768 check_stub_method (t, method_counter, field_counter);
1769 phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter);
1770 physnames[i1] = (char*) alloca (strlen (phys_name) + 1);
1771 strcpy (physnames[i1], phys_name);
1772 sym_arr[i1] = lookup_symbol (phys_name,
1773 SYMBOL_BLOCK_VALUE (sym_class),
1776 (struct symtab **) NULL);
1777 if (sym_arr[i1]) i1++;
1781 /* Only search baseclasses if there is no match yet,
1782 * since names in derived classes override those in baseclasses.
1786 for (ibase = 0; ibase < TYPE_N_BASECLASSES (t); ibase++)
1787 i1 += find_methods(TYPE_BASECLASS(t, ibase), name,
1788 physnames + i1, sym_arr + i1);
1792 /* Parse a string that specifies a line number.
1793 Pass the address of a char * variable; that variable will be
1794 advanced over the characters actually parsed.
1798 LINENUM -- that line number in current file. PC returned is 0.
1799 FILE:LINENUM -- that line in that file. PC returned is 0.
1800 FUNCTION -- line number of openbrace of that function.
1801 PC returned is the start of the function.
1802 VARIABLE -- line number of definition of that variable.
1804 FILE:FUNCTION -- likewise, but prefer functions in that file.
1805 *EXPR -- line in which address EXPR appears.
1807 FUNCTION may be an undebuggable function found in misc_function_vector.
1809 If the argument FUNFIRSTLINE is nonzero, we want the first line
1810 of real code inside a function when a function is specified.
1812 DEFAULT_SYMTAB specifies the file to use if none is specified.
1813 It defaults to current_source_symtab.
1814 DEFAULT_LINE specifies the line number to use for relative
1815 line numbers (that start with signs). Defaults to current_source_line.
1817 Note that it is possible to return zero for the symtab
1818 if no file is validly specified. Callers must check that.
1819 Also, the line number returned may be invalid. */
1821 struct symtabs_and_lines
1822 decode_line_1 (argptr, funfirstline, default_symtab, default_line)
1825 struct symtab *default_symtab;
1828 struct symtabs_and_lines decode_line_2 ();
1829 struct symtabs_and_lines values;
1830 struct symtab_and_line val;
1831 register char *p, *p1;
1833 register struct symtab *s;
1835 register struct symbol *sym;
1836 /* The symtab that SYM was found in. */
1837 struct symtab *sym_symtab;
1839 register CORE_ADDR pc;
1842 struct symbol *sym_class;
1844 struct symbol **sym_arr;
1848 /* Defaults have defaults. */
1850 if (default_symtab == 0)
1852 default_symtab = current_source_symtab;
1853 default_line = current_source_line;
1856 /* See if arg is *PC */
1858 if (**argptr == '*')
1861 pc = parse_and_eval_address_1 (argptr);
1862 values.sals = (struct symtab_and_line *)
1863 xmalloc (sizeof (struct symtab_and_line));
1865 values.sals[0] = find_pc_line (pc, 0);
1866 values.sals[0].pc = pc;
1870 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
1874 for (p = *argptr; *p; p++)
1876 if (p[0] == ':' || p[0] == ' ' || p[0] == '\t')
1879 while (p[0] == ' ' || p[0] == '\t') p++;
1887 /* Extract the class name. */
1889 while (p != *argptr && p[-1] == ' ') --p;
1890 copy = (char *) alloca (p - *argptr + 1);
1891 bcopy (*argptr, copy, p - *argptr);
1892 copy[p - *argptr] = 0;
1894 /* Discard the class name from the arg. */
1896 while (*p == ' ' || *p == '\t') p++;
1899 sym_class = lookup_symbol (copy, 0, STRUCT_NAMESPACE, 0,
1900 (struct symtab **)NULL);
1903 ( TYPE_CODE (SYMBOL_TYPE (sym_class)) == TYPE_CODE_STRUCT
1904 || TYPE_CODE (SYMBOL_TYPE (sym_class)) == TYPE_CODE_UNION))
1906 /* Arg token is not digits => try it as a function name
1907 Find the next token (everything up to end or next whitespace). */
1909 while (*p && *p != ' ' && *p != '\t' && *p != ',' && *p !=':') p++;
1910 q = operator_chars (*argptr, &q1);
1912 copy = (char *) alloca (p - *argptr + 1 + (q1 - q));
1917 copy[2] = CPLUS_MARKER;
1918 bcopy (q, copy + 3, q1 - q);
1919 copy[3 + (q1 - q)] = '\0';
1924 bcopy (*argptr, copy, p - *argptr);
1925 copy[p - *argptr] = '\0';
1928 /* no line number may be specified */
1929 while (*p == ' ' || *p == '\t') p++;
1933 i1 = 0; /* counter for the symbol array */
1934 t = SYMBOL_TYPE (sym_class);
1935 sym_arr = (struct symbol **) alloca(TYPE_NFN_FIELDS_TOTAL (t) * sizeof(struct symbol*));
1936 physnames = (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t) * sizeof(char*));
1938 if (destructor_name_p (copy, t))
1940 /* destructors are a special case. */
1941 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, 0);
1942 int len = TYPE_FN_FIELDLIST_LENGTH (t, 0) - 1;
1943 char *phys_name = TYPE_FN_FIELD_PHYSNAME (f, len);
1944 physnames[i1] = (char *)alloca (strlen (phys_name) + 1);
1945 strcpy (physnames[i1], phys_name);
1947 lookup_symbol (phys_name, SYMBOL_BLOCK_VALUE (sym_class),
1948 VAR_NAMESPACE, 0, (struct symtab **)NULL);
1949 if (sym_arr[i1]) i1++;
1952 i1 = find_methods (t, copy, physnames, sym_arr);
1955 /* There is exactly one field with that name. */
1958 if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
1960 /* Arg is the name of a function */
1961 pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) + FUNCTION_START_OFFSET;
1964 values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line));
1966 values.sals[0] = find_pc_line (pc, 0);
1967 values.sals[0].pc = (values.sals[0].end && values.sals[0].pc != pc) ? values.sals[0].end : pc;
1977 /* There is more than one field with that name
1978 (overloaded). Ask the user which one to use. */
1979 return decode_line_2 (sym_arr, i1, funfirstline);
1985 if (OPNAME_PREFIX_P (copy))
1987 tmp = (char *)alloca (strlen (copy+3) + 9);
1988 strcpy (tmp, "operator ");
1989 strcat (tmp, copy+3);
1994 error ("The class `%s' does not have destructor defined",
1997 error ("The class %s does not have any method named %s",
1998 sym_class->name, tmp);
2002 /* The quotes are important if copy is empty. */
2003 error("No class, struct, or union named \"%s\"", copy );
2008 /* Extract the file name. */
2010 while (p != *argptr && p[-1] == ' ') --p;
2011 copy = (char *) alloca (p - *argptr + 1);
2012 bcopy (*argptr, copy, p - *argptr);
2013 copy[p - *argptr] = 0;
2015 /* Find that file's data. */
2016 s = lookup_symtab (copy);
2019 if (symtab_list == 0 && partial_symtab_list == 0)
2020 error (no_symtab_msg);
2021 error ("No source file named %s.", copy);
2024 /* Discard the file name from the arg. */
2026 while (*p == ' ' || *p == '\t') p++;
2030 /* S is specified file's symtab, or 0 if no file specified.
2031 arg no longer contains the file name. */
2033 /* Check whether arg is all digits (and sign) */
2036 if (*p == '-' || *p == '+') p++;
2037 while (*p >= '0' && *p <= '9')
2040 if (p != *argptr && (*p == 0 || *p == ' ' || *p == '\t' || *p == ','))
2042 /* We found a token consisting of all digits -- at least one digit. */
2043 enum sign {none, plus, minus} sign = none;
2045 /* This is where we need to make sure that we have good defaults.
2046 We must guarantee that this section of code is never executed
2047 when we are called with just a function name, since
2048 select_source_symtab calls us with such an argument */
2050 if (s == 0 && default_symtab == 0)
2052 select_source_symtab (0);
2053 default_symtab = current_source_symtab;
2054 default_line = current_source_line;
2057 if (**argptr == '+')
2058 sign = plus, (*argptr)++;
2059 else if (**argptr == '-')
2060 sign = minus, (*argptr)++;
2061 val.line = atoi (*argptr);
2068 val.line = default_line + val.line;
2074 val.line = default_line - val.line;
2079 break; /* No need to adjust val.line. */
2082 while (*p == ' ' || *p == '\t') p++;
2088 values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line));
2089 values.sals[0] = val;
2094 /* Arg token is not digits => try it as a variable name
2095 Find the next token (everything up to end or next whitespace). */
2097 while (*p && *p != ' ' && *p != '\t' && *p != ',') p++;
2098 copy = (char *) alloca (p - *argptr + 1);
2099 bcopy (*argptr, copy, p - *argptr);
2100 copy[p - *argptr] = 0;
2101 while (*p == ' ' || *p == '\t') p++;
2104 /* Look up that token as a variable.
2105 If file specified, use that file's per-file block to start with. */
2107 sym = lookup_symbol (copy,
2108 (s ? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)
2109 : get_selected_block ()),
2110 VAR_NAMESPACE, 0, &sym_symtab);
2114 if (SYMBOL_CLASS (sym) == LOC_BLOCK)
2116 /* Arg is the name of a function */
2117 pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) + FUNCTION_START_OFFSET;
2120 val = find_pc_line (pc, 0);
2121 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2122 /* Convex: no need to suppress code on first line, if any */
2125 /* If SKIP_PROLOGUE left us in mid-line, and the next line is still
2126 part of the same function:
2127 advance to next line,
2128 recalculate its line number (might not be N+1). */
2129 if (val.pc != pc && val.end &&
2130 find_pc_misc_function (pc) == find_pc_misc_function (val.end)) {
2131 pc = val.end; /* First pc of next line */
2132 val = find_pc_line (pc, 0);
2136 values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line));
2137 values.sals[0] = val;
2140 /* I think this is always the same as the line that
2141 we calculate above, but the general principle is
2142 "trust the symbols more than stuff like
2144 if (SYMBOL_LINE (sym) != 0)
2145 values.sals[0].line = SYMBOL_LINE (sym);
2149 else if (SYMBOL_LINE (sym) != 0)
2151 /* We know its line number. */
2152 values.sals = (struct symtab_and_line *)
2153 xmalloc (sizeof (struct symtab_and_line));
2155 bzero (&values.sals[0], sizeof (values.sals[0]));
2156 values.sals[0].symtab = sym_symtab;
2157 values.sals[0].line = SYMBOL_LINE (sym);
2161 /* This can happen if it is compiled with a compiler which doesn't
2162 put out line numbers for variables. */
2163 error ("Line number not known for symbol \"%s\"", copy);
2166 if ((i = lookup_misc_func (copy)) >= 0)
2170 val.pc = misc_function_vector[i].address + FUNCTION_START_OFFSET;
2172 SKIP_PROLOGUE (val.pc);
2173 values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line));
2174 values.sals[0] = val;
2179 if (symtab_list == 0 && partial_symtab_list == 0 && misc_function_count == 0)
2180 error (no_symtab_msg);
2182 error ("Function %s not defined.", copy);
2183 return values; /* for lint */
2186 struct symtabs_and_lines
2187 decode_line_spec (string, funfirstline)
2191 struct symtabs_and_lines sals;
2193 error ("Empty line specification.");
2194 sals = decode_line_1 (&string, funfirstline,
2195 current_source_symtab, current_source_line);
2197 error ("Junk at end of line specification: %s", string);
2201 /* Given a list of NELTS symbols in sym_arr (with corresponding
2202 mangled names in physnames), return a list of lines to operate on
2203 (ask user if necessary). */
2204 struct symtabs_and_lines
2205 decode_line_2 (sym_arr, nelts, funfirstline)
2206 struct symbol *sym_arr[];
2210 struct symtabs_and_lines values, return_values;
2211 register CORE_ADDR pc;
2212 char *args, *arg1, *command_line_input ();
2216 values.sals = (struct symtab_and_line *) alloca (nelts * sizeof(struct symtab_and_line));
2217 return_values.sals = (struct symtab_and_line *) xmalloc (nelts * sizeof(struct symtab_and_line));
2220 printf("[0] cancel\n[1] all\n");
2223 if (sym_arr[i] && SYMBOL_CLASS (sym_arr[i]) == LOC_BLOCK)
2225 /* Arg is the name of a function */
2226 pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym_arr[i]))
2227 + FUNCTION_START_OFFSET;
2230 values.sals[i] = find_pc_line (pc, 0);
2231 values.sals[i].pc = (values.sals[i].end && values.sals[i].pc != pc) ?
2232 values.sals[i].end : pc;
2233 printf("[%d] file:%s; line number:%d\n",
2234 (i+2), values.sals[i].symtab->filename, values.sals[i].line);
2236 else printf ("?HERE\n");
2240 if ((prompt = getenv ("PS2")) == NULL)
2244 printf("%s ",prompt);
2247 args = command_line_input (0, 0);
2250 error_no_arg ("one or more choice numbers");
2258 while (*arg1 >= '0' && *arg1 <= '9') arg1++;
2259 if (*arg1 && *arg1 != ' ' && *arg1 != '\t')
2260 error ("Arguments must be choice numbers.");
2265 error ("cancelled");
2268 bcopy (values.sals, return_values.sals, (nelts * sizeof(struct symtab_and_line)));
2269 return_values.nelts = nelts;
2270 return return_values;
2273 if (num > nelts + 2)
2275 printf ("No choice number %d.\n", num);
2280 if (values.sals[num].pc)
2282 return_values.sals[i++] = values.sals[num];
2283 values.sals[num].pc = 0;
2287 printf ("duplicate request for %d ignored.\n", num);
2292 while (*args == ' ' || *args == '\t') args++;
2294 return_values.nelts = i;
2295 return return_values;
2298 /* Return the index of misc function named NAME. */
2301 lookup_misc_func (name)
2302 register char *name;
2306 for (i = 0; i < misc_function_count; i++)
2307 if (!strcmp (misc_function_vector[i].name, name))
2309 return -1; /* not found */
2312 /* Slave routine for sources_info. Force line breaks at ,'s.
2313 NAME is the name to print and *FIRST is nonzero if this is the first
2314 name printed. Set *FIRST to zero. */
2316 output_source_filename (name, first)
2321 /* Table of files printed so far. Since a single source file can
2322 result in several partial symbol tables, we need to avoid printing
2323 it more than once. Note: if some of the psymtabs are read in and
2324 some are not, it gets printed both under "Source files for which
2325 symbols have been read" and "Source files for which symbols will
2326 be read in on demand". I consider this a reasonable way to deal
2327 with the situation. I'm not sure whether this can also happen for
2328 symtabs; it doesn't hurt to check. */
2329 static char **tab = NULL;
2330 /* Allocated size of tab in elements.
2331 Start with one 256-byte block (when using GNU malloc.c).
2332 24 is the malloc overhead when range checking is in effect. */
2333 static int tab_alloc_size = (256 - 24) / sizeof (char *);
2334 /* Current size of tab in elements. */
2335 static int tab_cur_size;
2342 tab = (char **) xmalloc (tab_alloc_size * sizeof (*tab));
2346 /* Is NAME in tab? */
2347 for (p = tab; p < tab + tab_cur_size; p++)
2348 if (strcmp (*p, name) == 0)
2349 /* Yes; don't print it again. */
2351 /* No; add it to tab. */
2352 if (tab_cur_size == tab_alloc_size)
2354 tab_alloc_size *= 2;
2355 tab = (char **) xrealloc (tab, tab_alloc_size * sizeof (*tab));
2357 tab[tab_cur_size++] = name;
2366 printf_filtered (",");
2370 if (column != 0 && column + strlen (name) >= 70)
2372 printf_filtered ("\n");
2375 else if (column != 0)
2377 printf_filtered (" ");
2380 fputs_filtered (name, stdout);
2381 column += strlen (name);
2387 register struct symtab *s;
2388 register struct partial_symtab *ps;
2391 if (symtab_list == 0 && partial_symtab_list == 0)
2393 error (no_symtab_msg);
2396 printf_filtered ("Source files for which symbols have been read in:\n\n");
2399 for (s = symtab_list; s; s = s->next)
2400 output_source_filename (s->filename, &first);
2401 printf_filtered ("\n\n");
2403 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2406 for (ps = partial_symtab_list; ps; ps = ps->next)
2408 output_source_filename (ps->filename, &first);
2409 printf_filtered ("\n");
2412 /* List all symbols (if REGEXP is 0) or all symbols matching REGEXP.
2413 If CLASS is zero, list all symbols except functions and type names.
2414 If CLASS is 1, list only functions.
2415 If CLASS is 2, list only type names.
2416 If CLASS is 3, list only method names.
2418 BPT is non-zero if we should set a breakpoint at the functions
2422 list_symbols (regexp, class, bpt)
2427 register struct symtab *s;
2428 register struct partial_symtab *ps;
2429 register struct blockvector *bv;
2430 struct blockvector *prev_bv = 0;
2431 register struct block *b;
2433 register struct symbol *sym;
2434 struct partial_symbol *psym;
2436 static char *classnames[]
2437 = {"variable", "function", "type", "method"};
2438 int found_in_file = 0;
2440 static enum misc_function_type types[]
2441 = {mf_data, mf_text, mf_abs, mf_unknown};
2442 static enum misc_function_type types2[]
2443 = {mf_bss, mf_text, mf_abs, mf_unknown};
2444 enum misc_function_type ourtype = types[class];
2445 enum misc_function_type ourtype2 = types2[class];
2448 if (0 != (val = re_comp (regexp)))
2449 error ("Invalid regexp (%s): %s", val, regexp);
2451 /* Search through the partial_symtab_list *first* for all symbols
2452 matching the regexp. That way we don't have to reproduce all of
2453 the machinery below. */
2454 for (ps = partial_symtab_list; ps; ps = ps->next)
2456 struct partial_symbol *bound, *gbound, *sbound;
2459 if (ps->readin) continue;
2461 gbound = global_psymbols.list + ps->globals_offset + ps->n_global_syms;
2462 sbound = static_psymbols.list + ps->statics_offset + ps->n_static_syms;
2465 /* Go through all of the symbols stored in a partial
2466 symtab in one loop. */
2467 psym = global_psymbols.list + ps->globals_offset;
2472 if (bound == gbound && ps->n_static_syms != 0)
2474 psym = static_psymbols.list + ps->statics_offset;
2485 /* If it would match (logic taken from loop below)
2486 load the file and go on to the next one */
2487 if ((regexp == 0 || re_exec (SYMBOL_NAME (psym)))
2488 && ((class == 0 && SYMBOL_CLASS (psym) != LOC_TYPEDEF
2489 && SYMBOL_CLASS (psym) != LOC_BLOCK)
2490 || (class == 1 && SYMBOL_CLASS (psym) == LOC_BLOCK)
2491 || (class == 2 && SYMBOL_CLASS (psym) == LOC_TYPEDEF)
2492 || (class == 3 && SYMBOL_CLASS (psym) == LOC_BLOCK)))
2494 (void) PSYMTAB_TO_SYMTAB(ps);
2502 /* Here, we search through the misc function vector for functions that
2503 match, and call find_pc_symtab on them to force their symbols to
2504 be read. The symbol will then be found during the scan of symtabs
2505 below. If find_pc_symtab fails, set found_misc so that we will
2506 rescan to print any matching symbols without debug info. */
2509 for (i = 0; i < misc_function_count; i++) {
2510 if (misc_function_vector[i].type != ourtype
2511 && misc_function_vector[i].type != ourtype2)
2513 if (regexp == 0 || re_exec (misc_function_vector[i].name)) {
2514 if (0 == find_pc_symtab (misc_function_vector[i].address))
2520 /* Printout here so as to get after the "Reading in symbols"
2521 messages which will be generated above. */
2523 printf_filtered (regexp
2524 ? "All %ss matching regular expression \"%s\":\n"
2525 : "All defined %ss:\n",
2529 for (s = symtab_list; s; s = s->next)
2532 bv = BLOCKVECTOR (s);
2533 /* Often many files share a blockvector.
2534 Scan each blockvector only once so that
2535 we don't get every symbol many times.
2536 It happens that the first symtab in the list
2537 for any given blockvector is the main file. */
2539 for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
2541 b = BLOCKVECTOR_BLOCK (bv, i);
2542 /* Skip the sort if this block is always sorted. */
2543 if (!BLOCK_SHOULD_SORT (b))
2544 sort_block_syms (b);
2545 for (j = 0; j < BLOCK_NSYMS (b); j++)
2548 sym = BLOCK_SYM (b, j);
2549 if ((regexp == 0 || re_exec (SYMBOL_NAME (sym)))
2550 && ((class == 0 && SYMBOL_CLASS (sym) != LOC_TYPEDEF
2551 && SYMBOL_CLASS (sym) != LOC_BLOCK)
2552 || (class == 1 && SYMBOL_CLASS (sym) == LOC_BLOCK)
2553 || (class == 2 && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
2554 || (class == 3 && SYMBOL_CLASS (sym) == LOC_BLOCK)))
2558 /* Set a breakpoint here, if it's a function */
2560 break_command (SYMBOL_NAME(sym), 0);
2562 else if (!found_in_file)
2564 fputs_filtered ("\nFile ", stdout);
2565 fputs_filtered (s->filename, stdout);
2566 fputs_filtered (":\n", stdout);
2570 if (class != 2 && i == STATIC_BLOCK)
2571 printf_filtered ("static ");
2573 /* Typedef that is not a C++ class */
2575 && SYMBOL_NAMESPACE (sym) != STRUCT_NAMESPACE)
2576 typedef_print (SYMBOL_TYPE(sym), sym, stdout);
2577 /* variable, func, or typedef-that-is-c++-class */
2578 else if (class < 2 ||
2580 SYMBOL_NAMESPACE(sym) == STRUCT_NAMESPACE))
2582 type_print (SYMBOL_TYPE (sym),
2583 (SYMBOL_CLASS (sym) == LOC_TYPEDEF
2584 ? "" : SYMBOL_NAME (sym)),
2587 printf_filtered (";\n");
2593 type_print_base (TYPE_FN_FIELD_TYPE(t, i), stdout, 0, 0);
2594 type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t, i), stdout, 0);
2595 sprintf (buf, " %s::", type_name_no_tag (t));
2596 type_print_method_args (TYPE_FN_FIELD_ARGS (t, i), buf, name, stdout);
2606 /* If there are no eyes, avoid all contact. I mean, if there are
2607 no debug symbols, then print directly from the misc_function_vector. */
2609 if (found_misc || class != 1) {
2611 for (i = 0; i < misc_function_count; i++) {
2612 if (misc_function_vector[i].type != ourtype
2613 && misc_function_vector[i].type != ourtype2)
2615 if (regexp == 0 || re_exec (misc_function_vector[i].name)) {
2616 /* Functions: Look up by address. */
2618 if (0 != find_pc_symtab (misc_function_vector[i].address))
2620 /* Variables/Absolutes: Look up by name */
2621 if (0 != lookup_symbol (misc_function_vector[i].name,
2622 (struct block *)0, VAR_NAMESPACE, 0, (struct symtab **)0))
2624 if (!found_in_file) {
2625 printf_filtered ("\nNon-debugging symbols:\n");
2628 printf_filtered (" %08x %s\n",
2629 misc_function_vector[i].address,
2630 misc_function_vector[i].name);
2637 variables_info (regexp)
2640 list_symbols (regexp, 0, 0);
2644 functions_info (regexp)
2647 list_symbols (regexp, 1, 0);
2654 list_symbols (regexp, 2, 0);
2658 /* Tiemann says: "info methods was never implemented." */
2660 methods_info (regexp)
2663 list_symbols (regexp, 3, 0);
2667 /* Breakpoint all functions matching regular expression. */
2669 rbreak_command (regexp)
2672 list_symbols (regexp, 1, 1);
2675 /* Helper function to initialize the standard scalar types. */
2678 init_type (code, length, uns, name)
2679 enum type_code code;
2683 register struct type *type;
2685 type = (struct type *) xmalloc (sizeof (struct type));
2686 bzero (type, sizeof *type);
2687 TYPE_CODE (type) = code;
2688 TYPE_LENGTH (type) = length;
2689 TYPE_FLAGS (type) = uns ? TYPE_FLAG_UNSIGNED : 0;
2690 TYPE_FLAGS (type) |= TYPE_FLAG_PERM;
2691 TYPE_NFIELDS (type) = 0;
2692 TYPE_NAME (type) = name;
2695 if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION)
2696 INIT_CPLUS_SPECIFIC(type);
2700 /* Return Nonzero if block a is lexically nested within block b,
2701 or if a and b have the same pc range.
2702 Return zero otherwise. */
2705 struct block *a, *b;
2709 return BLOCK_START (a) >= BLOCK_START (b)
2710 && BLOCK_END (a) <= BLOCK_END (b);
2714 /* Helper routine for make_symbol_completion_list. */
2716 int return_val_size, return_val_index;
2720 completion_list_add_symbol (symname)
2723 if (return_val_index + 3 > return_val_size)
2725 (char **)xrealloc (return_val,
2726 (return_val_size *= 2) * sizeof (char *));
2728 return_val[return_val_index] =
2729 (char *)xmalloc (1 + strlen (symname));
2731 strcpy (return_val[return_val_index], symname);
2733 return_val[++return_val_index] = (char *)NULL;
2736 /* Return a NULL terminated array of all symbols (regardless of class) which
2737 begin by matching TEXT. If the answer is no symbols, then the return value
2738 is an array which contains only a NULL pointer.
2740 Problem: All of the symbols have to be copied because readline
2741 frees them. I'm not going to worry about this; hopefully there
2742 won't be that many. */
2745 make_symbol_completion_list (text)
2748 register struct symtab *s;
2749 register struct partial_symtab *ps;
2750 register struct block *b, *surrounding_static_block = 0;
2751 extern struct block *get_selected_block ();
2753 struct partial_symbol *psym;
2755 int text_len = strlen (text);
2756 return_val_size = 100;
2757 return_val_index = 0;
2759 (char **)xmalloc ((1 + return_val_size) *sizeof (char *));
2760 return_val[0] = (char *)NULL;
2762 /* Look through the partial symtabs for all symbols which begin
2763 by matching TEXT. Add each one that you find to the list. */
2765 for (ps = partial_symtab_list; ps; ps = ps->next)
2767 /* If the psymtab's been read in we'll get it when we search
2768 through the blockvector. */
2769 if (ps->readin) continue;
2771 for (psym = global_psymbols.list + ps->globals_offset;
2772 psym < (global_psymbols.list + ps->globals_offset
2773 + ps->n_global_syms);
2776 QUIT; /* If interrupted, then quit. */
2777 if ((strncmp (SYMBOL_NAME (psym), text, text_len) == 0))
2778 completion_list_add_symbol (SYMBOL_NAME (psym));
2781 for (psym = static_psymbols.list + ps->statics_offset;
2782 psym < (static_psymbols.list + ps->statics_offset
2783 + ps->n_static_syms);
2787 if ((strncmp (SYMBOL_NAME (psym), text, text_len) == 0))
2788 completion_list_add_symbol (SYMBOL_NAME (psym));
2792 /* At this point scan through the misc function vector and add each
2793 symbol you find to the list. Eventually we want to ignore
2794 anything that isn't a text symbol (everything else will be
2795 handled by the psymtab code above). */
2797 for (i = 0; i < misc_function_count; i++)
2798 if (!strncmp (text, misc_function_vector[i].name, text_len))
2799 completion_list_add_symbol (misc_function_vector[i].name);
2801 /* Search upwards from currently selected frame (so that we can
2802 complete on local vars. */
2803 for (b = get_selected_block (); b; b = BLOCK_SUPERBLOCK (b))
2805 if (!BLOCK_SUPERBLOCK (b))
2806 surrounding_static_block = b; /* For elmin of dups */
2808 /* Also catch fields of types defined in this places which
2809 match our text string. Only complete on types visible
2810 from current context. */
2811 for (i = 0; i < BLOCK_NSYMS (b); i++)
2813 register struct symbol *sym = BLOCK_SYM (b, i);
2815 if (!strncmp (SYMBOL_NAME (sym), text, text_len))
2816 completion_list_add_symbol (SYMBOL_NAME (sym));
2818 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF)
2820 struct type *t = SYMBOL_TYPE (sym);
2821 enum type_code c = TYPE_CODE (t);
2823 if (c == TYPE_CODE_UNION || c == TYPE_CODE_STRUCT)
2824 for (j = TYPE_N_BASECLASSES (t); j < TYPE_NFIELDS (t); j++)
2825 if (TYPE_FIELD_NAME (t, j) &&
2826 !strncmp (TYPE_FIELD_NAME (t, j), text, text_len))
2827 completion_list_add_symbol (TYPE_FIELD_NAME (t, j));
2832 /* Go through the symtabs and check the externs and statics for
2833 symbols which match. */
2835 for (s = symtab_list; s; s = s->next)
2837 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
2839 for (i = 0; i < BLOCK_NSYMS (b); i++)
2840 if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b, i)), text, text_len))
2841 completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b, i)));
2844 for (s = symtab_list; s; s = s->next)
2846 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
2848 /* Don't do this block twice. */
2849 if (b == surrounding_static_block) continue;
2851 for (i = 0; i < BLOCK_NSYMS (b); i++)
2852 if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b, i)), text, text_len))
2853 completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b, i)));
2856 return (return_val);
2860 /* Add the type of the symbol sym to the type of the current
2861 function whose block we are in (assumed). The type of
2862 this current function is contained in *TYPE.
2864 This basically works as follows: When we find a function
2865 symbol (N_FUNC with a 'f' or 'F' in the symbol name), we record
2866 a pointer to its type in the global in_function_type. Every
2867 time we come across a parameter symbol ('p' in its name), then
2868 this procedure adds the name and type of that parameter
2869 to the function type pointed to by *TYPE. (Which should correspond
2870 to in_function_type if it was called correctly).
2872 Note that since we are modifying a type, the result of
2873 lookup_function_type() should be bcopy()ed before calling
2874 this. When not in strict typing mode, the expression
2875 evaluator can choose to ignore this.
2877 Assumption: All of a function's parameter symbols will
2878 appear before another function symbol is found. The parameters
2879 appear in the same order in the argument list as they do in the
2883 add_param_to_type (type,sym)
2887 int num = ++(TYPE_NFIELDS(*type));
2889 if(TYPE_NFIELDS(*type)-1)
2890 TYPE_FIELDS(*type) =
2891 (struct field *)xrealloc((char *)(TYPE_FIELDS(*type)),
2892 num*sizeof(struct field));
2894 TYPE_FIELDS(*type) =
2895 (struct field *)xmalloc(num*sizeof(struct field));
2897 TYPE_FIELD_BITPOS(*type,num-1) = num-1;
2898 TYPE_FIELD_BITSIZE(*type,num-1) = 0;
2899 TYPE_FIELD_TYPE(*type,num-1) = SYMBOL_TYPE(sym);
2900 TYPE_FIELD_NAME(*type,num-1) = SYMBOL_NAME(sym);
2905 _initialize_symtab ()
2907 add_info ("variables", variables_info,
2908 "All global and static variable names, or those matching REGEXP.");
2909 add_info ("functions", functions_info,
2910 "All function names, or those matching REGEXP.");
2912 /* FIXME: This command has at least the following problems:
2913 1. It prints builtin types (in a very strange and confusing fashion).
2914 2. It doesn't print right, e.g. with
2915 typedef struct foo *FOO
2916 type_print prints "FOO" when we want to make it (in this situation)
2917 print "struct foo *".
2918 I also think "ptype" or "whatis" is more likely to be useful (but if
2919 there is much disagreement "info types" can be fixed). */
2920 add_info ("types", types_info,
2921 "All type names, or those matching REGEXP.");
2924 add_info ("methods", methods_info,
2925 "All method names, or those matching REGEXP::REGEXP.\n\
2926 If the class qualifier is ommited, it is assumed to be the current scope.\n\
2927 If the first REGEXP is ommited, then all methods matching the second REGEXP\n\
2930 add_info ("sources", sources_info,
2931 "Source files in the program.");
2933 add_com ("rbreak", no_class, rbreak_command,
2934 "Set a breakpoint for all functions matching REGEXP.");
2936 /* Initialize the one built-in type that isn't language dependent... */
2937 builtin_type_error = init_type (TYPE_CODE_ERROR, 0, 0, "<unknown type>");