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. */
36 #include <sys/types.h>
41 extern char *getenv ();
43 extern char *cplus_demangle ();
44 extern char *cplus_mangle_opname ();
45 extern struct value *value_of_this ();
46 extern void break_command ();
47 extern void select_source_symtab ();
49 /* Functions this file defines */
50 static int find_line_common ();
51 struct partial_symtab *lookup_partial_symtab ();
52 static struct partial_symbol *lookup_partial_symbol ();
53 static struct partial_symbol *lookup_demangled_partial_symbol ();
54 static struct symbol *lookup_demangled_block_symbol ();
56 /* The single non-language-specific builtin type */
57 struct type *builtin_type_error;
59 /* Block in which the most recently searched-for symbol was found.
60 Might be better to make this a parameter to lookup_symbol and
62 struct block *block_found;
64 char no_symtab_msg[] = "No symbol table is loaded. Use the \"file\" command.";
66 /* Check for a symtab of a specific name; first in symtabs, then in
67 psymtabs. *If* there is no '/' in the name, a match after a '/'
68 in the symtab filename will also work. */
70 static struct symtab *
71 lookup_symtab_1 (name)
74 register struct symtab *s;
75 register struct partial_symtab *ps;
76 register char *slash = strchr (name, '/');
77 register int len = strlen (name);
79 for (s = symtab_list; s; s = s->next)
80 if (!strcmp (name, s->filename))
83 for (ps = partial_symtab_list; ps; ps = ps->next)
84 if (!strcmp (name, ps->filename))
87 error ("Internal: readin pst for `%s' found when no symtab found.", name);
88 return PSYMTAB_TO_SYMTAB (ps);
93 for (s = symtab_list; s; s = s->next)
95 int l = strlen (s->filename);
97 if (s->filename[l - len -1] == '/'
98 && !strcmp (s->filename + l - len, name))
102 for (ps = partial_symtab_list; ps; ps = ps->next)
104 int l = strlen (ps->filename);
106 if (ps->filename[l - len - 1] == '/'
107 && !strcmp (ps->filename + l - len, name))
110 error ("Internal: readin pst for `%s' found when no symtab found.", name);
111 return PSYMTAB_TO_SYMTAB (ps);
118 /* Lookup the symbol table of a source file named NAME. Try a couple
119 of variations if the first lookup doesn't work. */
125 register struct symtab *s;
128 s = lookup_symtab_1 (name);
131 /* If name not found as specified, see if adding ".c" helps. */
133 copy = (char *) alloca (strlen (name) + 3);
136 s = lookup_symtab_1 (copy);
139 /* We didn't find anything; die. */
143 /* Lookup the partial symbol table of a source file named NAME. This
144 only returns true on an exact match (ie. this semantics are
145 different from lookup_symtab. */
147 struct partial_symtab *
148 lookup_partial_symtab (name)
151 register struct partial_symtab *s;
153 for (s = partial_symtab_list; s; s = s->next)
154 if (!strcmp (name, s->filename))
160 /* Return a typename for a struct/union/enum type
161 without the tag qualifier. If the type has a NULL name,
164 type_name_no_tag (type)
165 register struct type *type;
167 register char *name = TYPE_NAME (type);
172 switch (TYPE_CODE (type))
174 case TYPE_CODE_STRUCT:
175 if(!strncmp(name,"struct ",7))
178 case TYPE_CODE_UNION:
179 if(!strncmp(name,"union ",6))
183 if(!strncmp(name,"enum ",5))
188 return TYPE_NAME (type);
191 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
193 If this is a stubbed struct (i.e. declared as struct foo *), see if
194 we can find a full definition in some other file. If so, copy this
195 definition, so we can use it in future. If not, set a flag so we
196 don't waste too much time in future. (FIXME, this doesn't seem
199 This used to be coded as a macro, but I don't think it is called
200 often enough to merit such treatment.
203 struct complaint stub_noname_complaint =
204 {"stub type has NULL name", 0, 0};
207 check_stub_type(type)
210 if (TYPE_FLAGS(type) & TYPE_FLAG_STUB)
212 char* name= type_name_no_tag (type);
216 complain (&stub_noname_complaint, 0);
219 sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0,
220 (struct symtab **)NULL);
222 bcopy (SYMBOL_TYPE(sym), type, sizeof (struct type));
226 /* Demangle a GDB method stub type. */
228 gdb_mangle_name (type, i, j)
232 int mangled_name_len;
234 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
235 struct fn_field *method = &f[j];
236 char *field_name = TYPE_FN_FIELDLIST_NAME (type, i);
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 = (strlen (field_name)
249 + strlen (TYPE_FN_FIELD_PHYSNAME (f, j))
252 if (OPNAME_PREFIX_P (field_name))
254 char *opname = cplus_mangle_opname (field_name + 3);
256 error ("No mangling for \"%s\"", field_name);
257 mangled_name_len += strlen (opname);
258 mangled_name = (char *)xmalloc (mangled_name_len);
260 strncpy (mangled_name, field_name, 3);
261 mangled_name[3] = '\0';
262 strcat (mangled_name, opname);
266 mangled_name = (char *)xmalloc (mangled_name_len);
267 strcpy (mangled_name, TYPE_FN_FIELDLIST_NAME (type, i));
269 strcat (mangled_name, buf);
270 strcat (mangled_name, newname);
271 strcat (mangled_name, TYPE_FN_FIELD_PHYSNAME (f, j));
276 /* Lookup a primitive type named NAME.
277 Return zero if NAME is not a primitive type.*/
280 lookup_primitive_typename (name)
283 struct type ** const *p;
285 for (p = current_language->la_builtin_type_vector; *p; p++)
286 if(!strcmp((**p)->name, name))
291 /* Lookup a typedef or primitive type named NAME,
292 visible in lexical block BLOCK.
293 If NOERR is nonzero, return zero if NAME is not suitably defined. */
296 lookup_typename (name, block, noerr)
301 register struct symbol *sym =
302 lookup_symbol (name, block, VAR_NAMESPACE, 0, (struct symtab **)NULL);
303 if (sym == 0 || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
306 tmp = lookup_primitive_typename (name);
309 else if (!tmp && noerr)
312 error ("No type named %s.", name);
314 return SYMBOL_TYPE (sym);
318 lookup_unsigned_typename (name)
321 char *uns = alloca (strlen(name) + 10);
323 strcpy (uns, "unsigned ");
324 strcpy (uns+9, name);
325 return lookup_typename (uns, (struct block *)0, 0);
328 /* Lookup a structure type named "struct NAME",
329 visible in lexical block BLOCK. */
332 lookup_struct (name, block)
336 register struct symbol *sym
337 = lookup_symbol (name, block, STRUCT_NAMESPACE, 0, (struct symtab **)NULL);
340 error ("No struct type named %s.", name);
341 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
342 error ("This context has class, union or enum %s, not a struct.", name);
343 return SYMBOL_TYPE (sym);
346 /* Lookup a union type named "union NAME",
347 visible in lexical block BLOCK. */
350 lookup_union (name, block)
354 register struct symbol *sym
355 = lookup_symbol (name, block, STRUCT_NAMESPACE, 0, (struct symtab **)NULL);
358 error ("No union type named %s.", name);
359 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_UNION)
360 error ("This context has class, struct or enum %s, not a union.", name);
361 return SYMBOL_TYPE (sym);
364 /* Lookup an enum type named "enum NAME",
365 visible in lexical block BLOCK. */
368 lookup_enum (name, block)
372 register struct symbol *sym
373 = lookup_symbol (name, block, STRUCT_NAMESPACE, 0, (struct symtab **)NULL);
375 error ("No enum type named %s.", name);
376 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
377 error ("This context has class, struct or union %s, not an enum.", name);
378 return SYMBOL_TYPE (sym);
381 /* Lookup a template type named "template NAME<TYPE>",
382 visible in lexical block BLOCK. */
385 lookup_template_type (name, type, block)
391 char *nam = (char*) alloca(strlen(name) + strlen(type->name) + 4);
394 strcat(nam, type->name);
395 strcat(nam, " >"); /* extra space still introduced in gcc? */
397 sym = lookup_symbol (nam, block, VAR_NAMESPACE, 0, (struct symtab **)NULL);
400 error ("No template type named %s.", name);
401 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
402 error ("This context has class, union or enum %s, not a struct.", name);
403 return SYMBOL_TYPE (sym);
406 /* Given a type TYPE, lookup the type of the component of type named
408 If NOERR is nonzero, return zero if NAME is not suitably defined. */
411 lookup_struct_elt_type (type, name, noerr)
418 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
419 && TYPE_CODE (type) != TYPE_CODE_UNION)
421 target_terminal_ours ();
423 fprintf (stderr, "Type ");
424 type_print (type, "", stderr, -1);
425 error (" is not a structure or union type.");
428 check_stub_type (type);
430 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
432 char *t_field_name = TYPE_FIELD_NAME (type, i);
434 if (t_field_name && !strcmp (t_field_name, name))
435 return TYPE_FIELD_TYPE (type, i);
437 /* OK, it's not in this class. Recursively check the baseclasses. */
438 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
440 struct type *t = lookup_struct_elt_type (TYPE_BASECLASS (type, i),
449 target_terminal_ours ();
451 fprintf (stderr, "Type ");
452 type_print (type, "", stderr, -1);
453 fprintf (stderr, " has no component named ");
454 fputs_filtered (name, stderr);
456 return (struct type *)-1; /* For lint */
459 /* Given a type TYPE, return a type of pointers to that type.
460 May need to construct such a type if this is the first use.
462 C++: use TYPE_MAIN_VARIANT and TYPE_CHAIN to keep pointer
463 to member types under control. */
466 lookup_pointer_type (type)
469 register struct type *ptype = TYPE_POINTER_TYPE (type);
470 if (ptype) return TYPE_MAIN_VARIANT (ptype);
472 /* This is the first time anyone wanted a pointer to a TYPE. */
473 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
474 ptype = (struct type *) xmalloc (sizeof (struct type));
476 ptype = (struct type *) obstack_alloc (symbol_obstack,
477 sizeof (struct type));
479 bzero (ptype, sizeof (struct type));
480 TYPE_MAIN_VARIANT (ptype) = ptype;
481 TYPE_TARGET_TYPE (ptype) = type;
482 TYPE_POINTER_TYPE (type) = ptype;
483 /* New type is permanent if type pointed to is permanent. */
484 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
485 TYPE_FLAGS (ptype) |= TYPE_FLAG_PERM;
486 /* We assume the machine has only one representation for pointers! */
487 /* FIXME: This confuses host<->target data representations, and is a
488 poor assumption besides. */
489 TYPE_LENGTH (ptype) = sizeof (char *);
490 TYPE_CODE (ptype) = TYPE_CODE_PTR;
495 lookup_reference_type (type)
498 register struct type *rtype = TYPE_REFERENCE_TYPE (type);
499 if (rtype) return TYPE_MAIN_VARIANT (rtype);
501 /* This is the first time anyone wanted a pointer to a TYPE. */
502 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
503 rtype = (struct type *) xmalloc (sizeof (struct type));
505 rtype = (struct type *) obstack_alloc (symbol_obstack,
506 sizeof (struct type));
508 bzero (rtype, sizeof (struct type));
509 TYPE_MAIN_VARIANT (rtype) = rtype;
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 = TYPE_MAIN_VARIANT (type);
532 struct type *main_type;
537 if (TYPE_DOMAIN_TYPE (mtype) == domain)
539 mtype = TYPE_NEXT_VARIANT (mtype);
542 /* This is the first time anyone wanted this member type. */
543 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
544 mtype = (struct type *) xmalloc (sizeof (struct type));
546 mtype = (struct type *) obstack_alloc (symbol_obstack,
547 sizeof (struct type));
549 bzero (mtype, sizeof (struct type));
554 TYPE_NEXT_VARIANT (mtype) = TYPE_NEXT_VARIANT (main_type);
555 TYPE_NEXT_VARIANT (main_type) = mtype;
557 TYPE_MAIN_VARIANT (mtype) = main_type;
558 TYPE_TARGET_TYPE (mtype) = type;
559 TYPE_DOMAIN_TYPE (mtype) = domain;
560 /* New type is permanent if type pointed to is permanent. */
561 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
562 TYPE_FLAGS (mtype) |= TYPE_FLAG_PERM;
564 /* In practice, this is never used. */
565 TYPE_LENGTH (mtype) = 1;
566 TYPE_CODE (mtype) = TYPE_CODE_MEMBER;
569 /* Now splice in the new member pointer type. */
572 /* This type was not "smashed". */
573 TYPE_CHAIN (mtype) = TYPE_CHAIN (main_type);
574 TYPE_CHAIN (main_type) = mtype;
581 /* Allocate a stub method whose return type is
582 TYPE. We will fill in arguments later. This always
583 returns a fresh type. If we unify this type with
584 an existing type later, the storage allocated
585 here can be freed. */
587 allocate_stub_method (type)
590 struct type *mtype = (struct type *)xmalloc (sizeof (struct type));
591 bzero (mtype, sizeof (struct type));
592 TYPE_MAIN_VARIANT (mtype) = mtype;
593 TYPE_TARGET_TYPE (mtype) = type;
594 TYPE_FLAGS (mtype) = TYPE_FLAG_STUB;
595 TYPE_CODE (mtype) = TYPE_CODE_METHOD;
596 TYPE_LENGTH (mtype) = 1;
600 /* Lookup a method type belonging to class DOMAIN, returning type TYPE,
601 and taking a list of arguments ARGS.
602 If one is not found, allocate a new one. */
605 lookup_method_type (domain, type, args)
606 struct type *domain, *type, **args;
608 register struct type *mtype = TYPE_MAIN_VARIANT (type);
609 struct type *main_type;
614 if (TYPE_DOMAIN_TYPE (mtype) == domain)
616 struct type **t1 = args;
617 struct type **t2 = TYPE_ARG_TYPES (mtype);
621 for (i = 0; t1[i] != 0 && t1[i]->code != TYPE_CODE_VOID; i++)
628 mtype = TYPE_NEXT_VARIANT (mtype);
631 /* This is the first time anyone wanted this member type. */
632 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
633 mtype = (struct type *) xmalloc (sizeof (struct type));
635 mtype = (struct type *) obstack_alloc (symbol_obstack,
636 sizeof (struct type));
638 bzero (mtype, sizeof (struct type));
643 TYPE_NEXT_VARIANT (mtype) = TYPE_NEXT_VARIANT (main_type);
644 TYPE_NEXT_VARIANT (main_type) = mtype;
646 TYPE_MAIN_VARIANT (mtype) = main_type;
647 TYPE_TARGET_TYPE (mtype) = type;
648 TYPE_DOMAIN_TYPE (mtype) = domain;
649 TYPE_ARG_TYPES (mtype) = args;
650 /* New type is permanent if type pointed to is permanent. */
651 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
652 TYPE_FLAGS (mtype) |= TYPE_FLAG_PERM;
654 /* In practice, this is never used. */
655 TYPE_LENGTH (mtype) = 1;
656 TYPE_CODE (mtype) = TYPE_CODE_METHOD;
659 /* Now splice in the new member pointer type. */
662 /* This type was not "smashed". */
663 TYPE_CHAIN (mtype) = TYPE_CHAIN (main_type);
664 TYPE_CHAIN (main_type) = mtype;
672 /* Given a type TYPE, return a type which has offset OFFSET,
673 via_virtual VIA_VIRTUAL, and via_public VIA_PUBLIC.
674 May need to construct such a type if none exists. */
676 lookup_basetype_type (type, offset, via_virtual, via_public)
679 int via_virtual, via_public;
681 register struct type *btype = TYPE_MAIN_VARIANT (type);
682 struct type *main_type;
686 printf ("Internal error: type offset non-zero in lookup_basetype_type");
693 if (/* TYPE_OFFSET (btype) == offset
694 && */ TYPE_VIA_PUBLIC (btype) == via_public
695 && TYPE_VIA_VIRTUAL (btype) == via_virtual)
697 btype = TYPE_NEXT_VARIANT (btype);
700 /* This is the first time anyone wanted this member type. */
701 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
702 btype = (struct type *) xmalloc (sizeof (struct type));
704 btype = (struct type *) obstack_alloc (symbol_obstack,
705 sizeof (struct type));
710 bzero (btype, sizeof (struct type));
711 TYPE_MAIN_VARIANT (btype) = main_type;
715 bcopy (main_type, btype, sizeof (struct type));
716 TYPE_NEXT_VARIANT (main_type) = btype;
718 /* TYPE_OFFSET (btype) = offset; */
720 TYPE_FLAGS (btype) |= TYPE_FLAG_VIA_PUBLIC;
722 TYPE_FLAGS (btype) |= TYPE_FLAG_VIA_VIRTUAL;
723 /* New type is permanent if type pointed to is permanent. */
724 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
725 TYPE_FLAGS (btype) |= TYPE_FLAG_PERM;
727 /* In practice, this is never used. */
728 TYPE_LENGTH (btype) = 1;
729 TYPE_CODE (btype) = TYPE_CODE_STRUCT;
735 /* Given a type TYPE, return a type of functions that return that type.
736 May need to construct such a type if this is the first use. */
739 lookup_function_type (type)
742 register struct type *ptype = TYPE_FUNCTION_TYPE (type);
743 if (ptype) return ptype;
745 /* This is the first time anyone wanted a function returning a TYPE. */
746 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
747 ptype = (struct type *) xmalloc (sizeof (struct type));
749 ptype = (struct type *) obstack_alloc (symbol_obstack,
750 sizeof (struct type));
752 bzero (ptype, sizeof (struct type));
753 TYPE_TARGET_TYPE (ptype) = type;
754 TYPE_FUNCTION_TYPE (type) = ptype;
755 /* New type is permanent if type returned is permanent. */
756 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
757 TYPE_FLAGS (ptype) |= TYPE_FLAG_PERM;
758 TYPE_LENGTH (ptype) = 1;
759 TYPE_CODE (ptype) = TYPE_CODE_FUNC;
760 TYPE_NFIELDS (ptype) = 0;
764 /* Create an array type. Elements will be of type TYPE, and there will
767 Eventually this should be extended to take two more arguments which
768 specify the bounds of the array and the type of the index.
769 It should also be changed to be a "lookup" function, with the
770 appropriate data structures added to the type field.
771 Then read array type should call here. */
774 create_array_type (element_type, number)
775 struct type *element_type;
778 struct type *result_type = (struct type *)
779 obstack_alloc (symbol_obstack, sizeof (struct type));
780 struct type *range_type;
782 bzero (result_type, sizeof (struct type));
784 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
785 TYPE_TARGET_TYPE (result_type) = element_type;
786 TYPE_LENGTH (result_type) = number * TYPE_LENGTH (element_type);
787 TYPE_NFIELDS (result_type) = 1;
788 TYPE_FIELDS (result_type) =
789 (struct field *) obstack_alloc (symbol_obstack, sizeof (struct field));
792 /* Create range type. */
793 range_type = (struct type *) obstack_alloc (symbol_obstack,
794 sizeof (struct type));
795 TYPE_CODE (range_type) = TYPE_CODE_RANGE;
796 TYPE_TARGET_TYPE (range_type) = builtin_type_int; /* FIXME */
798 /* This should never be needed. */
799 TYPE_LENGTH (range_type) = sizeof (int);
801 TYPE_NFIELDS (range_type) = 2;
802 TYPE_FIELDS (range_type) =
803 (struct field *) obstack_alloc (symbol_obstack,
804 2 * sizeof (struct field));
805 TYPE_FIELD_BITPOS (range_type, 0) = 0; /* FIXME */
806 TYPE_FIELD_BITPOS (range_type, 1) = number-1; /* FIXME */
807 TYPE_FIELD_TYPE (range_type, 0) = builtin_type_int; /* FIXME */
808 TYPE_FIELD_TYPE (range_type, 1) = builtin_type_int; /* FIXME */
810 TYPE_FIELD_TYPE(result_type,0)=range_type;
811 TYPE_VPTR_FIELDNO (result_type) = -1;
817 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE. */
820 smash_to_member_type (type, domain, to_type)
821 struct type *type, *domain, *to_type;
823 bzero (type, sizeof (struct type));
824 TYPE_TARGET_TYPE (type) = to_type;
825 TYPE_DOMAIN_TYPE (type) = domain;
827 /* In practice, this is never needed. */
828 TYPE_LENGTH (type) = 1;
829 TYPE_CODE (type) = TYPE_CODE_MEMBER;
831 TYPE_MAIN_VARIANT (type) = lookup_member_type (domain, to_type);
834 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE. */
837 smash_to_method_type (type, domain, to_type, args)
838 struct type *type, *domain, *to_type, **args;
840 bzero (type, sizeof (struct type));
841 TYPE_TARGET_TYPE (type) = to_type;
842 TYPE_DOMAIN_TYPE (type) = domain;
843 TYPE_ARG_TYPES (type) = args;
845 /* In practice, this is never needed. */
846 TYPE_LENGTH (type) = 1;
847 TYPE_CODE (type) = TYPE_CODE_METHOD;
849 TYPE_MAIN_VARIANT (type) = lookup_method_type (domain, to_type, args);
852 /* Find which partial symtab on the partial_symtab_list contains
853 PC. Return 0 if none. */
855 struct partial_symtab *
857 register CORE_ADDR pc;
859 register struct partial_symtab *ps;
861 for (ps = partial_symtab_list; ps; ps = ps->next)
862 if (pc >= ps->textlow && pc < ps->texthigh)
868 /* Find which partial symbol within a psymtab contains PC. Return 0
869 if none. Check all psymtabs if PSYMTAB is 0. */
870 struct partial_symbol *
871 find_pc_psymbol (psymtab, pc)
872 struct partial_symtab *psymtab;
875 struct partial_symbol *best, *p;
879 psymtab = find_pc_psymtab (pc);
883 best_pc = psymtab->textlow - 1;
885 for (p = static_psymbols.list + psymtab->statics_offset;
886 (p - (static_psymbols.list + psymtab->statics_offset)
887 < psymtab->n_static_syms);
889 if (SYMBOL_NAMESPACE (p) == VAR_NAMESPACE
890 && SYMBOL_CLASS (p) == LOC_BLOCK
891 && pc >= SYMBOL_VALUE_ADDRESS (p)
892 && SYMBOL_VALUE_ADDRESS (p) > best_pc)
894 best_pc = SYMBOL_VALUE_ADDRESS (p);
897 if (best_pc == psymtab->textlow - 1)
903 /* Find the definition for a specified symbol name NAME
904 in namespace NAMESPACE, visible from lexical block BLOCK.
905 Returns the struct symbol pointer, or zero if no symbol is found.
906 If SYMTAB is non-NULL, store the symbol table in which the
907 symbol was found there, or NULL if not found.
908 C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
909 NAME is a field of the current implied argument `this'. If so set
910 *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
911 BLOCK_FOUND is set to the block in which NAME is found (in the case of
912 a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
915 lookup_symbol (name, block, namespace, is_a_field_of_this, symtab)
917 register struct block *block;
918 enum namespace namespace;
919 int *is_a_field_of_this;
920 struct symtab **symtab;
922 register struct symbol *sym;
923 register struct symtab *s;
924 register struct partial_symtab *ps;
925 struct blockvector *bv;
927 /* Search specified block and its superiors. */
931 sym = lookup_block_symbol (block, name, namespace);
937 /* Search the list of symtabs for one which contains the
938 address of the start of this block. */
940 for (s = symtab_list; s; s = s->next)
942 bv = BLOCKVECTOR (s);
943 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
944 if (BLOCK_START (b) <= BLOCK_START (block)
945 && BLOCK_END (b) > BLOCK_START (block))
953 block = BLOCK_SUPERBLOCK (block);
956 /* But that doesn't do any demangling for the STATIC_BLOCK.
957 I'm not sure whether demangling is needed in the case of
958 nested function in inner blocks; if so this needs to be changed.
960 Don't need to mess with the psymtabs; if we have a block,
961 that file is read in. If we don't, then we deal later with
962 all the psymtab stuff that needs checking. */
963 if (namespace == VAR_NAMESPACE && block != NULL)
966 /* Find the right symtab. */
967 for (s = symtab_list; s; s = s->next)
969 bv = BLOCKVECTOR (s);
970 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
971 if (BLOCK_START (b) <= BLOCK_START (block)
972 && BLOCK_END (b) > BLOCK_START (block))
974 sym = lookup_demangled_block_symbol (b, name);
987 /* C++: If requested to do so by the caller,
988 check to see if NAME is a field of `this'. */
989 if (is_a_field_of_this)
991 struct value *v = value_of_this (0);
993 *is_a_field_of_this = 0;
994 if (v && check_field (v, name))
996 *is_a_field_of_this = 1;
1003 /* Now search all global blocks. Do the symtab's first, then
1004 check the psymtab's */
1006 for (s = symtab_list; s; s = s->next)
1008 bv = BLOCKVECTOR (s);
1009 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1010 sym = lookup_block_symbol (block, name, namespace);
1013 block_found = block;
1020 /* Check for the possibility of the symbol being a global function
1021 that is stored on the misc function vector. Eventually, all
1022 global symbols might be resolved in this way. */
1024 if (namespace == VAR_NAMESPACE)
1026 int ind = lookup_misc_func (name);
1028 /* Look for a mangled C++ name for NAME. */
1031 int name_len = strlen (name);
1033 for (ind = misc_function_count; --ind >= 0; )
1034 /* Assume orginal name is prefix of mangled name. */
1035 if (!strncmp (misc_function_vector[ind].name, name, name_len))
1038 cplus_demangle(misc_function_vector[ind].name, -1);
1039 if (demangled != NULL)
1041 int cond = strcmp (demangled, name);
1047 /* Loop terminates on no match with ind == -1. */
1052 s = find_pc_symtab (misc_function_vector[ind].address);
1053 /* If S is zero, there are no debug symbols for this file.
1054 Skip this stuff and check for matching static symbols below. */
1057 bv = BLOCKVECTOR (s);
1058 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1059 sym = lookup_block_symbol (block, misc_function_vector[ind].name,
1061 /* sym == 0 if symbol was found in the misc_function_vector
1062 but not in the symtab.
1063 Return 0 to use the misc_function definition of "foo_".
1065 This happens for Fortran "foo_" symbols,
1066 which are "foo" in the symtab.
1068 This can also happen if "asm" is used to make a
1069 regular symbol but not a debugging symbol, e.g.
1070 asm(".globl _main");
1081 for (ps = partial_symtab_list; ps; ps = ps->next)
1082 if (!ps->readin && lookup_partial_symbol (ps, name, 1, namespace))
1084 s = PSYMTAB_TO_SYMTAB(ps);
1085 bv = BLOCKVECTOR (s);
1086 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1087 sym = lookup_block_symbol (block, name, namespace);
1089 error ("Internal: global symbol `%s' found in psymtab but not in symtab", name);
1095 /* Now search all per-file blocks.
1096 Not strictly correct, but more useful than an error.
1097 Do the symtabs first, then check the psymtabs */
1099 for (s = symtab_list; s; s = s->next)
1101 bv = BLOCKVECTOR (s);
1102 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1103 sym = lookup_block_symbol (block, name, namespace);
1106 block_found = block;
1113 for (ps = partial_symtab_list; ps; ps = ps->next)
1114 if (!ps->readin && lookup_partial_symbol (ps, name, 0, namespace))
1116 s = PSYMTAB_TO_SYMTAB(ps);
1117 bv = BLOCKVECTOR (s);
1118 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1119 sym = lookup_block_symbol (block, name, namespace);
1121 error ("Internal: static symbol `%s' found in psymtab but not in symtab", name);
1127 /* Now search all per-file blocks for static mangled symbols.
1128 Do the symtabs first, then check the psymtabs. */
1130 if (namespace == VAR_NAMESPACE)
1132 for (s = symtab_list; s; s = s->next)
1134 bv = BLOCKVECTOR (s);
1135 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1136 sym = lookup_demangled_block_symbol (block, name);
1139 block_found = block;
1146 for (ps = partial_symtab_list; ps; ps = ps->next)
1147 if (!ps->readin && lookup_demangled_partial_symbol (ps, name))
1149 s = PSYMTAB_TO_SYMTAB(ps);
1150 bv = BLOCKVECTOR (s);
1151 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1152 sym = lookup_demangled_block_symbol (block, name);
1154 error ("Internal: mangled static symbol `%s' found in psymtab but not in symtab", name);
1166 /* Look for a static demangled symbol in block BLOCK. */
1168 static struct symbol *
1169 lookup_demangled_block_symbol (block, name)
1170 register struct block *block;
1173 register int bot, top, inc;
1174 register struct symbol *sym;
1177 top = BLOCK_NSYMS (block);
1182 sym = BLOCK_SYM (block, bot);
1183 if (SYMBOL_NAME (sym)[0] == inc
1184 && SYMBOL_NAMESPACE (sym) == VAR_NAMESPACE)
1186 char *demangled = cplus_demangle(SYMBOL_NAME (sym), -1);
1187 if (demangled != NULL)
1189 int cond = strcmp (demangled, name);
1201 /* Look, in partial_symtab PST, for static mangled symbol NAME. */
1203 static struct partial_symbol *
1204 lookup_demangled_partial_symbol (pst, name)
1205 struct partial_symtab *pst;
1208 struct partial_symbol *start, *psym;
1209 int length = pst->n_static_syms;
1210 register int inc = name[0];
1213 return (struct partial_symbol *) 0;
1215 start = static_psymbols.list + pst->statics_offset;
1216 for (psym = start; psym < start + length; psym++)
1218 if (SYMBOL_NAME (psym)[0] == inc
1219 && SYMBOL_NAMESPACE (psym) == VAR_NAMESPACE)
1221 char *demangled = cplus_demangle(SYMBOL_NAME (psym), -1);
1222 if (demangled != NULL)
1224 int cond = strcmp (demangled, name);
1232 return (struct partial_symbol *) 0;
1235 /* Look, in partial_symtab PST, for symbol NAME. Check the global
1236 symbols if GLOBAL, the static symbols if not */
1238 static struct partial_symbol *
1239 lookup_partial_symbol (pst, name, global, namespace)
1240 struct partial_symtab *pst;
1243 enum namespace namespace;
1245 struct partial_symbol *start, *psym;
1246 int length = (global ? pst->n_global_syms : pst->n_static_syms);
1249 return (struct partial_symbol *) 0;
1252 global_psymbols.list + pst->globals_offset :
1253 static_psymbols.list + pst->statics_offset );
1255 if (global) /* This means we can use a binary */
1258 struct partial_symbol *top, *bottom, *center;
1260 /* Binary search. This search is guaranteed to end with center
1261 pointing at the earliest partial symbol with the correct
1262 name. At that point *all* partial symbols with that name
1263 will be checked against the correct namespace. */
1265 top = start + length - 1;
1266 while (top > bottom)
1268 center = bottom + (top - bottom) / 2;
1270 assert (center < top);
1272 if (strcmp (SYMBOL_NAME (center), name) >= 0)
1275 bottom = center + 1;
1277 assert (top == bottom);
1279 while (!strcmp (SYMBOL_NAME (top), name))
1281 if (SYMBOL_NAMESPACE (top) == namespace)
1288 /* Can't use a binary search */
1289 for (psym = start; psym < start + length; psym++)
1290 if (namespace == SYMBOL_NAMESPACE (psym)
1291 && !strcmp (name, SYMBOL_NAME (psym)))
1295 return (struct partial_symbol *) 0;
1298 /* Find the psymtab containing main(). */
1300 struct partial_symtab *
1301 find_main_psymtab ()
1303 register struct partial_symtab *pst;
1304 for (pst = partial_symtab_list; pst; pst = pst->next)
1305 if (lookup_partial_symbol (pst, "main", 1, VAR_NAMESPACE))
1310 /* Look for a symbol in block BLOCK. */
1313 lookup_block_symbol (block, name, namespace)
1314 register struct block *block;
1316 enum namespace namespace;
1318 register int bot, top, inc;
1319 register struct symbol *sym, *parameter_sym;
1321 top = BLOCK_NSYMS (block);
1324 /* If the blocks's symbols were sorted, start with a binary search. */
1326 if (BLOCK_SHOULD_SORT (block))
1328 /* First, advance BOT to not far before
1329 the first symbol whose name is NAME. */
1333 inc = (top - bot + 1);
1334 /* No need to keep binary searching for the last few bits worth. */
1337 inc = (inc >> 1) + bot;
1338 sym = BLOCK_SYM (block, inc);
1339 if (SYMBOL_NAME (sym)[0] < name[0])
1341 else if (SYMBOL_NAME (sym)[0] > name[0])
1343 else if (strcmp (SYMBOL_NAME (sym), name) < 0)
1349 /* Now scan forward until we run out of symbols,
1350 find one whose name is greater than NAME,
1351 or find one we want.
1352 If there is more than one symbol with the right name and namespace,
1353 we return the first one. dbxread.c is careful to make sure
1354 that if one is a register then it comes first. */
1356 top = BLOCK_NSYMS (block);
1359 sym = BLOCK_SYM (block, bot);
1360 inc = SYMBOL_NAME (sym)[0] - name[0];
1362 inc = strcmp (SYMBOL_NAME (sym), name);
1363 if (inc == 0 && SYMBOL_NAMESPACE (sym) == namespace)
1372 /* Here if block isn't sorted.
1373 This loop is equivalent to the loop above,
1374 but hacked greatly for speed.
1376 Note that parameter symbols do not always show up last in the
1377 list; this loop makes sure to take anything else other than
1378 parameter symbols first; it only uses parameter symbols as a
1379 last resort. Note that this only takes up extra computation
1382 parameter_sym = (struct symbol *) 0;
1383 top = BLOCK_NSYMS (block);
1387 sym = BLOCK_SYM (block, bot);
1388 if (SYMBOL_NAME (sym)[0] == inc
1389 && !strcmp (SYMBOL_NAME (sym), name)
1390 && SYMBOL_NAMESPACE (sym) == namespace)
1392 if (SYMBOL_CLASS (sym) == LOC_ARG
1393 || SYMBOL_CLASS (sym) == LOC_LOCAL_ARG
1394 || SYMBOL_CLASS (sym) == LOC_REF_ARG
1395 || SYMBOL_CLASS (sym) == LOC_REGPARM)
1396 parameter_sym = sym;
1402 return parameter_sym; /* Will be 0 if not found. */
1405 /* Return the symbol for the function which contains a specified
1406 lexical block, described by a struct block BL. */
1412 while (BLOCK_FUNCTION (bl) == 0 && BLOCK_SUPERBLOCK (bl) != 0)
1413 bl = BLOCK_SUPERBLOCK (bl);
1415 return BLOCK_FUNCTION (bl);
1418 /* Subroutine of find_pc_line */
1422 register CORE_ADDR pc;
1424 register struct block *b;
1425 struct blockvector *bv;
1426 register struct symtab *s;
1427 register struct partial_symtab *ps;
1429 /* Search all symtabs for one whose file contains our pc */
1431 for (s = symtab_list; s; s = s->next)
1433 bv = BLOCKVECTOR (s);
1434 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1435 if (BLOCK_START (b) <= pc
1436 && BLOCK_END (b) > pc)
1442 ps = find_pc_psymtab (pc);
1443 if (ps && ps->readin)
1445 "(Internal error: pc 0x%x in read in psymtab, but not in symtab.)\n", pc);
1448 s = PSYMTAB_TO_SYMTAB (ps);
1454 /* Find the source file and line number for a given PC value.
1455 Return a structure containing a symtab pointer, a line number,
1456 and a pc range for the entire source line.
1457 The value's .pc field is NOT the specified pc.
1458 NOTCURRENT nonzero means, if specified pc is on a line boundary,
1459 use the line that ends there. Otherwise, in that case, the line
1460 that begins there is used. */
1462 struct symtab_and_line
1463 find_pc_line (pc, notcurrent)
1468 register struct linetable *l;
1471 register struct linetable_entry *item;
1472 struct symtab_and_line val;
1473 struct blockvector *bv;
1475 /* Info on best line seen so far, and where it starts, and its file. */
1478 CORE_ADDR best_pc = 0;
1479 CORE_ADDR best_end = 0;
1480 struct symtab *best_symtab = 0;
1482 /* Store here the first line number
1483 of a file which contains the line at the smallest pc after PC.
1484 If we don't find a line whose range contains PC,
1485 we will use a line one less than this,
1486 with a range from the start of that file to the first line's pc. */
1488 CORE_ADDR alt_pc = 0;
1489 struct symtab *alt_symtab = 0;
1491 /* Info on best line seen in this file. */
1496 /* Info on first line of this file. */
1501 /* If this pc is not from the current frame,
1502 it is the address of the end of a call instruction.
1503 Quite likely that is the start of the following statement.
1504 But what we want is the statement containing the instruction.
1505 Fudge the pc to make sure we get that. */
1507 if (notcurrent) pc -= 1;
1509 s = find_pc_symtab (pc);
1519 bv = BLOCKVECTOR (s);
1521 /* Look at all the symtabs that share this blockvector.
1522 They all have the same apriori range, that we found was right;
1523 but they have different line tables. */
1525 for (; s && BLOCKVECTOR (s) == bv; s = s->next)
1527 /* Find the best line in this symtab. */
1534 for (i = 0; i < len; i++)
1536 item = &(l->item[i]);
1540 first_line = item->line;
1541 first_pc = item->pc;
1543 /* Return the last line that did not start after PC. */
1546 prev_line = item->line;
1553 /* Is this file's best line closer than the best in the other files?
1554 If so, record this file, and its best line, as best so far. */
1555 if (prev_line >= 0 && prev_pc > best_pc)
1558 best_line = prev_line;
1561 best_end = item->pc;
1565 /* Is this file's first line closer than the first lines of other files?
1566 If so, record this file, and its first line, as best alternate. */
1567 if (first_line >= 0 && first_pc > pc
1568 && (alt_pc == 0 || first_pc < alt_pc))
1571 alt_line = first_line;
1575 if (best_symtab == 0)
1577 val.symtab = alt_symtab;
1578 val.line = alt_line - 1;
1579 val.pc = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
1584 val.symtab = best_symtab;
1585 val.line = best_line;
1587 val.end = (best_end ? best_end
1589 : BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK))));
1594 /* Find the PC value for a given source file and line number.
1595 Returns zero for invalid line number.
1596 The source file is specified with a struct symtab. */
1599 find_line_pc (symtab, line)
1600 struct symtab *symtab;
1603 register struct linetable *l;
1609 l = LINETABLE (symtab);
1610 ind = find_line_common(l, line, &dummy);
1611 return (ind >= 0) ? l->item[ind].pc : 0;
1614 /* Find the range of pc values in a line.
1615 Store the starting pc of the line into *STARTPTR
1616 and the ending pc (start of next line) into *ENDPTR.
1617 Returns 1 to indicate success.
1618 Returns 0 if could not find the specified line. */
1621 find_line_pc_range (symtab, thisline, startptr, endptr)
1622 struct symtab *symtab;
1624 CORE_ADDR *startptr, *endptr;
1626 register struct linetable *l;
1628 int exact_match; /* did we get an exact linenumber match */
1633 l = LINETABLE (symtab);
1634 ind = find_line_common (l, thisline, &exact_match);
1637 *startptr = l->item[ind].pc;
1638 /* If we have not seen an entry for the specified line,
1639 assume that means the specified line has zero bytes. */
1640 if (!exact_match || ind == l->nitems-1)
1641 *endptr = *startptr;
1643 /* Perhaps the following entry is for the following line.
1644 It's worth a try. */
1645 if (ind+1 < l->nitems
1646 && l->item[ind+1].line == thisline + 1)
1647 *endptr = l->item[ind+1].pc;
1649 *endptr = find_line_pc (symtab, thisline+1);
1656 /* Given a line table and a line number, return the index into the line
1657 table for the pc of the nearest line whose number is >= the specified one.
1658 Return -1 if none is found. The value is >= 0 if it is an index.
1660 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
1663 find_line_common (l, lineno, exact_match)
1664 register struct linetable *l;
1665 register int lineno;
1671 /* BEST is the smallest linenumber > LINENO so far seen,
1672 or 0 if none has been seen so far.
1673 BEST_INDEX identifies the item for it. */
1675 int best_index = -1;
1684 for (i = 0; i < len; i++)
1686 register struct linetable_entry *item = &(l->item[i]);
1688 if (item->line == lineno)
1694 if (item->line > lineno && (best == 0 || item->line < best))
1701 /* If we got here, we didn't get an exact match. */
1708 find_pc_line_pc_range (pc, startptr, endptr)
1710 CORE_ADDR *startptr, *endptr;
1712 struct symtab_and_line sal;
1713 sal = find_pc_line (pc, 0);
1716 return sal.symtab != 0;
1719 /* If P is of the form "operator[ \t]+..." where `...' is
1720 some legitimate operator text, return a pointer to the
1721 beginning of the substring of the operator text.
1722 Otherwise, return "". */
1724 operator_chars (p, end)
1729 if (strncmp (p, "operator", 8))
1733 /* Don't get faked out by `operator' being part of a longer
1735 if ((*p >= 'A' && *p <= 'Z') || (*p >= 'a' && *p <= 'z')
1736 || *p == '_' || *p == '$' || *p == '\0')
1739 /* Allow some whitespace between `operator' and the operator symbol. */
1740 while (*p == ' ' || *p == '\t')
1762 if (p[1] == '=' || p[1] == p[0])
1773 error ("`operator ()' must be specified without whitespace in `()'");
1778 error ("`operator ?:' must be specified without whitespace in `?:'");
1783 error ("`operator []' must be specified without whitespace in `[]'");
1787 error ("`operator %s' not supported", p);
1794 /* Recursive helper function for decode_line_1.
1795 * Look for methods named NAME in type T.
1796 * Return number of matches.
1797 * Put matches in PHYSNAMES and SYM_ARR (which better be big enough!).
1798 * These allocations seem to define "big enough":
1799 * sym_arr = (struct symbol **) alloca(TYPE_NFN_FIELDS_TOTAL (t) * sizeof(struct symbol*));
1800 * physnames = (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t) * sizeof(char*));
1804 find_methods(t, name, physnames, sym_arr)
1808 struct symbol **sym_arr;
1812 struct symbol *sym_class;
1813 char *class_name = type_name_no_tag (t);
1814 /* Ignore this class if it doesn't have a name.
1815 This prevents core dumps, but is just a workaround
1816 because we might not find the function in
1817 certain cases, such as
1818 struct D {virtual int f();}
1819 struct C : D {virtual int g();}
1820 (in this case g++ 1.35.1- does not put out a name
1821 for D as such, it defines type 19 (for example) in
1822 the same stab as C, and then does a
1823 .stabs "D:T19" and a .stabs "D:t19".
1825 "break C::f" should not be looking for field f in
1827 but just for the field f in the baseclasses of C
1828 (no matter what their names).
1830 However, I don't know how to replace the code below
1831 that depends on knowing the name of D. */
1833 && (sym_class = lookup_symbol (class_name,
1834 (struct block *)NULL,
1837 (struct symtab **)NULL)))
1840 t = SYMBOL_TYPE (sym_class);
1841 for (method_counter = TYPE_NFN_FIELDS (t) - 1;
1842 method_counter >= 0;
1846 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, method_counter);
1848 char *method_name = TYPE_FN_FIELDLIST_NAME (t, method_counter);
1849 if (!strcmp (name, method_name))
1850 /* Find all the fields with that name. */
1851 for (field_counter = TYPE_FN_FIELDLIST_LENGTH (t, method_counter) - 1;
1856 if (TYPE_FLAGS (TYPE_FN_FIELD_TYPE (f, field_counter)) & TYPE_FLAG_STUB)
1857 check_stub_method (t, method_counter, field_counter);
1858 phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter);
1859 physnames[i1] = (char*) alloca (strlen (phys_name) + 1);
1860 strcpy (physnames[i1], phys_name);
1861 sym_arr[i1] = lookup_symbol (phys_name,
1862 SYMBOL_BLOCK_VALUE (sym_class),
1865 (struct symtab **) NULL);
1866 if (sym_arr[i1]) i1++;
1870 /* Only search baseclasses if there is no match yet,
1871 * since names in derived classes override those in baseclasses.
1875 for (ibase = 0; ibase < TYPE_N_BASECLASSES (t); ibase++)
1876 i1 += find_methods(TYPE_BASECLASS(t, ibase), name,
1877 physnames + i1, sym_arr + i1);
1881 /* Parse a string that specifies a line number.
1882 Pass the address of a char * variable; that variable will be
1883 advanced over the characters actually parsed.
1887 LINENUM -- that line number in current file. PC returned is 0.
1888 FILE:LINENUM -- that line in that file. PC returned is 0.
1889 FUNCTION -- line number of openbrace of that function.
1890 PC returned is the start of the function.
1891 VARIABLE -- line number of definition of that variable.
1893 FILE:FUNCTION -- likewise, but prefer functions in that file.
1894 *EXPR -- line in which address EXPR appears.
1896 FUNCTION may be an undebuggable function found in misc_function_vector.
1898 If the argument FUNFIRSTLINE is nonzero, we want the first line
1899 of real code inside a function when a function is specified.
1901 DEFAULT_SYMTAB specifies the file to use if none is specified.
1902 It defaults to current_source_symtab.
1903 DEFAULT_LINE specifies the line number to use for relative
1904 line numbers (that start with signs). Defaults to current_source_line.
1906 Note that it is possible to return zero for the symtab
1907 if no file is validly specified. Callers must check that.
1908 Also, the line number returned may be invalid. */
1910 struct symtabs_and_lines
1911 decode_line_1 (argptr, funfirstline, default_symtab, default_line)
1914 struct symtab *default_symtab;
1917 struct symtabs_and_lines decode_line_2 ();
1918 struct symtabs_and_lines values;
1919 struct symtab_and_line val;
1920 register char *p, *p1;
1922 register struct symtab *s;
1924 register struct symbol *sym;
1925 /* The symtab that SYM was found in. */
1926 struct symtab *sym_symtab;
1928 register CORE_ADDR pc;
1931 struct symbol *sym_class;
1933 struct symbol **sym_arr;
1937 /* Defaults have defaults. */
1939 if (default_symtab == 0)
1941 default_symtab = current_source_symtab;
1942 default_line = current_source_line;
1945 /* See if arg is *PC */
1947 if (**argptr == '*')
1950 pc = parse_and_eval_address_1 (argptr);
1951 values.sals = (struct symtab_and_line *)
1952 xmalloc (sizeof (struct symtab_and_line));
1954 values.sals[0] = find_pc_line (pc, 0);
1955 values.sals[0].pc = pc;
1959 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
1963 for (p = *argptr; *p; p++)
1965 if (p[0] == ':' || p[0] == ' ' || p[0] == '\t')
1968 while (p[0] == ' ' || p[0] == '\t') p++;
1976 /* Extract the class name. */
1978 while (p != *argptr && p[-1] == ' ') --p;
1979 copy = (char *) alloca (p - *argptr + 1);
1980 bcopy (*argptr, copy, p - *argptr);
1981 copy[p - *argptr] = 0;
1983 /* Discard the class name from the arg. */
1985 while (*p == ' ' || *p == '\t') p++;
1988 sym_class = lookup_symbol (copy, 0, STRUCT_NAMESPACE, 0,
1989 (struct symtab **)NULL);
1992 (TYPE_CODE (SYMBOL_TYPE (sym_class)) == TYPE_CODE_STRUCT
1993 || TYPE_CODE (SYMBOL_TYPE (sym_class)) == TYPE_CODE_UNION))
1995 /* Arg token is not digits => try it as a function name
1996 Find the next token (everything up to end or next whitespace). */
1998 while (*p && *p != ' ' && *p != '\t' && *p != ',' && *p !=':') p++;
1999 q = operator_chars (*argptr, &q1);
2001 copy = (char *) alloca (p - *argptr + 1 + (q1 - q));
2006 copy[2] = CPLUS_MARKER;
2007 bcopy (q, copy + 3, q1 - q);
2008 copy[3 + (q1 - q)] = '\0';
2013 bcopy (*argptr, copy, p - *argptr);
2014 copy[p - *argptr] = '\0';
2017 /* no line number may be specified */
2018 while (*p == ' ' || *p == '\t') p++;
2022 i1 = 0; /* counter for the symbol array */
2023 t = SYMBOL_TYPE (sym_class);
2024 sym_arr = (struct symbol **) alloca(TYPE_NFN_FIELDS_TOTAL (t) * sizeof(struct symbol*));
2025 physnames = (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t) * sizeof(char*));
2027 if (destructor_name_p (copy, t))
2029 /* destructors are a special case. */
2030 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, 0);
2031 int len = TYPE_FN_FIELDLIST_LENGTH (t, 0) - 1;
2032 char *phys_name = TYPE_FN_FIELD_PHYSNAME (f, len);
2033 physnames[i1] = (char *)alloca (strlen (phys_name) + 1);
2034 strcpy (physnames[i1], phys_name);
2036 lookup_symbol (phys_name, SYMBOL_BLOCK_VALUE (sym_class),
2037 VAR_NAMESPACE, 0, (struct symtab **)NULL);
2038 if (sym_arr[i1]) i1++;
2041 i1 = find_methods (t, copy, physnames, sym_arr);
2044 /* There is exactly one field with that name. */
2047 if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
2049 /* Arg is the name of a function */
2050 pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) + FUNCTION_START_OFFSET;
2053 values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line));
2055 values.sals[0] = find_pc_line (pc, 0);
2056 values.sals[0].pc = (values.sals[0].end && values.sals[0].pc != pc) ? values.sals[0].end : pc;
2066 /* There is more than one field with that name
2067 (overloaded). Ask the user which one to use. */
2068 return decode_line_2 (sym_arr, i1, funfirstline);
2074 if (OPNAME_PREFIX_P (copy))
2076 tmp = (char *)alloca (strlen (copy+3) + 9);
2077 strcpy (tmp, "operator ");
2078 strcat (tmp, copy+3);
2083 error ("The class `%s' does not have destructor defined",
2086 error ("The class %s does not have any method named %s",
2087 sym_class->name, tmp);
2091 /* The quotes are important if copy is empty. */
2092 error("No class, struct, or union named \"%s\"", copy );
2097 /* Extract the file name. */
2099 while (p != *argptr && p[-1] == ' ') --p;
2100 copy = (char *) alloca (p - *argptr + 1);
2101 bcopy (*argptr, copy, p - *argptr);
2102 copy[p - *argptr] = 0;
2104 /* Find that file's data. */
2105 s = lookup_symtab (copy);
2108 if (symtab_list == 0 && partial_symtab_list == 0)
2109 error (no_symtab_msg);
2110 error ("No source file named %s.", copy);
2113 /* Discard the file name from the arg. */
2115 while (*p == ' ' || *p == '\t') p++;
2119 /* S is specified file's symtab, or 0 if no file specified.
2120 arg no longer contains the file name. */
2122 /* Check whether arg is all digits (and sign) */
2125 if (*p == '-' || *p == '+') p++;
2126 while (*p >= '0' && *p <= '9')
2129 if (p != *argptr && (*p == 0 || *p == ' ' || *p == '\t' || *p == ','))
2131 /* We found a token consisting of all digits -- at least one digit. */
2132 enum sign {none, plus, minus} sign = none;
2134 /* This is where we need to make sure that we have good defaults.
2135 We must guarantee that this section of code is never executed
2136 when we are called with just a function name, since
2137 select_source_symtab calls us with such an argument */
2139 if (s == 0 && default_symtab == 0)
2141 select_source_symtab (0);
2142 default_symtab = current_source_symtab;
2143 default_line = current_source_line;
2146 if (**argptr == '+')
2147 sign = plus, (*argptr)++;
2148 else if (**argptr == '-')
2149 sign = minus, (*argptr)++;
2150 val.line = atoi (*argptr);
2157 val.line = default_line + val.line;
2163 val.line = default_line - val.line;
2168 break; /* No need to adjust val.line. */
2171 while (*p == ' ' || *p == '\t') p++;
2177 values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line));
2178 values.sals[0] = val;
2183 /* Arg token is not digits => try it as a variable name
2184 Find the next token (everything up to end or next whitespace). */
2186 while (*p && *p != ' ' && *p != '\t' && *p != ',') p++;
2187 copy = (char *) alloca (p - *argptr + 1);
2188 bcopy (*argptr, copy, p - *argptr);
2189 copy[p - *argptr] = 0;
2190 while (*p == ' ' || *p == '\t') p++;
2193 /* Look up that token as a variable.
2194 If file specified, use that file's per-file block to start with. */
2196 sym = lookup_symbol (copy,
2197 (s ? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)
2198 : get_selected_block ()),
2199 VAR_NAMESPACE, 0, &sym_symtab);
2203 if (SYMBOL_CLASS (sym) == LOC_BLOCK)
2205 /* Arg is the name of a function */
2206 pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) + FUNCTION_START_OFFSET;
2209 val = find_pc_line (pc, 0);
2210 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2211 /* Convex: no need to suppress code on first line, if any */
2214 val.pc = (val.end && val.pc != pc) ? val.end : pc;
2216 values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line));
2217 values.sals[0] = val;
2220 /* I think this is always the same as the line that
2221 we calculate above, but the general principle is
2222 "trust the symbols more than stuff like
2224 if (SYMBOL_LINE (sym) != 0)
2225 values.sals[0].line = SYMBOL_LINE (sym);
2229 else if (SYMBOL_LINE (sym) != 0)
2231 /* We know its line number. */
2232 values.sals = (struct symtab_and_line *)
2233 xmalloc (sizeof (struct symtab_and_line));
2235 bzero (&values.sals[0], sizeof (values.sals[0]));
2236 values.sals[0].symtab = sym_symtab;
2237 values.sals[0].line = SYMBOL_LINE (sym);
2241 /* This can happen if it is compiled with a compiler which doesn't
2242 put out line numbers for variables. */
2243 error ("Line number not known for symbol \"%s\"", copy);
2246 if ((i = lookup_misc_func (copy)) >= 0)
2250 val.pc = misc_function_vector[i].address + FUNCTION_START_OFFSET;
2252 SKIP_PROLOGUE (val.pc);
2253 values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line));
2254 values.sals[0] = val;
2259 if (symtab_list == 0 && partial_symtab_list == 0 && misc_function_count == 0)
2260 error (no_symtab_msg);
2262 error ("Function %s not defined.", copy);
2263 return values; /* for lint */
2266 struct symtabs_and_lines
2267 decode_line_spec (string, funfirstline)
2271 struct symtabs_and_lines sals;
2273 error ("Empty line specification.");
2274 sals = decode_line_1 (&string, funfirstline,
2275 current_source_symtab, current_source_line);
2277 error ("Junk at end of line specification: %s", string);
2281 /* Given a list of NELTS symbols in sym_arr (with corresponding
2282 mangled names in physnames), return a list of lines to operate on
2283 (ask user if necessary). */
2284 struct symtabs_and_lines
2285 decode_line_2 (sym_arr, nelts, funfirstline)
2286 struct symbol *sym_arr[];
2290 struct symtabs_and_lines values, return_values;
2291 register CORE_ADDR pc;
2292 char *args, *arg1, *command_line_input ();
2296 values.sals = (struct symtab_and_line *) alloca (nelts * sizeof(struct symtab_and_line));
2297 return_values.sals = (struct symtab_and_line *) xmalloc (nelts * sizeof(struct symtab_and_line));
2300 printf("[0] cancel\n[1] all\n");
2303 if (sym_arr[i] && SYMBOL_CLASS (sym_arr[i]) == LOC_BLOCK)
2305 /* Arg is the name of a function */
2306 pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym_arr[i]))
2307 + FUNCTION_START_OFFSET;
2310 values.sals[i] = find_pc_line (pc, 0);
2311 values.sals[i].pc = (values.sals[i].end && values.sals[i].pc != pc) ?
2312 values.sals[i].end : pc;
2313 printf("[%d] file:%s; line number:%d\n",
2314 (i+2), values.sals[i].symtab->filename, values.sals[i].line);
2316 else printf ("?HERE\n");
2320 if ((prompt = getenv ("PS2")) == NULL)
2324 printf("%s ",prompt);
2327 args = command_line_input (0, 0);
2330 error_no_arg ("one or more choice numbers");
2338 while (*arg1 >= '0' && *arg1 <= '9') arg1++;
2339 if (*arg1 && *arg1 != ' ' && *arg1 != '\t')
2340 error ("Arguments must be choice numbers.");
2345 error ("cancelled");
2348 bcopy (values.sals, return_values.sals, (nelts * sizeof(struct symtab_and_line)));
2349 return_values.nelts = nelts;
2350 return return_values;
2353 if (num > nelts + 2)
2355 printf ("No choice number %d.\n", num);
2360 if (values.sals[num].pc)
2362 return_values.sals[i++] = values.sals[num];
2363 values.sals[num].pc = 0;
2367 printf ("duplicate request for %d ignored.\n", num);
2372 while (*args == ' ' || *args == '\t') args++;
2374 return_values.nelts = i;
2375 return return_values;
2378 /* Return the index of misc function named NAME. */
2381 lookup_misc_func (name)
2382 register char *name;
2386 for (i = 0; i < misc_function_count; i++)
2387 if (!strcmp (misc_function_vector[i].name, name))
2389 return -1; /* not found */
2392 /* Slave routine for sources_info. Force line breaks at ,'s.
2393 NAME is the name to print and *FIRST is nonzero if this is the first
2394 name printed. Set *FIRST to zero. */
2396 output_source_filename (name, first)
2401 /* Table of files printed so far. Since a single source file can
2402 result in several partial symbol tables, we need to avoid printing
2403 it more than once. Note: if some of the psymtabs are read in and
2404 some are not, it gets printed both under "Source files for which
2405 symbols have been read" and "Source files for which symbols will
2406 be read in on demand". I consider this a reasonable way to deal
2407 with the situation. I'm not sure whether this can also happen for
2408 symtabs; it doesn't hurt to check. */
2409 static char **tab = NULL;
2410 /* Allocated size of tab in elements.
2411 Start with one 256-byte block (when using GNU malloc.c).
2412 24 is the malloc overhead when range checking is in effect. */
2413 static int tab_alloc_size = (256 - 24) / sizeof (char *);
2414 /* Current size of tab in elements. */
2415 static int tab_cur_size;
2422 tab = (char **) xmalloc (tab_alloc_size * sizeof (*tab));
2426 /* Is NAME in tab? */
2427 for (p = tab; p < tab + tab_cur_size; p++)
2428 if (strcmp (*p, name) == 0)
2429 /* Yes; don't print it again. */
2431 /* No; add it to tab. */
2432 if (tab_cur_size == tab_alloc_size)
2434 tab_alloc_size *= 2;
2435 tab = (char **) xrealloc (tab, tab_alloc_size * sizeof (*tab));
2437 tab[tab_cur_size++] = name;
2446 printf_filtered (",");
2450 if (column != 0 && column + strlen (name) >= 70)
2452 printf_filtered ("\n");
2455 else if (column != 0)
2457 printf_filtered (" ");
2460 fputs_filtered (name, stdout);
2461 column += strlen (name);
2467 register struct symtab *s;
2468 register struct partial_symtab *ps;
2471 if (symtab_list == 0 && partial_symtab_list == 0)
2473 printf (no_symtab_msg);
2477 printf_filtered ("Source files for which symbols have been read in:\n\n");
2480 for (s = symtab_list; s; s = s->next)
2481 output_source_filename (s->filename, &first);
2482 printf_filtered ("\n\n");
2484 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2487 for (ps = partial_symtab_list; ps; ps = ps->next)
2489 output_source_filename (ps->filename, &first);
2490 printf_filtered ("\n");
2493 /* List all symbols (if REGEXP is 0) or all symbols matching REGEXP.
2494 If CLASS is zero, list all symbols except functions and type names.
2495 If CLASS is 1, list only functions.
2496 If CLASS is 2, list only type names.
2497 If CLASS is 3, list only method names.
2499 BPT is non-zero if we should set a breakpoint at the functions
2503 list_symbols (regexp, class, bpt)
2508 register struct symtab *s;
2509 register struct partial_symtab *ps;
2510 register struct blockvector *bv;
2511 struct blockvector *prev_bv = 0;
2512 register struct block *b;
2514 register struct symbol *sym;
2515 struct partial_symbol *psym;
2517 static char *classnames[]
2518 = {"variable", "function", "type", "method"};
2519 int found_in_file = 0;
2521 static enum misc_function_type types[]
2522 = {mf_data, mf_text, mf_abs, mf_unknown};
2523 static enum misc_function_type types2[]
2524 = {mf_bss, mf_text, mf_abs, mf_unknown};
2525 enum misc_function_type ourtype = types[class];
2526 enum misc_function_type ourtype2 = types2[class];
2529 if (0 != (val = re_comp (regexp)))
2530 error ("Invalid regexp (%s): %s", val, regexp);
2532 /* Search through the partial_symtab_list *first* for all symbols
2533 matching the regexp. That way we don't have to reproduce all of
2534 the machinery below. */
2535 for (ps = partial_symtab_list; ps; ps = ps->next)
2537 struct partial_symbol *bound, *gbound, *sbound;
2540 if (ps->readin) continue;
2542 gbound = global_psymbols.list + ps->globals_offset + ps->n_global_syms;
2543 sbound = static_psymbols.list + ps->statics_offset + ps->n_static_syms;
2546 /* Go through all of the symbols stored in a partial
2547 symtab in one loop. */
2548 psym = global_psymbols.list + ps->globals_offset;
2553 if (bound == gbound && ps->n_static_syms != 0)
2555 psym = static_psymbols.list + ps->statics_offset;
2566 /* If it would match (logic taken from loop below)
2567 load the file and go on to the next one */
2568 if ((regexp == 0 || re_exec (SYMBOL_NAME (psym)))
2569 && ((class == 0 && SYMBOL_CLASS (psym) != LOC_TYPEDEF
2570 && SYMBOL_CLASS (psym) != LOC_BLOCK)
2571 || (class == 1 && SYMBOL_CLASS (psym) == LOC_BLOCK)
2572 || (class == 2 && SYMBOL_CLASS (psym) == LOC_TYPEDEF)
2573 || (class == 3 && SYMBOL_CLASS (psym) == LOC_BLOCK)))
2575 (void) PSYMTAB_TO_SYMTAB(ps);
2583 /* Here, we search through the misc function vector for functions that
2584 match, and call find_pc_symtab on them to force their symbols to
2585 be read. The symbol will then be found during the scan of symtabs
2586 below. If find_pc_symtab fails, set found_misc so that we will
2587 rescan to print any matching symbols without debug info. */
2590 for (i = 0; i < misc_function_count; i++) {
2591 if (misc_function_vector[i].type != ourtype
2592 && misc_function_vector[i].type != ourtype2)
2594 if (regexp == 0 || re_exec (misc_function_vector[i].name)) {
2595 if (0 == find_pc_symtab (misc_function_vector[i].address))
2601 /* Printout here so as to get after the "Reading in symbols"
2602 messages which will be generated above. */
2604 printf_filtered (regexp
2605 ? "All %ss matching regular expression \"%s\":\n"
2606 : "All defined %ss:\n",
2610 for (s = symtab_list; s; s = s->next)
2613 bv = BLOCKVECTOR (s);
2614 /* Often many files share a blockvector.
2615 Scan each blockvector only once so that
2616 we don't get every symbol many times.
2617 It happens that the first symtab in the list
2618 for any given blockvector is the main file. */
2620 for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
2622 b = BLOCKVECTOR_BLOCK (bv, i);
2623 /* Skip the sort if this block is always sorted. */
2624 if (!BLOCK_SHOULD_SORT (b))
2625 sort_block_syms (b);
2626 for (j = 0; j < BLOCK_NSYMS (b); j++)
2629 sym = BLOCK_SYM (b, j);
2630 if ((regexp == 0 || re_exec (SYMBOL_NAME (sym)))
2631 && ((class == 0 && SYMBOL_CLASS (sym) != LOC_TYPEDEF
2632 && SYMBOL_CLASS (sym) != LOC_BLOCK)
2633 || (class == 1 && SYMBOL_CLASS (sym) == LOC_BLOCK)
2634 || (class == 2 && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
2635 || (class == 3 && SYMBOL_CLASS (sym) == LOC_BLOCK)))
2639 /* Set a breakpoint here, if it's a function */
2641 break_command (SYMBOL_NAME(sym), 0);
2643 else if (!found_in_file)
2645 fputs_filtered ("\nFile ", stdout);
2646 fputs_filtered (s->filename, stdout);
2647 fputs_filtered (":\n", stdout);
2651 if (class != 2 && i == STATIC_BLOCK)
2652 printf_filtered ("static ");
2654 /* Typedef that is not a C++ class */
2656 && SYMBOL_NAMESPACE (sym) != STRUCT_NAMESPACE)
2657 typedef_print (SYMBOL_TYPE(sym), sym, stdout);
2658 /* variable, func, or typedef-that-is-c++-class */
2659 else if (class < 2 ||
2661 SYMBOL_NAMESPACE(sym) == STRUCT_NAMESPACE))
2663 type_print (SYMBOL_TYPE (sym),
2664 (SYMBOL_CLASS (sym) == LOC_TYPEDEF
2665 ? "" : SYMBOL_NAME (sym)),
2668 printf_filtered (";\n");
2674 type_print_base (TYPE_FN_FIELD_TYPE(t, i), stdout, 0, 0);
2675 type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t, i), stdout, 0);
2676 sprintf (buf, " %s::", type_name_no_tag (t));
2677 type_print_method_args (TYPE_FN_FIELD_ARGS (t, i), buf, name, stdout);
2687 /* If there are no eyes, avoid all contact. I mean, if there are
2688 no debug symbols, then print directly from the misc_function_vector. */
2690 if (found_misc || class != 1) {
2692 for (i = 0; i < misc_function_count; i++) {
2693 if (misc_function_vector[i].type != ourtype
2694 && misc_function_vector[i].type != ourtype2)
2696 if (regexp == 0 || re_exec (misc_function_vector[i].name)) {
2697 /* Functions: Look up by address. */
2699 if (0 != find_pc_symtab (misc_function_vector[i].address))
2701 /* Variables/Absolutes: Look up by name */
2702 if (0 != lookup_symbol (misc_function_vector[i].name,
2703 (struct block *)0, VAR_NAMESPACE, 0, (struct symtab **)0))
2705 if (!found_in_file) {
2706 printf_filtered ("\nNon-debugging symbols:\n");
2709 printf_filtered (" %08x %s\n",
2710 misc_function_vector[i].address,
2711 misc_function_vector[i].name);
2718 variables_info (regexp)
2721 list_symbols (regexp, 0, 0);
2725 functions_info (regexp)
2728 list_symbols (regexp, 1, 0);
2735 list_symbols (regexp, 2, 0);
2739 /* Tiemann says: "info methods was never implemented." */
2741 methods_info (regexp)
2744 list_symbols (regexp, 3, 0);
2748 /* Breakpoint all functions matching regular expression. */
2750 rbreak_command (regexp)
2753 list_symbols (regexp, 1, 1);
2756 /* Helper function to initialize the standard scalar types. */
2759 init_type (code, length, uns, name)
2760 enum type_code code;
2764 register struct type *type;
2766 type = (struct type *) xmalloc (sizeof (struct type));
2767 bzero (type, sizeof *type);
2768 TYPE_MAIN_VARIANT (type) = type;
2769 TYPE_CODE (type) = code;
2770 TYPE_LENGTH (type) = length;
2771 TYPE_FLAGS (type) = uns ? TYPE_FLAG_UNSIGNED : 0;
2772 TYPE_FLAGS (type) |= TYPE_FLAG_PERM;
2773 TYPE_NFIELDS (type) = 0;
2774 TYPE_NAME (type) = name;
2777 TYPE_NFN_FIELDS (type) = 0;
2778 TYPE_N_BASECLASSES (type) = 0;
2782 /* Return Nonzero if block a is lexically nested within block b,
2783 or if a and b have the same pc range.
2784 Return zero otherwise. */
2787 struct block *a, *b;
2791 return BLOCK_START (a) >= BLOCK_START (b)
2792 && BLOCK_END (a) <= BLOCK_END (b);
2796 /* Helper routine for make_symbol_completion_list. */
2798 int return_val_size, return_val_index;
2802 completion_list_add_symbol (symname)
2805 if (return_val_index + 3 > return_val_size)
2807 (char **)xrealloc (return_val,
2808 (return_val_size *= 2) * sizeof (char *));
2810 return_val[return_val_index] =
2811 (char *)xmalloc (1 + strlen (symname));
2813 strcpy (return_val[return_val_index], symname);
2815 return_val[++return_val_index] = (char *)NULL;
2818 /* Return a NULL terminated array of all symbols (regardless of class) which
2819 begin by matching TEXT. If the answer is no symbols, then the return value
2820 is an array which contains only a NULL pointer.
2822 Problem: All of the symbols have to be copied because readline
2823 frees them. I'm not going to worry about this; hopefully there
2824 won't be that many. */
2827 make_symbol_completion_list (text)
2830 register struct symtab *s;
2831 register struct partial_symtab *ps;
2832 register struct block *b, *surrounding_static_block = 0;
2833 extern struct block *get_selected_block ();
2835 struct partial_symbol *psym;
2837 int text_len = strlen (text);
2838 return_val_size = 100;
2839 return_val_index = 0;
2841 (char **)xmalloc ((1 + return_val_size) *sizeof (char *));
2842 return_val[0] = (char *)NULL;
2844 /* Look through the partial symtabs for all symbols which begin
2845 by matching TEXT. Add each one that you find to the list. */
2847 for (ps = partial_symtab_list; ps; ps = ps->next)
2849 /* If the psymtab's been read in we'll get it when we search
2850 through the blockvector. */
2851 if (ps->readin) continue;
2853 for (psym = global_psymbols.list + ps->globals_offset;
2854 psym < (global_psymbols.list + ps->globals_offset
2855 + ps->n_global_syms);
2858 QUIT; /* If interrupted, then quit. */
2859 if ((strncmp (SYMBOL_NAME (psym), text, text_len) == 0))
2860 completion_list_add_symbol (SYMBOL_NAME (psym));
2863 for (psym = static_psymbols.list + ps->statics_offset;
2864 psym < (static_psymbols.list + ps->statics_offset
2865 + ps->n_static_syms);
2869 if ((strncmp (SYMBOL_NAME (psym), text, text_len) == 0))
2870 completion_list_add_symbol (SYMBOL_NAME (psym));
2874 /* At this point scan through the misc function vector and add each
2875 symbol you find to the list. Eventually we want to ignore
2876 anything that isn't a text symbol (everything else will be
2877 handled by the psymtab code above). */
2879 for (i = 0; i < misc_function_count; i++)
2880 if (!strncmp (text, misc_function_vector[i].name, text_len))
2881 completion_list_add_symbol (misc_function_vector[i].name);
2883 /* Search upwards from currently selected frame (so that we can
2884 complete on local vars. */
2885 for (b = get_selected_block (); b; b = BLOCK_SUPERBLOCK (b))
2887 if (!BLOCK_SUPERBLOCK (b))
2888 surrounding_static_block = b; /* For elmin of dups */
2890 /* Also catch fields of types defined in this places which
2891 match our text string. Only complete on types visible
2892 from current context. */
2893 for (i = 0; i < BLOCK_NSYMS (b); i++)
2895 register struct symbol *sym = BLOCK_SYM (b, i);
2897 if (!strncmp (SYMBOL_NAME (sym), text, text_len))
2898 completion_list_add_symbol (SYMBOL_NAME (sym));
2900 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF)
2902 struct type *t = SYMBOL_TYPE (sym);
2903 enum type_code c = TYPE_CODE (t);
2905 if (c == TYPE_CODE_UNION || c == TYPE_CODE_STRUCT)
2906 for (j = TYPE_N_BASECLASSES (t); j < TYPE_NFIELDS (t); j++)
2907 if (TYPE_FIELD_NAME (t, j) &&
2908 !strncmp (TYPE_FIELD_NAME (t, j), text, text_len))
2909 completion_list_add_symbol (TYPE_FIELD_NAME (t, j));
2914 /* Go through the symtabs and check the externs and statics for
2915 symbols which match. */
2917 for (s = symtab_list; s; s = s->next)
2919 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
2921 for (i = 0; i < BLOCK_NSYMS (b); i++)
2922 if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b, i)), text, text_len))
2923 completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b, i)));
2926 for (s = symtab_list; s; s = s->next)
2928 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
2930 /* Don't do this block twice. */
2931 if (b == surrounding_static_block) continue;
2933 for (i = 0; i < BLOCK_NSYMS (b); i++)
2934 if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b, i)), text, text_len))
2935 completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b, i)));
2938 return (return_val);
2942 /* Add the type of the symbol sym to the type of the current
2943 function whose block we are in (assumed). The type of
2944 this current function is contained in *TYPE.
2946 This basically works as follows: When we find a function
2947 symbol (N_FUNC with a 'f' or 'F' in the symbol name), we record
2948 a pointer to its type in the global in_function_type. Every
2949 time we come across a parameter symbol ('p' in its name), then
2950 this procedure adds the name and type of that parameter
2951 to the function type pointed to by *TYPE. (Which should correspond
2952 to in_function_type if it was called correctly).
2954 Note that since we are modifying a type, the result of
2955 lookup_function_type() should be bcopy()ed before calling
2956 this. When not in strict typing mode, the expression
2957 evaluator can choose to ignore this.
2959 Assumption: All of a function's parameter symbols will
2960 appear before another function symbol is found. The parameters
2961 appear in the same order in the argument list as they do in the
2965 add_param_to_type (type,sym)
2969 int num = ++(TYPE_NFIELDS(*type));
2971 if(TYPE_NFIELDS(*type)-1)
2972 TYPE_FIELDS(*type) =
2973 (struct field *)xrealloc((char *)(TYPE_FIELDS(*type)),
2974 num*sizeof(struct field));
2976 TYPE_FIELDS(*type) =
2977 (struct field *)xmalloc(num*sizeof(struct field));
2979 TYPE_FIELD_BITPOS(*type,num-1) = num-1;
2980 TYPE_FIELD_BITSIZE(*type,num-1) = 0;
2981 TYPE_FIELD_TYPE(*type,num-1) = SYMBOL_TYPE(sym);
2982 TYPE_FIELD_NAME(*type,num-1) = SYMBOL_NAME(sym);
2987 _initialize_symtab ()
2989 add_info ("variables", variables_info,
2990 "All global and static variable names, or those matching REGEXP.");
2991 add_info ("functions", functions_info,
2992 "All function names, or those matching REGEXP.");
2994 /* FIXME: This command has at least the following problems:
2995 1. It prints builtin types (in a very strange and confusing fashion).
2996 2. It doesn't print right, e.g. with
2997 typedef struct foo *FOO
2998 type_print prints "FOO" when we want to make it (in this situation)
2999 print "struct foo *".
3000 I also think "ptype" or "whatis" is more likely to be useful (but if
3001 there is much disagreement "info types" can be fixed). */
3002 add_info ("types", types_info,
3003 "All types names, or those matching REGEXP.");
3006 add_info ("methods", methods_info,
3007 "All method names, or those matching REGEXP::REGEXP.\n\
3008 If the class qualifier is ommited, it is assumed to be the current scope.\n\
3009 If the first REGEXP is ommited, then all methods matching the second REGEXP\n\
3012 add_info ("sources", sources_info,
3013 "Source files in the program.");
3015 add_com ("rbreak", no_class, rbreak_command,
3016 "Set a breakpoint for all functions matching REGEXP.");
3018 /* Initialize the one built-in type that isn't language dependent... */
3019 builtin_type_error = init_type (TYPE_CODE_ERROR, 0, 0, "<unknown type>");