1 /* Symbol table lookup for the GNU debugger, GDB.
2 Copyright (C) 1986, 1987, 1988, 1989, 1990 Free Software Foundation, Inc.
4 This file is part of GDB.
6 GDB 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 1, or (at your option)
11 GDB 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 GDB; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
35 #include <sys/types.h>
40 extern char *getenv ();
42 extern char *cplus_demangle ();
43 extern struct value *value_of_this ();
44 extern void break_command ();
45 extern void select_source_symtab ();
47 /* Functions this file defines */
48 static int find_line_common ();
49 struct partial_symtab *lookup_partial_symtab ();
50 static struct partial_symbol *lookup_partial_symbol ();
51 static struct partial_symbol *lookup_demangled_partial_symbol ();
52 static struct symbol *lookup_demangled_block_symbol ();
54 /* These variables point to the objects
55 representing the predefined C data types. */
57 struct type *builtin_type_void;
58 struct type *builtin_type_char;
59 struct type *builtin_type_short;
60 struct type *builtin_type_int;
61 struct type *builtin_type_long;
62 struct type *builtin_type_long_long;
63 struct type *builtin_type_unsigned_char;
64 struct type *builtin_type_unsigned_short;
65 struct type *builtin_type_unsigned_int;
66 struct type *builtin_type_unsigned_long;
67 struct type *builtin_type_unsigned_long_long;
68 struct type *builtin_type_float;
69 struct type *builtin_type_double;
70 struct type *builtin_type_error;
72 /* Block in which the most recently searched-for symbol was found.
73 Might be better to make this a parameter to lookup_symbol and
75 struct block *block_found;
77 char no_symtab_msg[] = "No symbol table is loaded. Use the \"file\" command.";
79 /* Check for a symtab of a specific name; first in symtabs, then in
80 psymtabs. *If* there is no '/' in the name, a match after a '/'
81 in the symtab filename will also work. */
83 static struct symtab *
84 lookup_symtab_1 (name)
87 register struct symtab *s;
88 register struct partial_symtab *ps;
89 register char *slash = strchr (name, '/');
90 register int len = strlen (name);
92 for (s = symtab_list; s; s = s->next)
93 if (!strcmp (name, s->filename))
96 for (ps = partial_symtab_list; ps; ps = ps->next)
97 if (!strcmp (name, ps->filename))
100 fatal ("Internal: readin pst found when no symtab found.");
101 return PSYMTAB_TO_SYMTAB (ps);
106 for (s = symtab_list; s; s = s->next)
108 int l = strlen (s->filename);
110 if (s->filename[l - len -1] == '/'
111 && !strcmp (s->filename + l - len, name))
115 for (ps = partial_symtab_list; ps; ps = ps->next)
117 int l = strlen (ps->filename);
119 if (ps->filename[l - len - 1] == '/'
120 && !strcmp (ps->filename + l - len, name))
123 fatal ("Internal: readin pst found when no symtab found.");
124 return PSYMTAB_TO_SYMTAB (ps);
131 /* Lookup the symbol table of a source file named NAME. Try a couple
132 of variations if the first lookup doesn't work. */
138 register struct symtab *s;
141 s = lookup_symtab_1 (name);
144 /* If name not found as specified, see if adding ".c" helps. */
146 copy = (char *) alloca (strlen (name) + 3);
149 s = lookup_symtab_1 (copy);
152 /* We didn't find anything; die. */
156 /* Lookup the partial symbol table of a source file named NAME. This
157 only returns true on an exact match (ie. this semantics are
158 different from lookup_symtab. */
160 struct partial_symtab *
161 lookup_partial_symtab (name)
164 register struct partial_symtab *s;
166 for (s = partial_symtab_list; s; s = s->next)
167 if (!strcmp (name, s->filename))
173 /* Return a typename for a struct/union/enum type
174 without the tag qualifier. If the type has a NULL name,
177 type_name_no_tag (type)
178 register struct type *type;
180 register char *name = TYPE_NAME (type);
186 switch (TYPE_CODE (type))
188 case TYPE_CODE_STRUCT:
190 case TYPE_CODE_UNION:
197 name = strchr (name, ' ');
201 return TYPE_NAME (type);
204 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
206 If this is a stubbed struct (i.e. declared as struct foo *), see if
207 we can find a full definition in some other file. If so, copy this
208 definition, so we can use it in future. If not, set a flag so we
209 don't waste too much time in future.
211 This used to be coded as a macro, but I don't think it is called
212 often enough to merit such treatment.
215 struct complaint stub_noname_complaint =
216 {"stub type has NULL name", 0, 0};
219 check_stub_type(type)
222 if (TYPE_FLAGS(type) & TYPE_FLAG_STUB)
224 char* name= type_name_no_tag (type);
228 complain (&stub_noname_complaint, 0);
231 sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0,
232 (struct symtab **)NULL);
234 bcopy (SYMBOL_TYPE(sym), type, sizeof (struct type));
238 /* Demangle a GDB method stub type. */
240 gdb_mangle_typename (type)
243 static struct type *last_type;
244 static char *mangled_typename;
246 if (type != last_type)
248 /* Need a new type prefix. */
250 char *newname = type_name_no_tag (type);
254 if (mangled_typename)
255 free (mangled_typename);
257 len = strlen (newname);
258 sprintf (buf, "__%d", len);
259 mangled_typename = (char *)xmalloc (strlen (buf) + len + 1);
260 strcpy (mangled_typename, buf);
261 strcat (mangled_typename, newname);
262 /* Now we have built "__#newname". */
264 return mangled_typename;
267 /* Lookup a primitive type named NAME.
268 Return zero if NAME is not a primitive type.*/
271 lookup_primitive_typename (name)
274 if (!strcmp (name, "int"))
275 return builtin_type_int;
276 if (!strcmp (name, "long"))
277 return builtin_type_long;
278 if (!strcmp (name, "short"))
279 return builtin_type_short;
280 if (!strcmp (name, "char"))
281 return builtin_type_char;
282 if (!strcmp (name, "float"))
283 return builtin_type_float;
284 if (!strcmp (name, "double"))
285 return builtin_type_double;
286 if (!strcmp (name, "void"))
287 return builtin_type_void;
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 error ("No type named %s.", name);
311 return SYMBOL_TYPE (sym);
315 lookup_unsigned_typename (name)
318 if (!strcmp (name, "int"))
319 return builtin_type_unsigned_int;
320 if (!strcmp (name, "long"))
321 return builtin_type_unsigned_long;
322 if (!strcmp (name, "short"))
323 return builtin_type_unsigned_short;
324 if (!strcmp (name, "char"))
325 return builtin_type_unsigned_char;
326 error ("No type named unsigned %s.", name);
327 return (struct type *)-1; /* for lint */
330 /* Lookup a structure type named "struct NAME",
331 visible in lexical block BLOCK. */
334 lookup_struct (name, block)
338 register struct symbol *sym
339 = lookup_symbol (name, block, STRUCT_NAMESPACE, 0, (struct symtab **)NULL);
342 error ("No struct type named %s.", name);
343 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
344 error ("This context has class, union or enum %s, not a struct.", name);
345 return SYMBOL_TYPE (sym);
348 /* Lookup a union type named "union NAME",
349 visible in lexical block BLOCK. */
352 lookup_union (name, block)
356 register struct symbol *sym
357 = lookup_symbol (name, block, STRUCT_NAMESPACE, 0, (struct symtab **)NULL);
360 error ("No union type named %s.", name);
361 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_UNION)
362 error ("This context has class, struct or enum %s, not a union.", name);
363 return SYMBOL_TYPE (sym);
366 /* Lookup an enum type named "enum NAME",
367 visible in lexical block BLOCK. */
370 lookup_enum (name, block)
374 register struct symbol *sym
375 = lookup_symbol (name, block, STRUCT_NAMESPACE, 0, (struct symtab **)NULL);
377 error ("No enum type named %s.", name);
378 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
379 error ("This context has class, struct or union %s, not an enum.", name);
380 return SYMBOL_TYPE (sym);
383 /* Given a type TYPE, lookup the type of the component of type named
385 If NOERR is nonzero, return zero if NAME is not suitably defined. */
388 lookup_struct_elt_type (type, name, noerr)
395 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
396 && TYPE_CODE (type) != TYPE_CODE_UNION)
398 target_terminal_ours ();
400 fprintf (stderr, "Type ");
401 type_print (type, "", stderr, -1);
402 error (" is not a structure or union type.");
405 check_stub_type (type);
407 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
409 char *t_field_name = TYPE_FIELD_NAME (type, i);
411 if (t_field_name && !strcmp (t_field_name, name))
412 return TYPE_FIELD_TYPE (type, i);
414 /* OK, it's not in this class. Recursively check the baseclasses. */
415 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
417 struct type *t = lookup_struct_elt_type (TYPE_BASECLASS (type, i),
426 target_terminal_ours ();
428 fprintf (stderr, "Type ");
429 type_print (type, "", stderr, -1);
430 fprintf (stderr, " has no component named ");
431 fputs_filtered (name, stderr);
433 return (struct type *)-1; /* For lint */
436 /* Given a type TYPE, return a type of pointers to that type.
437 May need to construct such a type if this is the first use.
439 C++: use TYPE_MAIN_VARIANT and TYPE_CHAIN to keep pointer
440 to member types under control. */
443 lookup_pointer_type (type)
446 register struct type *ptype = TYPE_POINTER_TYPE (type);
447 if (ptype) return TYPE_MAIN_VARIANT (ptype);
449 /* This is the first time anyone wanted a pointer to a TYPE. */
450 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
451 ptype = (struct type *) xmalloc (sizeof (struct type));
453 ptype = (struct type *) obstack_alloc (symbol_obstack,
454 sizeof (struct type));
456 bzero (ptype, sizeof (struct type));
457 TYPE_MAIN_VARIANT (ptype) = ptype;
458 TYPE_TARGET_TYPE (ptype) = type;
459 TYPE_POINTER_TYPE (type) = ptype;
460 /* New type is permanent if type pointed to is permanent. */
461 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
462 TYPE_FLAGS (ptype) |= TYPE_FLAG_PERM;
463 /* We assume the machine has only one representation for pointers! */
464 TYPE_LENGTH (ptype) = sizeof (char *);
465 TYPE_CODE (ptype) = TYPE_CODE_PTR;
470 lookup_reference_type (type)
473 register struct type *rtype = TYPE_REFERENCE_TYPE (type);
474 if (rtype) return TYPE_MAIN_VARIANT (rtype);
476 /* This is the first time anyone wanted a pointer to a TYPE. */
477 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
478 rtype = (struct type *) xmalloc (sizeof (struct type));
480 rtype = (struct type *) obstack_alloc (symbol_obstack,
481 sizeof (struct type));
483 bzero (rtype, sizeof (struct type));
484 TYPE_MAIN_VARIANT (rtype) = rtype;
485 TYPE_TARGET_TYPE (rtype) = type;
486 TYPE_REFERENCE_TYPE (type) = rtype;
487 /* New type is permanent if type pointed to is permanent. */
488 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
489 TYPE_FLAGS (rtype) |= TYPE_FLAG_PERM;
490 /* We assume the machine has only one representation for pointers! */
491 TYPE_LENGTH (rtype) = sizeof (char *);
492 TYPE_CODE (rtype) = TYPE_CODE_REF;
497 /* Implement direct support for MEMBER_TYPE in GNU C++.
498 May need to construct such a type if this is the first use.
499 The TYPE is the type of the member. The DOMAIN is the type
500 of the aggregate that the member belongs to. */
503 lookup_member_type (type, domain)
504 struct type *type, *domain;
506 register struct type *mtype = TYPE_MAIN_VARIANT (type);
507 struct type *main_type;
512 if (TYPE_DOMAIN_TYPE (mtype) == domain)
514 mtype = TYPE_NEXT_VARIANT (mtype);
517 /* This is the first time anyone wanted this member type. */
518 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
519 mtype = (struct type *) xmalloc (sizeof (struct type));
521 mtype = (struct type *) obstack_alloc (symbol_obstack,
522 sizeof (struct type));
524 bzero (mtype, sizeof (struct type));
529 TYPE_NEXT_VARIANT (mtype) = TYPE_NEXT_VARIANT (main_type);
530 TYPE_NEXT_VARIANT (main_type) = mtype;
532 TYPE_MAIN_VARIANT (mtype) = main_type;
533 TYPE_TARGET_TYPE (mtype) = type;
534 TYPE_DOMAIN_TYPE (mtype) = domain;
535 /* New type is permanent if type pointed to is permanent. */
536 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
537 TYPE_FLAGS (mtype) |= TYPE_FLAG_PERM;
539 /* In practice, this is never used. */
540 TYPE_LENGTH (mtype) = 1;
541 TYPE_CODE (mtype) = TYPE_CODE_MEMBER;
544 /* Now splice in the new member pointer type. */
547 /* This type was not "smashed". */
548 TYPE_CHAIN (mtype) = TYPE_CHAIN (main_type);
549 TYPE_CHAIN (main_type) = mtype;
556 /* Allocate a stub method whose return type is
557 TYPE. We will fill in arguments later. This always
558 returns a fresh type. If we unify this type with
559 an existing type later, the storage allocated
560 here can be freed. */
562 allocate_stub_method (type)
565 struct type *mtype = (struct type *)xmalloc (sizeof (struct type));
566 bzero (mtype, sizeof (struct type));
567 TYPE_MAIN_VARIANT (mtype) = mtype;
568 TYPE_TARGET_TYPE (mtype) = type;
569 TYPE_FLAGS (mtype) = TYPE_FLAG_STUB;
570 TYPE_CODE (mtype) = TYPE_CODE_METHOD;
571 TYPE_LENGTH (mtype) = 1;
575 /* Lookup a method type returning type TYPE, belonging
576 to class DOMAIN, and taking a list of arguments ARGS.
577 If one is not found, allocate a new one. */
580 lookup_method_type (type, domain, args)
581 struct type *type, *domain, **args;
583 register struct type *mtype = TYPE_MAIN_VARIANT (type);
584 struct type *main_type;
589 if (TYPE_DOMAIN_TYPE (mtype) == domain)
591 struct type **t1 = args;
592 struct type **t2 = TYPE_ARG_TYPES (mtype);
596 for (i = 0; t1[i] != 0 && t1[i]->code != TYPE_CODE_VOID; i++)
603 mtype = TYPE_NEXT_VARIANT (mtype);
606 /* This is the first time anyone wanted this member type. */
607 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
608 mtype = (struct type *) xmalloc (sizeof (struct type));
610 mtype = (struct type *) obstack_alloc (symbol_obstack,
611 sizeof (struct type));
613 bzero (mtype, sizeof (struct type));
618 TYPE_NEXT_VARIANT (mtype) = TYPE_NEXT_VARIANT (main_type);
619 TYPE_NEXT_VARIANT (main_type) = mtype;
621 TYPE_MAIN_VARIANT (mtype) = main_type;
622 TYPE_TARGET_TYPE (mtype) = type;
623 TYPE_DOMAIN_TYPE (mtype) = domain;
624 TYPE_ARG_TYPES (mtype) = args;
625 /* New type is permanent if type pointed to is permanent. */
626 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
627 TYPE_FLAGS (mtype) |= TYPE_FLAG_PERM;
629 /* In practice, this is never used. */
630 TYPE_LENGTH (mtype) = 1;
631 TYPE_CODE (mtype) = TYPE_CODE_METHOD;
634 /* Now splice in the new member pointer type. */
637 /* This type was not "smashed". */
638 TYPE_CHAIN (mtype) = TYPE_CHAIN (main_type);
639 TYPE_CHAIN (main_type) = mtype;
647 /* Given a type TYPE, return a type which has offset OFFSET,
648 via_virtual VIA_VIRTUAL, and via_public VIA_PUBLIC.
649 May need to construct such a type if none exists. */
651 lookup_basetype_type (type, offset, via_virtual, via_public)
654 int via_virtual, via_public;
656 register struct type *btype = TYPE_MAIN_VARIANT (type);
657 struct type *main_type;
661 printf ("Internal error: type offset non-zero in lookup_basetype_type");
668 if (/* TYPE_OFFSET (btype) == offset
669 && */ TYPE_VIA_PUBLIC (btype) == via_public
670 && TYPE_VIA_VIRTUAL (btype) == via_virtual)
672 btype = TYPE_NEXT_VARIANT (btype);
675 /* This is the first time anyone wanted this member type. */
676 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
677 btype = (struct type *) xmalloc (sizeof (struct type));
679 btype = (struct type *) obstack_alloc (symbol_obstack,
680 sizeof (struct type));
685 bzero (btype, sizeof (struct type));
686 TYPE_MAIN_VARIANT (btype) = main_type;
690 bcopy (main_type, btype, sizeof (struct type));
691 TYPE_NEXT_VARIANT (main_type) = btype;
693 /* TYPE_OFFSET (btype) = offset; */
695 TYPE_FLAGS (btype) |= TYPE_FLAG_VIA_PUBLIC;
697 TYPE_FLAGS (btype) |= TYPE_FLAG_VIA_VIRTUAL;
698 /* New type is permanent if type pointed to is permanent. */
699 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
700 TYPE_FLAGS (btype) |= TYPE_FLAG_PERM;
702 /* In practice, this is never used. */
703 TYPE_LENGTH (btype) = 1;
704 TYPE_CODE (btype) = TYPE_CODE_STRUCT;
710 /* Given a type TYPE, return a type of functions that return that type.
711 May need to construct such a type if this is the first use. */
714 lookup_function_type (type)
717 register struct type *ptype = TYPE_FUNCTION_TYPE (type);
718 if (ptype) return ptype;
720 /* This is the first time anyone wanted a function returning a TYPE. */
721 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
722 ptype = (struct type *) xmalloc (sizeof (struct type));
724 ptype = (struct type *) obstack_alloc (symbol_obstack,
725 sizeof (struct type));
727 bzero (ptype, sizeof (struct type));
728 TYPE_TARGET_TYPE (ptype) = type;
729 TYPE_FUNCTION_TYPE (type) = ptype;
730 /* New type is permanent if type returned is permanent. */
731 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
732 TYPE_FLAGS (ptype) |= TYPE_FLAG_PERM;
733 TYPE_LENGTH (ptype) = 1;
734 TYPE_CODE (ptype) = TYPE_CODE_FUNC;
735 TYPE_NFIELDS (ptype) = 0;
739 /* Create an array type. Elements will be of type TYPE, and there will
742 Eventually this should be extended to take two more arguments which
743 specify the bounds of the array and the type of the index.
744 It should also be changed to be a "lookup" function, with the
745 appropriate data structures added to the type field.
746 Then read array type should call here. */
749 create_array_type (element_type, number)
750 struct type *element_type;
753 struct type *result_type = (struct type *)
754 obstack_alloc (symbol_obstack, sizeof (struct type));
756 bzero (result_type, sizeof (struct type));
758 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
759 TYPE_TARGET_TYPE (result_type) = element_type;
760 TYPE_LENGTH (result_type) = number * TYPE_LENGTH (element_type);
761 TYPE_NFIELDS (result_type) = 1;
762 TYPE_FIELDS (result_type) =
763 (struct field *) obstack_alloc (symbol_obstack, sizeof (struct field));
764 TYPE_FIELD_TYPE (result_type, 0) = builtin_type_int;
765 TYPE_VPTR_FIELDNO (result_type) = -1;
771 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE. */
774 smash_to_member_type (type, domain, to_type)
775 struct type *type, *domain, *to_type;
777 bzero (type, sizeof (struct type));
778 TYPE_TARGET_TYPE (type) = to_type;
779 TYPE_DOMAIN_TYPE (type) = domain;
781 /* In practice, this is never needed. */
782 TYPE_LENGTH (type) = 1;
783 TYPE_CODE (type) = TYPE_CODE_MEMBER;
785 TYPE_MAIN_VARIANT (type) = lookup_member_type (domain, to_type);
788 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE. */
791 smash_to_method_type (type, domain, to_type, args)
792 struct type *type, *domain, *to_type, **args;
794 bzero (type, sizeof (struct type));
795 TYPE_TARGET_TYPE (type) = to_type;
796 TYPE_DOMAIN_TYPE (type) = domain;
797 TYPE_ARG_TYPES (type) = args;
799 /* In practice, this is never needed. */
800 TYPE_LENGTH (type) = 1;
801 TYPE_CODE (type) = TYPE_CODE_METHOD;
803 TYPE_MAIN_VARIANT (type) = lookup_method_type (domain, to_type, args);
806 /* Find which partial symtab on the partial_symtab_list contains
807 PC. Return 0 if none. */
809 struct partial_symtab *
811 register CORE_ADDR pc;
813 register struct partial_symtab *ps;
815 for (ps = partial_symtab_list; ps; ps = ps->next)
816 if (pc >= ps->textlow && pc < ps->texthigh)
822 /* Find which partial symbol within a psymtab contains PC. Return 0
823 if none. Check all psymtabs if PSYMTAB is 0. */
824 struct partial_symbol *
825 find_pc_psymbol (psymtab, pc)
826 struct partial_symtab *psymtab;
829 struct partial_symbol *best, *p;
833 psymtab = find_pc_psymtab (pc);
837 best_pc = psymtab->textlow - 1;
839 for (p = static_psymbols.list + psymtab->statics_offset;
840 (p - (static_psymbols.list + psymtab->statics_offset)
841 < psymtab->n_static_syms);
843 if (SYMBOL_NAMESPACE (p) == VAR_NAMESPACE
844 && SYMBOL_CLASS (p) == LOC_BLOCK
845 && pc >= SYMBOL_VALUE_ADDRESS (p)
846 && SYMBOL_VALUE_ADDRESS (p) > best_pc)
848 best_pc = SYMBOL_VALUE_ADDRESS (p);
851 if (best_pc == psymtab->textlow - 1)
857 /* Find the definition for a specified symbol name NAME
858 in namespace NAMESPACE, visible from lexical block BLOCK.
859 Returns the struct symbol pointer, or zero if no symbol is found.
860 If SYMTAB is non-NULL, store the symbol table in which the
861 symbol was found there, or NULL if not found.
862 C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
863 NAME is a field of the current implied argument `this'. If so set
864 *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
865 BLOCK_FOUND is set to the block in which NAME is found (in the case of
866 a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
869 lookup_symbol (name, block, namespace, is_a_field_of_this, symtab)
871 register struct block *block;
872 enum namespace namespace;
873 int *is_a_field_of_this;
874 struct symtab **symtab;
876 register struct symbol *sym;
877 register struct symtab *s;
878 register struct partial_symtab *ps;
879 struct blockvector *bv;
881 /* Search specified block and its superiors. */
885 sym = lookup_block_symbol (block, name, namespace);
891 /* Search the list of symtabs for one which contains the
892 address of the start of this block. */
894 for (s = symtab_list; s; s = s->next)
896 bv = BLOCKVECTOR (s);
897 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
898 if (BLOCK_START (b) <= BLOCK_START (block)
899 && BLOCK_END (b) > BLOCK_START (block))
907 block = BLOCK_SUPERBLOCK (block);
910 /* But that doesn't do any demangling for the STATIC_BLOCK.
911 I'm not sure whether demangling is needed in the case of
912 nested function in inner blocks; if so this needs to be changed.
914 Don't need to mess with the psymtabs; if we have a block,
915 that file is read in. If we don't, then we deal later with
916 all the psymtab stuff that needs checking. */
917 if (namespace == VAR_NAMESPACE && block != NULL)
920 /* Find the right symtab. */
921 for (s = symtab_list; s; s = s->next)
923 bv = BLOCKVECTOR (s);
924 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
925 if (BLOCK_START (b) <= BLOCK_START (block)
926 && BLOCK_END (b) > BLOCK_START (block))
928 sym = lookup_demangled_block_symbol (b, name);
941 /* C++: If requested to do so by the caller,
942 check to see if NAME is a field of `this'. */
943 if (is_a_field_of_this)
945 struct value *v = value_of_this (0);
947 *is_a_field_of_this = 0;
948 if (v && check_field (v, name))
950 *is_a_field_of_this = 1;
957 /* Now search all global blocks. Do the symtab's first, then
958 check the psymtab's */
960 for (s = symtab_list; s; s = s->next)
962 bv = BLOCKVECTOR (s);
963 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
964 sym = lookup_block_symbol (block, name, namespace);
974 /* Check for the possibility of the symbol being a global function
975 that is stored on the misc function vector. Eventually, all
976 global symbols might be resolved in this way. */
978 if (namespace == VAR_NAMESPACE)
980 int ind = lookup_misc_func (name);
982 /* Look for a mangled C++ name for NAME. */
985 int name_len = strlen (name);
987 for (ind = misc_function_count; --ind >= 0; )
988 /* Assume orginal name is prefix of mangled name. */
989 if (!strncmp (misc_function_vector[ind].name, name, name_len))
992 cplus_demangle(misc_function_vector[ind].name, -1);
993 if (demangled != NULL)
995 int cond = strcmp (demangled, name);
1001 /* Loop terminates on no match with ind == -1. */
1006 s = find_pc_symtab (misc_function_vector[ind].address);
1009 bv = BLOCKVECTOR (s);
1010 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1011 sym = lookup_block_symbol (block, misc_function_vector[ind].name,
1013 /* sym == 0 if symbol was found in the misc_function_vector
1014 but not in the symtab.
1015 Return 0 to use the misc_function definition of "foo_".
1017 This happens for Fortran "foo_" symbols,
1018 which are "foo" in the symtab.
1020 This can also happen if "asm" is used to make a
1021 regular symbol but not a debugging symbol, e.g.
1022 asm(".globl _main");
1033 for (ps = partial_symtab_list; ps; ps = ps->next)
1034 if (!ps->readin && lookup_partial_symbol (ps, name, 1, namespace))
1036 s = PSYMTAB_TO_SYMTAB(ps);
1037 bv = BLOCKVECTOR (s);
1038 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1039 sym = lookup_block_symbol (block, name, namespace);
1041 fatal ("Internal: global symbol found in psymtab but not in symtab");
1047 /* Now search all per-file blocks.
1048 Not strictly correct, but more useful than an error.
1049 Do the symtabs first, then check the psymtabs */
1051 for (s = symtab_list; s; s = s->next)
1053 bv = BLOCKVECTOR (s);
1054 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1055 sym = lookup_block_symbol (block, name, namespace);
1058 block_found = block;
1065 for (ps = partial_symtab_list; ps; ps = ps->next)
1066 if (!ps->readin && lookup_partial_symbol (ps, name, 0, namespace))
1068 s = PSYMTAB_TO_SYMTAB(ps);
1069 bv = BLOCKVECTOR (s);
1070 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1071 sym = lookup_block_symbol (block, name, namespace);
1073 fatal ("Internal: static symbol found in psymtab but not in symtab");
1079 /* Now search all per-file blocks for static mangled symbols.
1080 Do the symtabs first, then check the psymtabs. */
1082 if (namespace == VAR_NAMESPACE)
1084 for (s = symtab_list; s; s = s->next)
1086 bv = BLOCKVECTOR (s);
1087 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1088 sym = lookup_demangled_block_symbol (block, name);
1091 block_found = block;
1098 for (ps = partial_symtab_list; ps; ps = ps->next)
1099 if (!ps->readin && lookup_demangled_partial_symbol (ps, name))
1101 s = PSYMTAB_TO_SYMTAB(ps);
1102 bv = BLOCKVECTOR (s);
1103 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1104 sym = lookup_demangled_block_symbol (block, name);
1106 fatal ("Internal: static symbol found in psymtab but not in symtab");
1118 /* Look for a static demangled symbol in block BLOCK. */
1120 static struct symbol *
1121 lookup_demangled_block_symbol (block, name)
1122 register struct block *block;
1125 register int bot, top, inc;
1126 register struct symbol *sym;
1129 top = BLOCK_NSYMS (block);
1134 sym = BLOCK_SYM (block, bot);
1135 if (SYMBOL_NAME (sym)[0] == inc
1136 && SYMBOL_NAMESPACE (sym) == VAR_NAMESPACE)
1138 char *demangled = cplus_demangle(SYMBOL_NAME (sym), -1);
1139 if (demangled != NULL)
1141 int cond = strcmp (demangled, name);
1153 /* Look, in partial_symtab PST, for static mangled symbol NAME. */
1155 static struct partial_symbol *
1156 lookup_demangled_partial_symbol (pst, name)
1157 struct partial_symtab *pst;
1160 struct partial_symbol *start, *psym;
1161 int length = pst->n_static_syms;
1162 register int inc = name[0];
1165 return (struct partial_symbol *) 0;
1167 start = static_psymbols.list + pst->statics_offset;
1168 for (psym = start; psym < start + length; psym++)
1170 if (SYMBOL_NAME (psym)[0] == inc
1171 && SYMBOL_NAMESPACE (psym) == VAR_NAMESPACE)
1173 char *demangled = cplus_demangle(SYMBOL_NAME (psym), -1);
1174 if (demangled != NULL)
1176 int cond = strcmp (demangled, name);
1184 return (struct partial_symbol *) 0;
1187 /* Look, in partial_symtab PST, for symbol NAME. Check the global
1188 symbols if GLOBAL, the static symbols if not */
1190 static struct partial_symbol *
1191 lookup_partial_symbol (pst, name, global, namespace)
1192 struct partial_symtab *pst;
1195 enum namespace namespace;
1197 struct partial_symbol *start, *psym;
1198 int length = (global ? pst->n_global_syms : pst->n_static_syms);
1201 return (struct partial_symbol *) 0;
1204 global_psymbols.list + pst->globals_offset :
1205 static_psymbols.list + pst->statics_offset );
1207 if (global) /* This means we can use a binary */
1210 struct partial_symbol *top, *bottom, *center;
1212 /* Binary search. This search is guaranteed to end with center
1213 pointing at the earliest partial symbol with the correct
1214 name. At that point *all* partial symbols with that name
1215 will be checked against the correct namespace. */
1217 top = start + length - 1;
1218 while (top > bottom)
1220 center = bottom + (top - bottom) / 2;
1222 assert (center < top);
1224 if (strcmp (SYMBOL_NAME (center), name) >= 0)
1227 bottom = center + 1;
1229 assert (top == bottom);
1231 while (!strcmp (SYMBOL_NAME (top), name))
1233 if (SYMBOL_NAMESPACE (top) == namespace)
1240 /* Can't use a binary search */
1241 for (psym = start; psym < start + length; psym++)
1242 if (namespace == SYMBOL_NAMESPACE (psym)
1243 && !strcmp (name, SYMBOL_NAME (psym)))
1247 return (struct partial_symbol *) 0;
1250 /* Look for a symbol in block BLOCK. */
1253 lookup_block_symbol (block, name, namespace)
1254 register struct block *block;
1256 enum namespace namespace;
1258 register int bot, top, inc;
1259 register struct symbol *sym, *parameter_sym;
1261 top = BLOCK_NSYMS (block);
1264 /* If the blocks's symbols were sorted, start with a binary search. */
1266 if (BLOCK_SHOULD_SORT (block))
1268 /* First, advance BOT to not far before
1269 the first symbol whose name is NAME. */
1273 inc = (top - bot + 1);
1274 /* No need to keep binary searching for the last few bits worth. */
1277 inc = (inc >> 1) + bot;
1278 sym = BLOCK_SYM (block, inc);
1279 if (SYMBOL_NAME (sym)[0] < name[0])
1281 else if (SYMBOL_NAME (sym)[0] > name[0])
1283 else if (strcmp (SYMBOL_NAME (sym), name) < 0)
1289 /* Now scan forward until we run out of symbols,
1290 find one whose name is greater than NAME,
1291 or find one we want.
1292 If there is more than one symbol with the right name and namespace,
1293 we return the first one. dbxread.c is careful to make sure
1294 that if one is a register then it comes first. */
1296 top = BLOCK_NSYMS (block);
1299 sym = BLOCK_SYM (block, bot);
1300 inc = SYMBOL_NAME (sym)[0] - name[0];
1302 inc = strcmp (SYMBOL_NAME (sym), name);
1303 if (inc == 0 && SYMBOL_NAMESPACE (sym) == namespace)
1312 /* Here if block isn't sorted.
1313 This loop is equivalent to the loop above,
1314 but hacked greatly for speed.
1316 Note that parameter symbols do not always show up last in the
1317 list; this loop makes sure to take anything else other than
1318 parameter symbols first; it only uses parameter symbols as a
1319 last resort. Note that this only takes up extra computation
1322 parameter_sym = (struct symbol *) 0;
1323 top = BLOCK_NSYMS (block);
1327 sym = BLOCK_SYM (block, bot);
1328 if (SYMBOL_NAME (sym)[0] == inc
1329 && !strcmp (SYMBOL_NAME (sym), name)
1330 && SYMBOL_NAMESPACE (sym) == namespace)
1332 if (SYMBOL_CLASS (sym) == LOC_ARG
1333 || SYMBOL_CLASS (sym) == LOC_LOCAL_ARG
1334 || SYMBOL_CLASS (sym) == LOC_REF_ARG
1335 || SYMBOL_CLASS (sym) == LOC_REGPARM)
1336 parameter_sym = sym;
1342 return parameter_sym; /* Will be 0 if not found. */
1345 /* Return the symbol for the function which contains a specified
1346 lexical block, described by a struct block BL. */
1352 while (BLOCK_FUNCTION (bl) == 0 && BLOCK_SUPERBLOCK (bl) != 0)
1353 bl = BLOCK_SUPERBLOCK (bl);
1355 return BLOCK_FUNCTION (bl);
1358 /* Subroutine of find_pc_line */
1362 register CORE_ADDR pc;
1364 register struct block *b;
1365 struct blockvector *bv;
1366 register struct symtab *s;
1367 register struct partial_symtab *ps;
1369 /* Search all symtabs for one whose file contains our pc */
1371 for (s = symtab_list; s; s = s->next)
1373 bv = BLOCKVECTOR (s);
1374 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1375 if (BLOCK_START (b) <= pc
1376 && BLOCK_END (b) > pc)
1382 ps = find_pc_psymtab (pc);
1383 if (ps && ps->readin)
1384 fatal ("Internal error: pc in read in psymtab, but not in symtab.");
1387 s = PSYMTAB_TO_SYMTAB (ps);
1393 /* Find the source file and line number for a given PC value.
1394 Return a structure containing a symtab pointer, a line number,
1395 and a pc range for the entire source line.
1396 The value's .pc field is NOT the specified pc.
1397 NOTCURRENT nonzero means, if specified pc is on a line boundary,
1398 use the line that ends there. Otherwise, in that case, the line
1399 that begins there is used. */
1401 struct symtab_and_line
1402 find_pc_line (pc, notcurrent)
1407 register struct linetable *l;
1410 register struct linetable_entry *item;
1411 struct symtab_and_line val;
1412 struct blockvector *bv;
1414 /* Info on best line seen so far, and where it starts, and its file. */
1417 CORE_ADDR best_pc = 0;
1418 CORE_ADDR best_end = 0;
1419 struct symtab *best_symtab = 0;
1421 /* Store here the first line number
1422 of a file which contains the line at the smallest pc after PC.
1423 If we don't find a line whose range contains PC,
1424 we will use a line one less than this,
1425 with a range from the start of that file to the first line's pc. */
1427 CORE_ADDR alt_pc = 0;
1428 struct symtab *alt_symtab = 0;
1430 /* Info on best line seen in this file. */
1435 /* Info on first line of this file. */
1440 /* If this pc is not from the current frame,
1441 it is the address of the end of a call instruction.
1442 Quite likely that is the start of the following statement.
1443 But what we want is the statement containing the instruction.
1444 Fudge the pc to make sure we get that. */
1446 if (notcurrent) pc -= 1;
1448 s = find_pc_symtab (pc);
1458 bv = BLOCKVECTOR (s);
1460 /* Look at all the symtabs that share this blockvector.
1461 They all have the same apriori range, that we found was right;
1462 but they have different line tables. */
1464 for (; s && BLOCKVECTOR (s) == bv; s = s->next)
1466 /* Find the best line in this symtab. */
1471 for (i = 0; i < len; i++)
1473 item = &(l->item[i]);
1477 first_line = item->line;
1478 first_pc = item->pc;
1480 /* Return the last line that did not start after PC. */
1483 prev_line = item->line;
1490 /* Is this file's best line closer than the best in the other files?
1491 If so, record this file, and its best line, as best so far. */
1492 if (prev_line >= 0 && prev_pc > best_pc)
1495 best_line = prev_line;
1498 best_end = item->pc;
1502 /* Is this file's first line closer than the first lines of other files?
1503 If so, record this file, and its first line, as best alternate. */
1504 if (first_line >= 0 && first_pc > pc
1505 && (alt_pc == 0 || first_pc < alt_pc))
1508 alt_line = first_line;
1512 if (best_symtab == 0)
1514 val.symtab = alt_symtab;
1515 val.line = alt_line - 1;
1516 val.pc = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
1521 val.symtab = best_symtab;
1522 val.line = best_line;
1524 val.end = (best_end ? best_end
1526 : BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK))));
1531 /* Find the PC value for a given source file and line number.
1532 Returns zero for invalid line number.
1533 The source file is specified with a struct symtab. */
1536 find_line_pc (symtab, line)
1537 struct symtab *symtab;
1540 register struct linetable *l;
1546 l = LINETABLE (symtab);
1547 ind = find_line_common(l, line, &dummy);
1548 return (ind >= 0) ? l->item[ind].pc : 0;
1551 /* Find the range of pc values in a line.
1552 Store the starting pc of the line into *STARTPTR
1553 and the ending pc (start of next line) into *ENDPTR.
1554 Returns 1 to indicate success.
1555 Returns 0 if could not find the specified line. */
1558 find_line_pc_range (symtab, thisline, startptr, endptr)
1559 struct symtab *symtab;
1561 CORE_ADDR *startptr, *endptr;
1563 register struct linetable *l;
1565 int exact_match; /* did we get an exact linenumber match */
1570 l = LINETABLE (symtab);
1571 ind = find_line_common (l, thisline, &exact_match);
1574 *startptr = l->item[ind].pc;
1575 /* If we have not seen an entry for the specified line,
1576 assume that means the specified line has zero bytes. */
1577 if (!exact_match || ind == l->nitems-1)
1578 *endptr = *startptr;
1580 /* Perhaps the following entry is for the following line.
1581 It's worth a try. */
1582 if (ind+1 < l->nitems
1583 && l->item[ind+1].line == thisline + 1)
1584 *endptr = l->item[ind+1].pc;
1586 *endptr = find_line_pc (symtab, thisline+1);
1593 /* Given a line table and a line number, return the index into the line
1594 table for the pc of the nearest line whose number is >= the specified one.
1595 Return -1 if none is found. The value is >= 0 if it is an index.
1597 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
1600 find_line_common (l, lineno, exact_match)
1601 register struct linetable *l;
1602 register int lineno;
1608 /* BEST is the smallest linenumber > LINENO so far seen,
1609 or 0 if none has been seen so far.
1610 BEST_INDEX identifies the item for it. */
1612 int best_index = -1;
1619 for (i = 0; i < len; i++)
1621 register struct linetable_entry *item = &(l->item[i]);
1623 if (item->line == lineno)
1629 if (item->line > lineno && (best == 0 || item->line < best))
1636 /* If we got here, we didn't get an exact match. */
1643 find_pc_line_pc_range (pc, startptr, endptr)
1645 CORE_ADDR *startptr, *endptr;
1647 struct symtab_and_line sal;
1648 sal = find_pc_line (pc, 0);
1651 return sal.symtab != 0;
1654 /* If P is of the form "operator[ \t]+..." where `...' is
1655 some legitimate operator text, return a pointer to the
1656 beginning of the substring of the operator text.
1657 Otherwise, return "". */
1659 operator_chars (p, end)
1664 if (strncmp (p, "operator", 8))
1668 /* Don't get faked out by `operator' being part of a longer
1670 if ((*p >= 'A' && *p <= 'Z') || (*p >= 'a' && *p <= 'z')
1671 || *p == '_' || *p == '$' || *p == '\0')
1674 /* Allow some whitespace between `operator' and the operator symbol. */
1675 while (*p == ' ' || *p == '\t')
1697 if (p[1] == '=' || p[1] == p[0])
1708 error ("`operator ()' must be specified without whitespace in `()'");
1713 error ("`operator ?:' must be specified without whitespace in `?:'");
1718 error ("`operator []' must be specified without whitespace in `[]'");
1722 error ("`operator %s' not supported", p);
1729 /* Recursive helper function for decode_line_1.
1730 * Look for methods named NAME in type T.
1731 * Return number of matches.
1732 * Put matches in PHYSNAMES and SYM_ARR (which better be big enough!).
1733 * These allocations seem to define "big enough":
1734 * sym_arr = (struct symbol **) alloca(TYPE_NFN_FIELDS_TOTAL (t) * sizeof(struct symbol*));
1735 * physnames = (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t) * sizeof(char*));
1739 find_methods(t, name, physnames, sym_arr)
1743 struct symbol **sym_arr;
1747 struct symbol *sym_class;
1748 char *class_name = type_name_no_tag (t);
1749 /* Ignore this class if it doesn't have a name.
1750 This prevents core dumps, but is just a workaround
1751 because we might not find the function in
1752 certain cases, such as
1753 struct D {virtual int f();}
1754 struct C : D {virtual int g();}
1755 (in this case g++ 1.35.1- does not put out a name
1756 for D as such, it defines type 19 (for example) in
1757 the same stab as C, and then does a
1758 .stabs "D:T19" and a .stabs "D:t19".
1760 "break C::f" should not be looking for field f in
1762 but just for the field f in the baseclasses of C
1763 (no matter what their names).
1765 However, I don't know how to replace the code below
1766 that depends on knowing the name of D. */
1768 && (sym_class = lookup_symbol (class_name,
1769 (struct block *)NULL,
1772 (struct symtab **)NULL)))
1775 t = SYMBOL_TYPE (sym_class);
1776 for (method_counter = TYPE_NFN_FIELDS (t) - 1;
1777 method_counter >= 0;
1781 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, method_counter);
1783 char *method_name = TYPE_FN_FIELDLIST_NAME (t, method_counter);
1784 if (!strcmp (name, method_name))
1785 /* Find all the fields with that name. */
1786 for (field_counter = TYPE_FN_FIELDLIST_LENGTH (t, method_counter) - 1;
1791 if (TYPE_FLAGS (TYPE_FN_FIELD_TYPE (f, field_counter)) & TYPE_FLAG_STUB)
1792 check_stub_method (t, method_counter, field_counter);
1793 phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter);
1794 physnames[i1] = (char*) alloca (strlen (phys_name) + 1);
1795 strcpy (physnames[i1], phys_name);
1796 sym_arr[i1] = lookup_symbol (phys_name,
1797 SYMBOL_BLOCK_VALUE (sym_class),
1800 (struct symtab **) NULL);
1801 if (sym_arr[i1]) i1++;
1805 /* Only search baseclasses if there is no match yet,
1806 * since names in derived classes override those in baseclasses.
1810 for (ibase = 0; ibase < TYPE_N_BASECLASSES (t); ibase++)
1811 i1 += find_methods(TYPE_BASECLASS(t, ibase), name,
1812 physnames + i1, sym_arr + i1);
1816 /* Parse a string that specifies a line number.
1817 Pass the address of a char * variable; that variable will be
1818 advanced over the characters actually parsed.
1822 LINENUM -- that line number in current file. PC returned is 0.
1823 FILE:LINENUM -- that line in that file. PC returned is 0.
1824 FUNCTION -- line number of openbrace of that function.
1825 PC returned is the start of the function.
1826 VARIABLE -- line number of definition of that variable.
1828 FILE:FUNCTION -- likewise, but prefer functions in that file.
1829 *EXPR -- line in which address EXPR appears.
1831 FUNCTION may be an undebuggable function found in misc_function_vector.
1833 If the argument FUNFIRSTLINE is nonzero, we want the first line
1834 of real code inside a function when a function is specified.
1836 DEFAULT_SYMTAB specifies the file to use if none is specified.
1837 It defaults to current_source_symtab.
1838 DEFAULT_LINE specifies the line number to use for relative
1839 line numbers (that start with signs). Defaults to current_source_line.
1841 Note that it is possible to return zero for the symtab
1842 if no file is validly specified. Callers must check that.
1843 Also, the line number returned may be invalid. */
1845 struct symtabs_and_lines
1846 decode_line_1 (argptr, funfirstline, default_symtab, default_line)
1849 struct symtab *default_symtab;
1852 struct symtabs_and_lines decode_line_2 ();
1853 struct symtabs_and_lines values;
1854 struct symtab_and_line val;
1855 register char *p, *p1;
1857 register struct symtab *s;
1859 register struct symbol *sym;
1860 /* The symtab that SYM was found in. */
1861 struct symtab *sym_symtab;
1863 register CORE_ADDR pc;
1866 struct symbol *sym_class;
1868 struct symbol **sym_arr;
1872 /* Defaults have defaults. */
1874 if (default_symtab == 0)
1876 default_symtab = current_source_symtab;
1877 default_line = current_source_line;
1880 /* See if arg is *PC */
1882 if (**argptr == '*')
1885 pc = parse_and_eval_address_1 (argptr);
1886 values.sals = (struct symtab_and_line *)
1887 xmalloc (sizeof (struct symtab_and_line));
1889 values.sals[0] = find_pc_line (pc, 0);
1890 values.sals[0].pc = pc;
1894 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
1898 for (p = *argptr; *p; p++)
1900 if (p[0] == ':' || p[0] == ' ' || p[0] == '\t')
1903 while (p[0] == ' ' || p[0] == '\t') p++;
1905 q = operator_chars (*argptr, &q1);
1912 /* Extract the class name. */
1914 while (p != *argptr && p[-1] == ' ') --p;
1915 copy = (char *) alloca (p - *argptr + 1);
1916 bcopy (*argptr, copy, p - *argptr);
1917 copy[p - *argptr] = 0;
1919 /* Discard the class name from the arg. */
1921 while (*p == ' ' || *p == '\t') p++;
1924 sym_class = lookup_symbol (copy, 0, STRUCT_NAMESPACE, 0,
1925 (struct symtab **)NULL);
1928 (TYPE_CODE (SYMBOL_TYPE (sym_class)) == TYPE_CODE_STRUCT
1929 || TYPE_CODE (SYMBOL_TYPE (sym_class)) == TYPE_CODE_UNION))
1931 /* Arg token is not digits => try it as a function name
1932 Find the next token (everything up to end or next whitespace). */
1934 while (*p && *p != ' ' && *p != '\t' && *p != ',' && *p !=':') p++;
1935 q = operator_chars (*argptr, &q1);
1937 copy = (char *) alloca (p - *argptr + 1 + (q1 - q));
1942 copy[2] = CPLUS_MARKER;
1943 bcopy (q, copy + 3, q1 - q);
1944 copy[3 + (q1 - q)] = '\0';
1949 bcopy (*argptr, copy, p - *argptr);
1950 copy[p - *argptr] = '\0';
1953 /* no line number may be specified */
1954 while (*p == ' ' || *p == '\t') p++;
1958 i1 = 0; /* counter for the symbol array */
1959 t = SYMBOL_TYPE (sym_class);
1960 sym_arr = (struct symbol **) alloca(TYPE_NFN_FIELDS_TOTAL (t) * sizeof(struct symbol*));
1961 physnames = (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t) * sizeof(char*));
1963 if (destructor_name_p (copy, t))
1965 /* destructors are a special case. */
1966 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, 0);
1967 int len = TYPE_FN_FIELDLIST_LENGTH (t, 0) - 1;
1968 char *phys_name = TYPE_FN_FIELD_PHYSNAME (f, len);
1969 physnames[i1] = (char *)alloca (strlen (phys_name) + 1);
1970 strcpy (physnames[i1], phys_name);
1972 lookup_symbol (phys_name, SYMBOL_BLOCK_VALUE (sym_class),
1973 VAR_NAMESPACE, 0, (struct symtab **)NULL);
1974 if (sym_arr[i1]) i1++;
1977 i1 = find_methods (t, copy, physnames, sym_arr);
1980 /* There is exactly one field with that name. */
1983 if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
1985 /* Arg is the name of a function */
1986 pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) + FUNCTION_START_OFFSET;
1989 values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line));
1991 values.sals[0] = find_pc_line (pc, 0);
1992 values.sals[0].pc = (values.sals[0].end && values.sals[0].pc != pc) ? values.sals[0].end : pc;
2002 /* There is more than one field with that name
2003 (overloaded). Ask the user which one to use. */
2004 return decode_line_2 (sym_arr, i1, funfirstline);
2010 if (OPNAME_PREFIX_P (copy))
2012 tmp = (char *)alloca (strlen (copy+3) + 9);
2013 strcpy (tmp, "operator ");
2014 strcat (tmp, copy+3);
2018 error ("that class does not have any method named %s", tmp);
2022 /* The quotes are important if copy is empty. */
2023 error("No class, struct, or union named \"%s\"", copy );
2028 /* Extract the file name. */
2030 while (p != *argptr && p[-1] == ' ') --p;
2031 copy = (char *) alloca (p - *argptr + 1 + (q1 - q));
2036 copy[2] = CPLUS_MARKER;
2037 bcopy (q, copy + 3, q1-q);
2038 copy[3 + (q1-q)] = 0;
2043 bcopy (*argptr, copy, p - *argptr);
2044 copy[p - *argptr] = 0;
2047 /* Find that file's data. */
2048 s = lookup_symtab (copy);
2051 if (symtab_list == 0 && partial_symtab_list == 0)
2052 error (no_symtab_msg);
2053 error ("No source file named %s.", copy);
2056 /* Discard the file name from the arg. */
2058 while (*p == ' ' || *p == '\t') p++;
2062 /* S is specified file's symtab, or 0 if no file specified.
2063 arg no longer contains the file name. */
2065 /* Check whether arg is all digits (and sign) */
2068 if (*p == '-' || *p == '+') p++;
2069 while (*p >= '0' && *p <= '9')
2072 if (p != *argptr && (*p == 0 || *p == ' ' || *p == '\t' || *p == ','))
2074 /* We found a token consisting of all digits -- at least one digit. */
2075 enum sign {none, plus, minus} sign = none;
2077 /* This is where we need to make sure that we have good defaults.
2078 We must guarantee that this section of code is never executed
2079 when we are called with just a function name, since
2080 select_source_symtab calls us with such an argument */
2082 if (s == 0 && default_symtab == 0)
2084 if (symtab_list == 0 && partial_symtab_list == 0)
2085 error (no_symtab_msg);
2086 select_source_symtab (0);
2087 default_symtab = current_source_symtab;
2088 default_line = current_source_line;
2091 if (**argptr == '+')
2092 sign = plus, (*argptr)++;
2093 else if (**argptr == '-')
2094 sign = minus, (*argptr)++;
2095 val.line = atoi (*argptr);
2102 val.line = default_line + val.line;
2108 val.line = default_line - val.line;
2113 break; /* No need to adjust val.line. */
2116 while (*p == ' ' || *p == '\t') p++;
2122 values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line));
2123 values.sals[0] = val;
2128 /* Arg token is not digits => try it as a variable name
2129 Find the next token (everything up to end or next whitespace). */
2131 while (*p && *p != ' ' && *p != '\t' && *p != ',') p++;
2132 copy = (char *) alloca (p - *argptr + 1);
2133 bcopy (*argptr, copy, p - *argptr);
2134 copy[p - *argptr] = 0;
2135 while (*p == ' ' || *p == '\t') p++;
2138 /* Look up that token as a variable.
2139 If file specified, use that file's per-file block to start with. */
2141 sym = lookup_symbol (copy,
2142 (s ? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)
2143 : get_selected_block ()),
2144 VAR_NAMESPACE, 0, &sym_symtab);
2148 if (SYMBOL_CLASS (sym) == LOC_BLOCK)
2150 /* Arg is the name of a function */
2151 pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) + FUNCTION_START_OFFSET;
2154 val = find_pc_line (pc, 0);
2155 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2156 /* Convex: no need to suppress code on first line, if any */
2159 val.pc = (val.end && val.pc != pc) ? val.end : pc;
2161 values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line));
2162 values.sals[0] = val;
2165 /* I think this is always the same as the line that
2166 we calculate above, but the general principle is
2167 "trust the symbols more than stuff like
2169 if (SYMBOL_LINE (sym) != 0)
2170 values.sals[0].line = SYMBOL_LINE (sym);
2174 else if (SYMBOL_LINE (sym) != 0)
2176 /* We know its line number. */
2177 values.sals = (struct symtab_and_line *)
2178 xmalloc (sizeof (struct symtab_and_line));
2180 bzero (&values.sals[0], sizeof (values.sals[0]));
2181 values.sals[0].symtab = sym_symtab;
2182 values.sals[0].line = SYMBOL_LINE (sym);
2186 /* This can happen if it is compiled with a compiler which doesn't
2187 put out line numbers for variables. */
2188 error ("Line number not known for symbol \"%s\"", copy);
2191 if (symtab_list == 0 && partial_symtab_list == 0)
2192 error (no_symtab_msg);
2194 if ((i = lookup_misc_func (copy)) >= 0)
2198 val.pc = misc_function_vector[i].address + FUNCTION_START_OFFSET;
2200 SKIP_PROLOGUE (val.pc);
2201 values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line));
2202 values.sals[0] = val;
2207 error ("Function %s not defined.", copy);
2208 return values; /* for lint */
2211 struct symtabs_and_lines
2212 decode_line_spec (string, funfirstline)
2216 struct symtabs_and_lines sals;
2218 error ("Empty line specification.");
2219 sals = decode_line_1 (&string, funfirstline,
2220 current_source_symtab, current_source_line);
2222 error ("Junk at end of line specification: %s", string);
2226 /* Given a list of NELTS symbols in sym_arr (with corresponding
2227 mangled names in physnames), return a list of lines to operate on
2228 (ask user if necessary). */
2229 struct symtabs_and_lines
2230 decode_line_2 (sym_arr, nelts, funfirstline)
2231 struct symbol *sym_arr[];
2235 struct symtabs_and_lines values, return_values;
2236 register CORE_ADDR pc;
2237 char *args, *arg1, *command_line_input ();
2241 values.sals = (struct symtab_and_line *) alloca (nelts * sizeof(struct symtab_and_line));
2242 return_values.sals = (struct symtab_and_line *) xmalloc (nelts * sizeof(struct symtab_and_line));
2245 printf("[0] cancel\n[1] all\n");
2248 if (sym_arr[i] && SYMBOL_CLASS (sym_arr[i]) == LOC_BLOCK)
2250 /* Arg is the name of a function */
2251 pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym_arr[i]))
2252 + FUNCTION_START_OFFSET;
2255 values.sals[i] = find_pc_line (pc, 0);
2256 values.sals[i].pc = (values.sals[i].end && values.sals[i].pc != pc) ?
2257 values.sals[i].end : pc;
2258 printf("[%d] file:%s; line number:%d\n",
2259 (i+2), values.sals[i].symtab->filename, values.sals[i].line);
2261 else printf ("?HERE\n");
2265 if ((prompt = getenv ("PS2")) == NULL)
2269 printf("%s ",prompt);
2272 args = command_line_input (0, 0);
2275 error_no_arg ("one or more choice numbers");
2283 while (*arg1 >= '0' && *arg1 <= '9') arg1++;
2284 if (*arg1 && *arg1 != ' ' && *arg1 != '\t')
2285 error ("Arguments must be choice numbers.");
2290 error ("cancelled");
2293 bcopy (values.sals, return_values.sals, (nelts * sizeof(struct symtab_and_line)));
2294 return_values.nelts = nelts;
2295 return return_values;
2298 if (num > nelts + 2)
2300 printf ("No choice number %d.\n", num);
2305 if (values.sals[num].pc)
2307 return_values.sals[i++] = values.sals[num];
2308 values.sals[num].pc = 0;
2312 printf ("duplicate request for %d ignored.\n", num);
2317 while (*args == ' ' || *args == '\t') args++;
2319 return_values.nelts = i;
2320 return return_values;
2323 /* Return the index of misc function named NAME. */
2326 lookup_misc_func (name)
2327 register char *name;
2331 for (i = 0; i < misc_function_count; i++)
2332 if (!strcmp (misc_function_vector[i].name, name))
2334 return -1; /* not found */
2337 /* Slave routine for sources_info. Force line breaks at ,'s.
2338 NAME is the name to print and *FIRST is nonzero if this is the first
2339 name printed. Set *FIRST to zero. */
2341 output_source_filename (name, first)
2346 /* Table of files printed so far. Since a single source file can
2347 result in several partial symbol tables, we need to avoid printing
2348 it more than once. Note: if some of the psymtabs are read in and
2349 some are not, it gets printed both under "Source files for which
2350 symbols have been read" and "Source files for which symbols will
2351 be read in on demand". I consider this a reasonable way to deal
2352 with the situation. I'm not sure whether this can also happen for
2353 symtabs; it doesn't hurt to check. */
2354 static char **tab = NULL;
2355 /* Allocated size of tab in elements.
2356 Start with one 256-byte block (when using GNU malloc.c).
2357 24 is the malloc overhead when range checking is in effect. */
2358 static int tab_alloc_size = (256 - 24) / sizeof (char *);
2359 /* Current size of tab in elements. */
2360 static int tab_cur_size;
2367 tab = (char **) xmalloc (tab_alloc_size * sizeof (*tab));
2371 /* Is NAME in tab? */
2372 for (p = tab; p < tab + tab_cur_size; p++)
2373 if (strcmp (*p, name) == 0)
2374 /* Yes; don't print it again. */
2376 /* No; add it to tab. */
2377 if (tab_cur_size == tab_alloc_size)
2379 tab_alloc_size *= 2;
2380 tab = (char **) xrealloc (tab, tab_alloc_size * sizeof (*tab));
2382 tab[tab_cur_size++] = name;
2391 printf_filtered (",");
2395 if (column != 0 && column + strlen (name) >= 70)
2397 printf_filtered ("\n");
2400 else if (column != 0)
2402 printf_filtered (" ");
2405 fputs_filtered (name, stdout);
2406 column += strlen (name);
2412 register struct symtab *s;
2413 register struct partial_symtab *ps;
2416 if (symtab_list == 0 && partial_symtab_list == 0)
2418 printf (no_symtab_msg);
2422 printf_filtered ("Source files for which symbols have been read in:\n\n");
2425 for (s = symtab_list; s; s = s->next)
2426 output_source_filename (s->filename, &first);
2427 printf_filtered ("\n\n");
2429 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2432 for (ps = partial_symtab_list; ps; ps = ps->next)
2434 output_source_filename (ps->filename, &first);
2435 printf_filtered ("\n");
2438 /* List all symbols (if REGEXP is 0) or all symbols matching REGEXP.
2439 If CLASS is zero, list all symbols except functions and type names.
2440 If CLASS is 1, list only functions.
2441 If CLASS is 2, list only type names.
2443 BPT is non-zero if we should set a breakpoint at the functions
2447 list_symbols (regexp, class, bpt)
2452 register struct symtab *s;
2453 register struct partial_symtab *ps;
2454 register struct blockvector *bv;
2455 struct blockvector *prev_bv = 0;
2456 register struct block *b;
2458 register struct symbol *sym;
2459 struct partial_symbol *psym;
2461 static char *classnames[]
2462 = {"variable", "function", "type", "method"};
2463 int found_in_file = 0;
2466 if (0 != (val = re_comp (regexp)))
2467 error ("Invalid regexp (%s): %s", val, regexp);
2469 /* Search through the partial_symtab_list *first* for all symbols
2470 matching the regexp. That way we don't have to reproduce all of
2471 the machinery below. */
2472 for (ps = partial_symtab_list; ps; ps = ps->next)
2474 struct partial_symbol *bound, *gbound, *sbound;
2477 if (ps->readin) continue;
2479 gbound = global_psymbols.list + ps->globals_offset + ps->n_global_syms;
2480 sbound = static_psymbols.list + ps->statics_offset + ps->n_static_syms;
2483 /* Go through all of the symbols stored in a partial
2484 symtab in one loop. */
2485 psym = global_psymbols.list + ps->globals_offset;
2490 if (bound == gbound && ps->n_static_syms != 0)
2492 psym = static_psymbols.list + ps->statics_offset;
2503 /* If it would match (logic taken from loop below)
2504 load the file and go on to the next one */
2505 if ((regexp == 0 || re_exec (SYMBOL_NAME (psym)))
2506 && ((class == 0 && SYMBOL_CLASS (psym) != LOC_TYPEDEF
2507 && SYMBOL_CLASS (psym) != LOC_BLOCK)
2508 || (class == 1 && SYMBOL_CLASS (psym) == LOC_BLOCK)
2509 || (class == 2 && SYMBOL_CLASS (psym) == LOC_TYPEDEF)
2510 || (class == 3 && SYMBOL_CLASS (psym) == LOC_BLOCK)))
2512 (void) PSYMTAB_TO_SYMTAB(ps);
2520 /* Here, *if* the class is correct (function only, right now), we
2521 search through the misc function vector for symbols that
2522 match, and call find_pc_symtab on them to force their symbols to
2523 be read. The symbol will then be found during the scan of symtabs
2528 for (i = 0; i < misc_function_count; i++)
2529 if (regexp == 0 || re_exec (misc_function_vector[i].name))
2531 (void) find_pc_symtab (misc_function_vector[i].address);
2535 /* Printout here so as to get after the "Reading in symbols"
2536 messages which will be generated above. */
2538 printf_filtered (regexp
2539 ? "All %ss matching regular expression \"%s\":\n"
2540 : "All defined %ss:\n",
2544 for (s = symtab_list; s; s = s->next)
2547 bv = BLOCKVECTOR (s);
2548 /* Often many files share a blockvector.
2549 Scan each blockvector only once so that
2550 we don't get every symbol many times.
2551 It happens that the first symtab in the list
2552 for any given blockvector is the main file. */
2554 for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
2556 b = BLOCKVECTOR_BLOCK (bv, i);
2557 /* Skip the sort if this block is always sorted. */
2558 if (!BLOCK_SHOULD_SORT (b))
2559 sort_block_syms (b);
2560 for (j = 0; j < BLOCK_NSYMS (b); j++)
2563 sym = BLOCK_SYM (b, j);
2564 if ((regexp == 0 || re_exec (SYMBOL_NAME (sym)))
2565 && ((class == 0 && SYMBOL_CLASS (sym) != LOC_TYPEDEF
2566 && SYMBOL_CLASS (sym) != LOC_BLOCK)
2567 || (class == 1 && SYMBOL_CLASS (sym) == LOC_BLOCK)
2568 || (class == 2 && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
2569 || (class == 3 && SYMBOL_CLASS (sym) == LOC_BLOCK)))
2573 /* Set a breakpoint here, if it's a function */
2575 break_command (SYMBOL_NAME(sym), 0);
2577 else if (!found_in_file)
2579 fputs_filtered ("\nFile ", stdout);
2580 fputs_filtered (s->filename, stdout);
2581 fputs_filtered (":\n", stdout);
2585 if (class != 2 && i == STATIC_BLOCK)
2586 printf_filtered ("static ");
2588 && SYMBOL_NAMESPACE (sym) != STRUCT_NAMESPACE)
2589 printf_filtered ("typedef ");
2593 type_print (SYMBOL_TYPE (sym),
2594 (SYMBOL_CLASS (sym) == LOC_TYPEDEF
2595 ? "" : SYMBOL_NAME (sym)),
2599 && SYMBOL_NAMESPACE (sym) != STRUCT_NAMESPACE
2600 && (TYPE_NAME ((SYMBOL_TYPE (sym))) == 0
2601 || 0 != strcmp (TYPE_NAME ((SYMBOL_TYPE (sym))),
2602 SYMBOL_NAME (sym))))
2604 fputs_filtered (" ", stdout);
2605 fprint_symbol (stdout, SYMBOL_NAME (sym));
2608 printf_filtered (";\n");
2614 type_print_base (TYPE_FN_FIELD_TYPE(t, i), stdout, 0, 0);
2615 type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t, i), stdout, 0);
2616 sprintf (buf, " %s::", type_name_no_tag (t));
2617 type_print_method_args (TYPE_FN_FIELD_ARGS (t, i), buf, name, stdout);
2628 variables_info (regexp)
2631 list_symbols (regexp, 0, 0);
2635 functions_info (regexp)
2638 list_symbols (regexp, 1, 0);
2645 list_symbols (regexp, 2, 0);
2649 /* Tiemann says: "info methods was never implemented." */
2651 methods_info (regexp)
2654 list_symbols (regexp, 3, 0);
2658 /* Breakpoint all functions matching regular expression. */
2660 rbreak_command (regexp)
2663 list_symbols (regexp, 1, 1);
2666 /* Initialize the standard C scalar types. */
2670 init_type (code, length, uns, name)
2671 enum type_code code;
2675 register struct type *type;
2677 type = (struct type *) xmalloc (sizeof (struct type));
2678 bzero (type, sizeof *type);
2679 TYPE_MAIN_VARIANT (type) = type;
2680 TYPE_CODE (type) = code;
2681 TYPE_LENGTH (type) = length;
2682 TYPE_FLAGS (type) = uns ? TYPE_FLAG_UNSIGNED : 0;
2683 TYPE_FLAGS (type) |= TYPE_FLAG_PERM;
2684 TYPE_NFIELDS (type) = 0;
2685 TYPE_NAME (type) = name;
2688 TYPE_NFN_FIELDS (type) = 0;
2689 TYPE_N_BASECLASSES (type) = 0;
2693 /* Return Nonzero if block a is lexically nested within block b,
2694 or if a and b have the same pc range.
2695 Return zero otherwise. */
2698 struct block *a, *b;
2702 return BLOCK_START (a) >= BLOCK_START (b)
2703 && BLOCK_END (a) <= BLOCK_END (b);
2707 /* Helper routine for make_symbol_completion_list. */
2709 int return_val_size, return_val_index;
2713 completion_list_add_symbol (symname)
2716 if (return_val_index + 3 > return_val_size)
2718 (char **)xrealloc (return_val,
2719 (return_val_size *= 2) * sizeof (char *));
2721 return_val[return_val_index] =
2722 (char *)xmalloc (1 + strlen (symname));
2724 strcpy (return_val[return_val_index], symname);
2726 return_val[++return_val_index] = (char *)NULL;
2729 /* Return a NULL terminated array of all symbols (regardless of class) which
2730 begin by matching TEXT. If the answer is no symbols, then the return value
2731 is an array which contains only a NULL pointer.
2733 Problem: All of the symbols have to be copied because readline
2734 frees them. I'm not going to worry about this; hopefully there
2735 won't be that many. */
2738 make_symbol_completion_list (text)
2741 register struct symtab *s;
2742 register struct partial_symtab *ps;
2743 register struct block *b, *surrounding_static_block = 0;
2744 extern struct block *get_selected_block ();
2746 struct partial_symbol *psym;
2748 int text_len = strlen (text);
2749 return_val_size = 100;
2750 return_val_index = 0;
2752 (char **)xmalloc ((1 + return_val_size) *sizeof (char *));
2753 return_val[0] = (char *)NULL;
2755 /* Look through the partial symtabs for all symbols which begin
2756 by matching TEXT. Add each one that you find to the list. */
2758 for (ps = partial_symtab_list; ps; ps = ps->next)
2760 /* If the psymtab's been read in we'll get it when we search
2761 through the blockvector. */
2762 if (ps->readin) continue;
2764 for (psym = global_psymbols.list + ps->globals_offset;
2765 psym < (global_psymbols.list + ps->globals_offset
2766 + ps->n_global_syms);
2769 QUIT; /* If interrupted, then quit. */
2770 if ((strncmp (SYMBOL_NAME (psym), text, text_len) == 0))
2771 completion_list_add_symbol (SYMBOL_NAME (psym));
2774 for (psym = static_psymbols.list + ps->statics_offset;
2775 psym < (static_psymbols.list + ps->statics_offset
2776 + ps->n_static_syms);
2780 if ((strncmp (SYMBOL_NAME (psym), text, text_len) == 0))
2781 completion_list_add_symbol (SYMBOL_NAME (psym));
2785 /* At this point scan through the misc function vector and add each
2786 symbol you find to the list. Eventually we want to ignore
2787 anything that isn't a text symbol (everything else will be
2788 handled by the psymtab code above). */
2790 for (i = 0; i < misc_function_count; i++)
2791 if (!strncmp (text, misc_function_vector[i].name, text_len))
2792 completion_list_add_symbol (misc_function_vector[i].name);
2794 /* Search upwards from currently selected frame (so that we can
2795 complete on local vars. */
2796 for (b = get_selected_block (); b; b = BLOCK_SUPERBLOCK (b))
2798 if (!BLOCK_SUPERBLOCK (b))
2799 surrounding_static_block = b; /* For elmin of dups */
2801 /* Also catch fields of types defined in this places which
2802 match our text string. Only complete on types visible
2803 from current context. */
2804 for (i = 0; i < BLOCK_NSYMS (b); i++)
2806 register struct symbol *sym = BLOCK_SYM (b, i);
2808 if (!strncmp (SYMBOL_NAME (sym), text, text_len))
2809 completion_list_add_symbol (SYMBOL_NAME (sym));
2811 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF)
2813 struct type *t = SYMBOL_TYPE (sym);
2814 enum type_code c = TYPE_CODE (t);
2816 if (c == TYPE_CODE_UNION || c == TYPE_CODE_STRUCT)
2817 for (j = TYPE_N_BASECLASSES (t); j < TYPE_NFIELDS (t); j++)
2818 if (TYPE_FIELD_NAME (t, j) &&
2819 !strncmp (TYPE_FIELD_NAME (t, j), text, text_len))
2820 completion_list_add_symbol (TYPE_FIELD_NAME (t, j));
2825 /* Go through the symtabs and check the externs and statics for
2826 symbols which match. */
2828 for (s = symtab_list; s; s = s->next)
2830 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
2832 for (i = 0; i < BLOCK_NSYMS (b); i++)
2833 if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b, i)), text, text_len))
2834 completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b, i)));
2837 for (s = symtab_list; s; s = s->next)
2839 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
2841 /* Don't do this block twice. */
2842 if (b == surrounding_static_block) continue;
2844 for (i = 0; i < BLOCK_NSYMS (b); i++)
2845 if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b, i)), text, text_len))
2846 completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b, i)));
2849 return (return_val);
2853 _initialize_symtab ()
2855 add_info ("variables", variables_info,
2856 "All global and static variable names, or those matching REGEXP.");
2857 add_info ("functions", functions_info,
2858 "All function names, or those matching REGEXP.");
2860 /* FIXME: This command has at least the following problems:
2861 1. It prints builtin types (in a very strange and confusing fashion).
2862 2. It doesn't print right, e.g. with
2863 typedef struct foo *FOO
2864 type_print prints "FOO" when we want to make it (in this situation)
2865 print "struct foo *".
2866 I also think "ptype" or "whatis" is more likely to be useful (but if
2867 there is much disagreement "info types" can be fixed). */
2868 add_info ("types", types_info,
2869 "All types names, or those matching REGEXP.");
2872 add_info ("methods", methods_info,
2873 "All method names, or those matching REGEXP::REGEXP.\n\
2874 If the class qualifier is ommited, it is assumed to be the current scope.\n\
2875 If the first REGEXP is ommited, then all methods matching the second REGEXP\n\
2878 add_info ("sources", sources_info,
2879 "Source files in the program.");
2881 add_com ("rbreak", no_class, rbreak_command,
2882 "Set a breakpoint for all functions matching REGEXP.");
2884 /* FIXME: The code below assumes that the sizes of the basic data
2885 types are the same on the host and target machines!!! */
2887 builtin_type_void = init_type (TYPE_CODE_VOID, 1, 0, "void");
2889 builtin_type_float = init_type (TYPE_CODE_FLT, sizeof (float), 0, "float");
2890 builtin_type_double = init_type (TYPE_CODE_FLT, sizeof (double), 0, "double");
2892 builtin_type_char = init_type (TYPE_CODE_INT, sizeof (char), 0, "char");
2893 builtin_type_short = init_type (TYPE_CODE_INT, sizeof (short), 0, "short");
2894 builtin_type_long = init_type (TYPE_CODE_INT, sizeof (long), 0, "long");
2895 builtin_type_int = init_type (TYPE_CODE_INT, sizeof (int), 0, "int");
2897 builtin_type_unsigned_char = init_type (TYPE_CODE_INT, sizeof (char), 1, "unsigned char");
2898 builtin_type_unsigned_short = init_type (TYPE_CODE_INT, sizeof (short), 1, "unsigned short");
2899 builtin_type_unsigned_long = init_type (TYPE_CODE_INT, sizeof (long), 1, "unsigned long");
2900 builtin_type_unsigned_int = init_type (TYPE_CODE_INT, sizeof (int), 1, "unsigned int");
2902 builtin_type_long_long =
2903 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
2905 builtin_type_unsigned_long_long =
2906 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
2907 1, "unsigned long long");
2909 builtin_type_error = init_type (TYPE_CODE_ERROR, 0, 0, "<unknown type>");