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>
42 extern char *getenv ();
44 extern char *cplus_demangle ();
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 /* These variables point to the objects
57 representing the predefined C data types. */
59 struct type
*builtin_type_void
;
60 struct type
*builtin_type_char
;
61 struct type
*builtin_type_short
;
62 struct type
*builtin_type_int
;
63 struct type
*builtin_type_long
;
64 struct type
*builtin_type_long_long
;
65 struct type
*builtin_type_unsigned_char
;
66 struct type
*builtin_type_unsigned_short
;
67 struct type
*builtin_type_unsigned_int
;
68 struct type
*builtin_type_unsigned_long
;
69 struct type
*builtin_type_unsigned_long_long
;
70 struct type
*builtin_type_float
;
71 struct type
*builtin_type_double
;
72 struct type
*builtin_type_error
;
74 /* Block in which the most recently searched-for symbol was found.
75 Might be better to make this a parameter to lookup_symbol and
77 struct block
*block_found
;
79 char no_symtab_msg
[] = "No symbol table is loaded. Use the \"file\" command.";
81 /* Check for a symtab of a specific name; first in symtabs, then in
82 psymtabs. *If* there is no '/' in the name, a match after a '/'
83 in the symtab filename will also work. */
85 static struct symtab
*
86 lookup_symtab_1 (name
)
89 register struct symtab
*s
;
90 register struct partial_symtab
*ps
;
91 register char *slash
= strchr (name
, '/');
92 register int len
= strlen (name
);
94 for (s
= symtab_list
; s
; s
= s
->next
)
95 if (!strcmp (name
, s
->filename
))
98 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
99 if (!strcmp (name
, ps
->filename
))
102 fatal ("Internal: readin pst found when no symtab found.");
103 return PSYMTAB_TO_SYMTAB (ps
);
108 for (s
= symtab_list
; s
; s
= s
->next
)
110 int l
= strlen (s
->filename
);
112 if (s
->filename
[l
- len
-1] == '/'
113 && !strcmp (s
->filename
+ l
- len
, name
))
117 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
119 int l
= strlen (ps
->filename
);
121 if (ps
->filename
[l
- len
- 1] == '/'
122 && !strcmp (ps
->filename
+ l
- len
, name
))
125 fatal ("Internal: readin pst found when no symtab found.");
126 return PSYMTAB_TO_SYMTAB (ps
);
133 /* Lookup the symbol table of a source file named NAME. Try a couple
134 of variations if the first lookup doesn't work. */
140 register struct symtab
*s
;
143 s
= lookup_symtab_1 (name
);
146 /* If name not found as specified, see if adding ".c" helps. */
148 copy
= (char *) alloca (strlen (name
) + 3);
151 s
= lookup_symtab_1 (copy
);
154 /* We didn't find anything; die. */
158 /* Lookup the partial symbol table of a source file named NAME. This
159 only returns true on an exact match (ie. this semantics are
160 different from lookup_symtab. */
162 struct partial_symtab
*
163 lookup_partial_symtab (name
)
166 register struct partial_symtab
*s
;
168 for (s
= partial_symtab_list
; s
; s
= s
->next
)
169 if (!strcmp (name
, s
->filename
))
175 /* Return a typename for a struct/union/enum type
176 without the tag qualifier. If the type has a NULL name,
179 type_name_no_tag (type
)
180 register struct type
*type
;
182 register char *name
= TYPE_NAME (type
);
188 switch (TYPE_CODE (type
))
190 case TYPE_CODE_STRUCT
:
192 case TYPE_CODE_UNION
:
199 name
= strchr (name
, ' ');
203 return TYPE_NAME (type
);
206 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
208 If this is a stubbed struct (i.e. declared as struct foo *), see if
209 we can find a full definition in some other file. If so, copy this
210 definition, so we can use it in future. If not, set a flag so we
211 don't waste too much time in future.
213 This used to be coded as a macro, but I don't think it is called
214 often enough to merit such treatment.
217 struct complaint stub_noname_complaint
=
218 {"stub type has NULL name", 0, 0};
221 check_stub_type(type
)
224 if (TYPE_FLAGS(type
) & TYPE_FLAG_STUB
)
226 char* name
= type_name_no_tag (type
);
230 complain (&stub_noname_complaint
, 0);
233 sym
= lookup_symbol (name
, 0, STRUCT_NAMESPACE
, 0,
234 (struct symtab
**)NULL
);
236 bcopy (SYMBOL_TYPE(sym
), type
, sizeof (struct type
));
240 /* Demangle a GDB method stub type. */
242 gdb_mangle_typename (type
)
245 static struct type
*last_type
;
246 static char *mangled_typename
;
248 if (type
!= last_type
)
250 /* Need a new type prefix. */
252 char *newname
= type_name_no_tag (type
);
256 if (mangled_typename
)
257 free (mangled_typename
);
259 len
= strlen (newname
);
260 sprintf (buf
, "__%d", len
);
261 mangled_typename
= (char *)xmalloc (strlen (buf
) + len
+ 1);
262 strcpy (mangled_typename
, buf
);
263 strcat (mangled_typename
, newname
);
264 /* Now we have built "__#newname". */
266 return mangled_typename
;
269 /* Lookup a primitive type named NAME.
270 Return zero if NAME is not a primitive type.*/
273 lookup_primitive_typename (name
)
276 if (!strcmp (name
, "int"))
277 return builtin_type_int
;
278 if (!strcmp (name
, "long"))
279 return builtin_type_long
;
280 if (!strcmp (name
, "short"))
281 return builtin_type_short
;
282 if (!strcmp (name
, "char"))
283 return builtin_type_char
;
284 if (!strcmp (name
, "float"))
285 return builtin_type_float
;
286 if (!strcmp (name
, "double"))
287 return builtin_type_double
;
288 if (!strcmp (name
, "void"))
289 return builtin_type_void
;
293 /* Lookup a typedef or primitive type named NAME,
294 visible in lexical block BLOCK.
295 If NOERR is nonzero, return zero if NAME is not suitably defined. */
298 lookup_typename (name
, block
, noerr
)
303 register struct symbol
*sym
=
304 lookup_symbol (name
, block
, VAR_NAMESPACE
, 0, (struct symtab
**)NULL
);
305 if (sym
== 0 || SYMBOL_CLASS (sym
) != LOC_TYPEDEF
)
308 tmp
= lookup_primitive_typename (name
);
311 error ("No type named %s.", name
);
313 return SYMBOL_TYPE (sym
);
317 lookup_unsigned_typename (name
)
320 if (!strcmp (name
, "int"))
321 return builtin_type_unsigned_int
;
322 if (!strcmp (name
, "long"))
323 return builtin_type_unsigned_long
;
324 if (!strcmp (name
, "short"))
325 return builtin_type_unsigned_short
;
326 if (!strcmp (name
, "char"))
327 return builtin_type_unsigned_char
;
328 error ("No type named unsigned %s.", name
);
329 return (struct type
*)-1; /* for lint */
332 /* Lookup a structure type named "struct NAME",
333 visible in lexical block BLOCK. */
336 lookup_struct (name
, block
)
340 register struct symbol
*sym
341 = lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0, (struct symtab
**)NULL
);
344 error ("No struct type named %s.", name
);
345 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
346 error ("This context has class, union or enum %s, not a struct.", name
);
347 return SYMBOL_TYPE (sym
);
350 /* Lookup a union type named "union NAME",
351 visible in lexical block BLOCK. */
354 lookup_union (name
, block
)
358 register struct symbol
*sym
359 = lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0, (struct symtab
**)NULL
);
362 error ("No union type named %s.", name
);
363 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_UNION
)
364 error ("This context has class, struct or enum %s, not a union.", name
);
365 return SYMBOL_TYPE (sym
);
368 /* Lookup an enum type named "enum NAME",
369 visible in lexical block BLOCK. */
372 lookup_enum (name
, block
)
376 register struct symbol
*sym
377 = lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0, (struct symtab
**)NULL
);
379 error ("No enum type named %s.", name
);
380 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_ENUM
)
381 error ("This context has class, struct or union %s, not an enum.", name
);
382 return SYMBOL_TYPE (sym
);
385 /* Given a type TYPE, lookup the type of the component of type named
387 If NOERR is nonzero, return zero if NAME is not suitably defined. */
390 lookup_struct_elt_type (type
, name
, noerr
)
397 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
398 && TYPE_CODE (type
) != TYPE_CODE_UNION
)
400 target_terminal_ours ();
402 fprintf (stderr
, "Type ");
403 type_print (type
, "", stderr
, -1);
404 error (" is not a structure or union type.");
407 check_stub_type (type
);
409 for (i
= TYPE_NFIELDS (type
) - 1; i
>= TYPE_N_BASECLASSES (type
); i
--)
411 char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
413 if (t_field_name
&& !strcmp (t_field_name
, name
))
414 return TYPE_FIELD_TYPE (type
, i
);
416 /* OK, it's not in this class. Recursively check the baseclasses. */
417 for (i
= TYPE_N_BASECLASSES (type
) - 1; i
>= 0; i
--)
419 struct type
*t
= lookup_struct_elt_type (TYPE_BASECLASS (type
, i
),
428 target_terminal_ours ();
430 fprintf (stderr
, "Type ");
431 type_print (type
, "", stderr
, -1);
432 fprintf (stderr
, " has no component named ");
433 fputs_filtered (name
, stderr
);
435 return (struct type
*)-1; /* For lint */
438 /* Given a type TYPE, return a type of pointers to that type.
439 May need to construct such a type if this is the first use.
441 C++: use TYPE_MAIN_VARIANT and TYPE_CHAIN to keep pointer
442 to member types under control. */
445 lookup_pointer_type (type
)
448 register struct type
*ptype
= TYPE_POINTER_TYPE (type
);
449 if (ptype
) return TYPE_MAIN_VARIANT (ptype
);
451 /* This is the first time anyone wanted a pointer to a TYPE. */
452 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
453 ptype
= (struct type
*) xmalloc (sizeof (struct type
));
455 ptype
= (struct type
*) obstack_alloc (symbol_obstack
,
456 sizeof (struct type
));
458 bzero (ptype
, sizeof (struct type
));
459 TYPE_MAIN_VARIANT (ptype
) = ptype
;
460 TYPE_TARGET_TYPE (ptype
) = type
;
461 TYPE_POINTER_TYPE (type
) = ptype
;
462 /* New type is permanent if type pointed to is permanent. */
463 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
464 TYPE_FLAGS (ptype
) |= TYPE_FLAG_PERM
;
465 /* We assume the machine has only one representation for pointers! */
466 TYPE_LENGTH (ptype
) = sizeof (char *);
467 TYPE_CODE (ptype
) = TYPE_CODE_PTR
;
472 lookup_reference_type (type
)
475 register struct type
*rtype
= TYPE_REFERENCE_TYPE (type
);
476 if (rtype
) return TYPE_MAIN_VARIANT (rtype
);
478 /* This is the first time anyone wanted a pointer to a TYPE. */
479 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
480 rtype
= (struct type
*) xmalloc (sizeof (struct type
));
482 rtype
= (struct type
*) obstack_alloc (symbol_obstack
,
483 sizeof (struct type
));
485 bzero (rtype
, sizeof (struct type
));
486 TYPE_MAIN_VARIANT (rtype
) = rtype
;
487 TYPE_TARGET_TYPE (rtype
) = type
;
488 TYPE_REFERENCE_TYPE (type
) = rtype
;
489 /* New type is permanent if type pointed to is permanent. */
490 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
491 TYPE_FLAGS (rtype
) |= TYPE_FLAG_PERM
;
492 /* We assume the machine has only one representation for pointers! */
493 TYPE_LENGTH (rtype
) = sizeof (char *);
494 TYPE_CODE (rtype
) = TYPE_CODE_REF
;
499 /* Implement direct support for MEMBER_TYPE in GNU C++.
500 May need to construct such a type if this is the first use.
501 The TYPE is the type of the member. The DOMAIN is the type
502 of the aggregate that the member belongs to. */
505 lookup_member_type (type
, domain
)
506 struct type
*type
, *domain
;
508 register struct type
*mtype
= TYPE_MAIN_VARIANT (type
);
509 struct type
*main_type
;
514 if (TYPE_DOMAIN_TYPE (mtype
) == domain
)
516 mtype
= TYPE_NEXT_VARIANT (mtype
);
519 /* This is the first time anyone wanted this member type. */
520 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
521 mtype
= (struct type
*) xmalloc (sizeof (struct type
));
523 mtype
= (struct type
*) obstack_alloc (symbol_obstack
,
524 sizeof (struct type
));
526 bzero (mtype
, sizeof (struct type
));
531 TYPE_NEXT_VARIANT (mtype
) = TYPE_NEXT_VARIANT (main_type
);
532 TYPE_NEXT_VARIANT (main_type
) = mtype
;
534 TYPE_MAIN_VARIANT (mtype
) = main_type
;
535 TYPE_TARGET_TYPE (mtype
) = type
;
536 TYPE_DOMAIN_TYPE (mtype
) = domain
;
537 /* New type is permanent if type pointed to is permanent. */
538 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
539 TYPE_FLAGS (mtype
) |= TYPE_FLAG_PERM
;
541 /* In practice, this is never used. */
542 TYPE_LENGTH (mtype
) = 1;
543 TYPE_CODE (mtype
) = TYPE_CODE_MEMBER
;
546 /* Now splice in the new member pointer type. */
549 /* This type was not "smashed". */
550 TYPE_CHAIN (mtype
) = TYPE_CHAIN (main_type
);
551 TYPE_CHAIN (main_type
) = mtype
;
558 /* Allocate a stub method whose return type is
559 TYPE. We will fill in arguments later. This always
560 returns a fresh type. If we unify this type with
561 an existing type later, the storage allocated
562 here can be freed. */
564 allocate_stub_method (type
)
567 struct type
*mtype
= (struct type
*)xmalloc (sizeof (struct type
));
568 bzero (mtype
, sizeof (struct type
));
569 TYPE_MAIN_VARIANT (mtype
) = mtype
;
570 TYPE_TARGET_TYPE (mtype
) = type
;
571 TYPE_FLAGS (mtype
) = TYPE_FLAG_STUB
;
572 TYPE_CODE (mtype
) = TYPE_CODE_METHOD
;
573 TYPE_LENGTH (mtype
) = 1;
577 /* Lookup a method type returning type TYPE, belonging
578 to class DOMAIN, and taking a list of arguments ARGS.
579 If one is not found, allocate a new one. */
582 lookup_method_type (type
, domain
, args
)
583 struct type
*type
, *domain
, **args
;
585 register struct type
*mtype
= TYPE_MAIN_VARIANT (type
);
586 struct type
*main_type
;
591 if (TYPE_DOMAIN_TYPE (mtype
) == domain
)
593 struct type
**t1
= args
;
594 struct type
**t2
= TYPE_ARG_TYPES (mtype
);
598 for (i
= 0; t1
[i
] != 0 && t1
[i
]->code
!= TYPE_CODE_VOID
; i
++)
605 mtype
= TYPE_NEXT_VARIANT (mtype
);
608 /* This is the first time anyone wanted this member type. */
609 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
610 mtype
= (struct type
*) xmalloc (sizeof (struct type
));
612 mtype
= (struct type
*) obstack_alloc (symbol_obstack
,
613 sizeof (struct type
));
615 bzero (mtype
, sizeof (struct type
));
620 TYPE_NEXT_VARIANT (mtype
) = TYPE_NEXT_VARIANT (main_type
);
621 TYPE_NEXT_VARIANT (main_type
) = mtype
;
623 TYPE_MAIN_VARIANT (mtype
) = main_type
;
624 TYPE_TARGET_TYPE (mtype
) = type
;
625 TYPE_DOMAIN_TYPE (mtype
) = domain
;
626 TYPE_ARG_TYPES (mtype
) = args
;
627 /* New type is permanent if type pointed to is permanent. */
628 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
629 TYPE_FLAGS (mtype
) |= TYPE_FLAG_PERM
;
631 /* In practice, this is never used. */
632 TYPE_LENGTH (mtype
) = 1;
633 TYPE_CODE (mtype
) = TYPE_CODE_METHOD
;
636 /* Now splice in the new member pointer type. */
639 /* This type was not "smashed". */
640 TYPE_CHAIN (mtype
) = TYPE_CHAIN (main_type
);
641 TYPE_CHAIN (main_type
) = mtype
;
649 /* Given a type TYPE, return a type which has offset OFFSET,
650 via_virtual VIA_VIRTUAL, and via_public VIA_PUBLIC.
651 May need to construct such a type if none exists. */
653 lookup_basetype_type (type
, offset
, via_virtual
, via_public
)
656 int via_virtual
, via_public
;
658 register struct type
*btype
= TYPE_MAIN_VARIANT (type
);
659 struct type
*main_type
;
663 printf ("Internal error: type offset non-zero in lookup_basetype_type");
670 if (/* TYPE_OFFSET (btype) == offset
671 && */ TYPE_VIA_PUBLIC (btype
) == via_public
672 && TYPE_VIA_VIRTUAL (btype
) == via_virtual
)
674 btype
= TYPE_NEXT_VARIANT (btype
);
677 /* This is the first time anyone wanted this member type. */
678 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
679 btype
= (struct type
*) xmalloc (sizeof (struct type
));
681 btype
= (struct type
*) obstack_alloc (symbol_obstack
,
682 sizeof (struct type
));
687 bzero (btype
, sizeof (struct type
));
688 TYPE_MAIN_VARIANT (btype
) = main_type
;
692 bcopy (main_type
, btype
, sizeof (struct type
));
693 TYPE_NEXT_VARIANT (main_type
) = btype
;
695 /* TYPE_OFFSET (btype) = offset; */
697 TYPE_FLAGS (btype
) |= TYPE_FLAG_VIA_PUBLIC
;
699 TYPE_FLAGS (btype
) |= TYPE_FLAG_VIA_VIRTUAL
;
700 /* New type is permanent if type pointed to is permanent. */
701 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
702 TYPE_FLAGS (btype
) |= TYPE_FLAG_PERM
;
704 /* In practice, this is never used. */
705 TYPE_LENGTH (btype
) = 1;
706 TYPE_CODE (btype
) = TYPE_CODE_STRUCT
;
712 /* Given a type TYPE, return a type of functions that return that type.
713 May need to construct such a type if this is the first use. */
716 lookup_function_type (type
)
719 register struct type
*ptype
= TYPE_FUNCTION_TYPE (type
);
720 if (ptype
) return ptype
;
722 /* This is the first time anyone wanted a function returning a TYPE. */
723 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
724 ptype
= (struct type
*) xmalloc (sizeof (struct type
));
726 ptype
= (struct type
*) obstack_alloc (symbol_obstack
,
727 sizeof (struct type
));
729 bzero (ptype
, sizeof (struct type
));
730 TYPE_TARGET_TYPE (ptype
) = type
;
731 TYPE_FUNCTION_TYPE (type
) = ptype
;
732 /* New type is permanent if type returned is permanent. */
733 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
734 TYPE_FLAGS (ptype
) |= TYPE_FLAG_PERM
;
735 TYPE_LENGTH (ptype
) = 1;
736 TYPE_CODE (ptype
) = TYPE_CODE_FUNC
;
737 TYPE_NFIELDS (ptype
) = 0;
741 /* Create an array type. Elements will be of type TYPE, and there will
744 Eventually this should be extended to take two more arguments which
745 specify the bounds of the array and the type of the index.
746 It should also be changed to be a "lookup" function, with the
747 appropriate data structures added to the type field.
748 Then read array type should call here. */
751 create_array_type (element_type
, number
)
752 struct type
*element_type
;
755 struct type
*result_type
= (struct type
*)
756 obstack_alloc (symbol_obstack
, sizeof (struct type
));
758 bzero (result_type
, sizeof (struct type
));
760 TYPE_CODE (result_type
) = TYPE_CODE_ARRAY
;
761 TYPE_TARGET_TYPE (result_type
) = element_type
;
762 TYPE_LENGTH (result_type
) = number
* TYPE_LENGTH (element_type
);
763 TYPE_NFIELDS (result_type
) = 1;
764 TYPE_FIELDS (result_type
) =
765 (struct field
*) obstack_alloc (symbol_obstack
, sizeof (struct field
));
766 TYPE_FIELD_TYPE (result_type
, 0) = builtin_type_int
;
767 TYPE_VPTR_FIELDNO (result_type
) = -1;
773 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE. */
776 smash_to_member_type (type
, domain
, to_type
)
777 struct type
*type
, *domain
, *to_type
;
779 bzero (type
, sizeof (struct type
));
780 TYPE_TARGET_TYPE (type
) = to_type
;
781 TYPE_DOMAIN_TYPE (type
) = domain
;
783 /* In practice, this is never needed. */
784 TYPE_LENGTH (type
) = 1;
785 TYPE_CODE (type
) = TYPE_CODE_MEMBER
;
787 TYPE_MAIN_VARIANT (type
) = lookup_member_type (domain
, to_type
);
790 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE. */
793 smash_to_method_type (type
, domain
, to_type
, args
)
794 struct type
*type
, *domain
, *to_type
, **args
;
796 bzero (type
, sizeof (struct type
));
797 TYPE_TARGET_TYPE (type
) = to_type
;
798 TYPE_DOMAIN_TYPE (type
) = domain
;
799 TYPE_ARG_TYPES (type
) = args
;
801 /* In practice, this is never needed. */
802 TYPE_LENGTH (type
) = 1;
803 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
805 TYPE_MAIN_VARIANT (type
) = lookup_method_type (domain
, to_type
, args
);
808 /* Find which partial symtab on the partial_symtab_list contains
809 PC. Return 0 if none. */
811 struct partial_symtab
*
813 register CORE_ADDR pc
;
815 register struct partial_symtab
*ps
;
817 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
818 if (pc
>= ps
->textlow
&& pc
< ps
->texthigh
)
824 /* Find which partial symbol within a psymtab contains PC. Return 0
825 if none. Check all psymtabs if PSYMTAB is 0. */
826 struct partial_symbol
*
827 find_pc_psymbol (psymtab
, pc
)
828 struct partial_symtab
*psymtab
;
831 struct partial_symbol
*best
, *p
;
835 psymtab
= find_pc_psymtab (pc
);
839 best_pc
= psymtab
->textlow
- 1;
841 for (p
= static_psymbols
.list
+ psymtab
->statics_offset
;
842 (p
- (static_psymbols
.list
+ psymtab
->statics_offset
)
843 < psymtab
->n_static_syms
);
845 if (SYMBOL_NAMESPACE (p
) == VAR_NAMESPACE
846 && SYMBOL_CLASS (p
) == LOC_BLOCK
847 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
848 && SYMBOL_VALUE_ADDRESS (p
) > best_pc
)
850 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
853 if (best_pc
== psymtab
->textlow
- 1)
859 /* Find the definition for a specified symbol name NAME
860 in namespace NAMESPACE, visible from lexical block BLOCK.
861 Returns the struct symbol pointer, or zero if no symbol is found.
862 If SYMTAB is non-NULL, store the symbol table in which the
863 symbol was found there, or NULL if not found.
864 C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
865 NAME is a field of the current implied argument `this'. If so set
866 *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
867 BLOCK_FOUND is set to the block in which NAME is found (in the case of
868 a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
871 lookup_symbol (name
, block
, namespace, is_a_field_of_this
, symtab
)
873 register struct block
*block
;
874 enum namespace namespace;
875 int *is_a_field_of_this
;
876 struct symtab
**symtab
;
878 register struct symbol
*sym
;
879 register struct symtab
*s
;
880 register struct partial_symtab
*ps
;
881 struct blockvector
*bv
;
883 /* Search specified block and its superiors. */
887 sym
= lookup_block_symbol (block
, name
, namespace);
893 /* Search the list of symtabs for one which contains the
894 address of the start of this block. */
896 for (s
= symtab_list
; s
; s
= s
->next
)
898 bv
= BLOCKVECTOR (s
);
899 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
900 if (BLOCK_START (b
) <= BLOCK_START (block
)
901 && BLOCK_END (b
) > BLOCK_START (block
))
909 block
= BLOCK_SUPERBLOCK (block
);
912 /* But that doesn't do any demangling for the STATIC_BLOCK.
913 I'm not sure whether demangling is needed in the case of
914 nested function in inner blocks; if so this needs to be changed.
916 Don't need to mess with the psymtabs; if we have a block,
917 that file is read in. If we don't, then we deal later with
918 all the psymtab stuff that needs checking. */
919 if (namespace == VAR_NAMESPACE
&& block
!= NULL
)
922 /* Find the right symtab. */
923 for (s
= symtab_list
; s
; s
= s
->next
)
925 bv
= BLOCKVECTOR (s
);
926 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
927 if (BLOCK_START (b
) <= BLOCK_START (block
)
928 && BLOCK_END (b
) > BLOCK_START (block
))
930 sym
= lookup_demangled_block_symbol (b
, name
);
943 /* C++: If requested to do so by the caller,
944 check to see if NAME is a field of `this'. */
945 if (is_a_field_of_this
)
947 struct value
*v
= value_of_this (0);
949 *is_a_field_of_this
= 0;
950 if (v
&& check_field (v
, name
))
952 *is_a_field_of_this
= 1;
959 /* Now search all global blocks. Do the symtab's first, then
960 check the psymtab's */
962 for (s
= symtab_list
; s
; s
= s
->next
)
964 bv
= BLOCKVECTOR (s
);
965 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
966 sym
= lookup_block_symbol (block
, name
, namespace);
976 /* Check for the possibility of the symbol being a global function
977 that is stored on the misc function vector. Eventually, all
978 global symbols might be resolved in this way. */
980 if (namespace == VAR_NAMESPACE
)
982 int ind
= lookup_misc_func (name
);
984 /* Look for a mangled C++ name for NAME. */
987 int name_len
= strlen (name
);
989 for (ind
= misc_function_count
; --ind
>= 0; )
990 /* Assume orginal name is prefix of mangled name. */
991 if (!strncmp (misc_function_vector
[ind
].name
, name
, name_len
))
994 cplus_demangle(misc_function_vector
[ind
].name
, -1);
995 if (demangled
!= NULL
)
997 int cond
= strcmp (demangled
, name
);
1003 /* Loop terminates on no match with ind == -1. */
1008 s
= find_pc_symtab (misc_function_vector
[ind
].address
);
1011 bv
= BLOCKVECTOR (s
);
1012 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1013 sym
= lookup_block_symbol (block
, misc_function_vector
[ind
].name
,
1015 /* sym == 0 if symbol was found in the misc_function_vector
1016 but not in the symtab.
1017 Return 0 to use the misc_function definition of "foo_".
1019 This happens for Fortran "foo_" symbols,
1020 which are "foo" in the symtab.
1022 This can also happen if "asm" is used to make a
1023 regular symbol but not a debugging symbol, e.g.
1024 asm(".globl _main");
1035 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
1036 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 1, namespace))
1038 s
= PSYMTAB_TO_SYMTAB(ps
);
1039 bv
= BLOCKVECTOR (s
);
1040 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1041 sym
= lookup_block_symbol (block
, name
, namespace);
1043 fatal ("Internal: global symbol found in psymtab but not in symtab");
1049 /* Now search all per-file blocks.
1050 Not strictly correct, but more useful than an error.
1051 Do the symtabs first, then check the psymtabs */
1053 for (s
= symtab_list
; s
; s
= s
->next
)
1055 bv
= BLOCKVECTOR (s
);
1056 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1057 sym
= lookup_block_symbol (block
, name
, namespace);
1060 block_found
= block
;
1067 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
1068 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 0, namespace))
1070 s
= PSYMTAB_TO_SYMTAB(ps
);
1071 bv
= BLOCKVECTOR (s
);
1072 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1073 sym
= lookup_block_symbol (block
, name
, namespace);
1075 fatal ("Internal: static symbol found in psymtab but not in symtab");
1081 /* Now search all per-file blocks for static mangled symbols.
1082 Do the symtabs first, then check the psymtabs. */
1084 if (namespace == VAR_NAMESPACE
)
1086 for (s
= symtab_list
; s
; s
= s
->next
)
1088 bv
= BLOCKVECTOR (s
);
1089 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1090 sym
= lookup_demangled_block_symbol (block
, name
);
1093 block_found
= block
;
1100 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
1101 if (!ps
->readin
&& lookup_demangled_partial_symbol (ps
, name
))
1103 s
= PSYMTAB_TO_SYMTAB(ps
);
1104 bv
= BLOCKVECTOR (s
);
1105 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1106 sym
= lookup_demangled_block_symbol (block
, name
);
1108 fatal ("Internal: static symbol found in psymtab but not in symtab");
1120 /* Look for a static demangled symbol in block BLOCK. */
1122 static struct symbol
*
1123 lookup_demangled_block_symbol (block
, name
)
1124 register struct block
*block
;
1127 register int bot
, top
, inc
;
1128 register struct symbol
*sym
;
1131 top
= BLOCK_NSYMS (block
);
1136 sym
= BLOCK_SYM (block
, bot
);
1137 if (SYMBOL_NAME (sym
)[0] == inc
1138 && SYMBOL_NAMESPACE (sym
) == VAR_NAMESPACE
)
1140 char *demangled
= cplus_demangle(SYMBOL_NAME (sym
), -1);
1141 if (demangled
!= NULL
)
1143 int cond
= strcmp (demangled
, name
);
1155 /* Look, in partial_symtab PST, for static mangled symbol NAME. */
1157 static struct partial_symbol
*
1158 lookup_demangled_partial_symbol (pst
, name
)
1159 struct partial_symtab
*pst
;
1162 struct partial_symbol
*start
, *psym
;
1163 int length
= pst
->n_static_syms
;
1164 register int inc
= name
[0];
1167 return (struct partial_symbol
*) 0;
1169 start
= static_psymbols
.list
+ pst
->statics_offset
;
1170 for (psym
= start
; psym
< start
+ length
; psym
++)
1172 if (SYMBOL_NAME (psym
)[0] == inc
1173 && SYMBOL_NAMESPACE (psym
) == VAR_NAMESPACE
)
1175 char *demangled
= cplus_demangle(SYMBOL_NAME (psym
), -1);
1176 if (demangled
!= NULL
)
1178 int cond
= strcmp (demangled
, name
);
1186 return (struct partial_symbol
*) 0;
1189 /* Look, in partial_symtab PST, for symbol NAME. Check the global
1190 symbols if GLOBAL, the static symbols if not */
1192 static struct partial_symbol
*
1193 lookup_partial_symbol (pst
, name
, global
, namespace)
1194 struct partial_symtab
*pst
;
1197 enum namespace namespace;
1199 struct partial_symbol
*start
, *psym
;
1200 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
1203 return (struct partial_symbol
*) 0;
1206 global_psymbols
.list
+ pst
->globals_offset
:
1207 static_psymbols
.list
+ pst
->statics_offset
);
1209 if (global
) /* This means we can use a binary */
1212 struct partial_symbol
*top
, *bottom
, *center
;
1214 /* Binary search. This search is guaranteed to end with center
1215 pointing at the earliest partial symbol with the correct
1216 name. At that point *all* partial symbols with that name
1217 will be checked against the correct namespace. */
1219 top
= start
+ length
- 1;
1220 while (top
> bottom
)
1222 center
= bottom
+ (top
- bottom
) / 2;
1224 assert (center
< top
);
1226 if (strcmp (SYMBOL_NAME (center
), name
) >= 0)
1229 bottom
= center
+ 1;
1231 assert (top
== bottom
);
1233 while (!strcmp (SYMBOL_NAME (top
), name
))
1235 if (SYMBOL_NAMESPACE (top
) == namespace)
1242 /* Can't use a binary search */
1243 for (psym
= start
; psym
< start
+ length
; psym
++)
1244 if (namespace == SYMBOL_NAMESPACE (psym
)
1245 && !strcmp (name
, SYMBOL_NAME (psym
)))
1249 return (struct partial_symbol
*) 0;
1252 /* Look for a symbol in block BLOCK. */
1255 lookup_block_symbol (block
, name
, namespace)
1256 register struct block
*block
;
1258 enum namespace namespace;
1260 register int bot
, top
, inc
;
1261 register struct symbol
*sym
, *parameter_sym
;
1263 top
= BLOCK_NSYMS (block
);
1266 /* If the blocks's symbols were sorted, start with a binary search. */
1268 if (BLOCK_SHOULD_SORT (block
))
1270 /* First, advance BOT to not far before
1271 the first symbol whose name is NAME. */
1275 inc
= (top
- bot
+ 1);
1276 /* No need to keep binary searching for the last few bits worth. */
1279 inc
= (inc
>> 1) + bot
;
1280 sym
= BLOCK_SYM (block
, inc
);
1281 if (SYMBOL_NAME (sym
)[0] < name
[0])
1283 else if (SYMBOL_NAME (sym
)[0] > name
[0])
1285 else if (strcmp (SYMBOL_NAME (sym
), name
) < 0)
1291 /* Now scan forward until we run out of symbols,
1292 find one whose name is greater than NAME,
1293 or find one we want.
1294 If there is more than one symbol with the right name and namespace,
1295 we return the first one. dbxread.c is careful to make sure
1296 that if one is a register then it comes first. */
1298 top
= BLOCK_NSYMS (block
);
1301 sym
= BLOCK_SYM (block
, bot
);
1302 inc
= SYMBOL_NAME (sym
)[0] - name
[0];
1304 inc
= strcmp (SYMBOL_NAME (sym
), name
);
1305 if (inc
== 0 && SYMBOL_NAMESPACE (sym
) == namespace)
1314 /* Here if block isn't sorted.
1315 This loop is equivalent to the loop above,
1316 but hacked greatly for speed.
1318 Note that parameter symbols do not always show up last in the
1319 list; this loop makes sure to take anything else other than
1320 parameter symbols first; it only uses parameter symbols as a
1321 last resort. Note that this only takes up extra computation
1324 parameter_sym
= (struct symbol
*) 0;
1325 top
= BLOCK_NSYMS (block
);
1329 sym
= BLOCK_SYM (block
, bot
);
1330 if (SYMBOL_NAME (sym
)[0] == inc
1331 && !strcmp (SYMBOL_NAME (sym
), name
)
1332 && SYMBOL_NAMESPACE (sym
) == namespace)
1334 if (SYMBOL_CLASS (sym
) == LOC_ARG
1335 || SYMBOL_CLASS (sym
) == LOC_LOCAL_ARG
1336 || SYMBOL_CLASS (sym
) == LOC_REF_ARG
1337 || SYMBOL_CLASS (sym
) == LOC_REGPARM
)
1338 parameter_sym
= sym
;
1344 return parameter_sym
; /* Will be 0 if not found. */
1347 /* Return the symbol for the function which contains a specified
1348 lexical block, described by a struct block BL. */
1354 while (BLOCK_FUNCTION (bl
) == 0 && BLOCK_SUPERBLOCK (bl
) != 0)
1355 bl
= BLOCK_SUPERBLOCK (bl
);
1357 return BLOCK_FUNCTION (bl
);
1360 /* Subroutine of find_pc_line */
1364 register CORE_ADDR pc
;
1366 register struct block
*b
;
1367 struct blockvector
*bv
;
1368 register struct symtab
*s
;
1369 register struct partial_symtab
*ps
;
1371 /* Search all symtabs for one whose file contains our pc */
1373 for (s
= symtab_list
; s
; s
= s
->next
)
1375 bv
= BLOCKVECTOR (s
);
1376 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1377 if (BLOCK_START (b
) <= pc
1378 && BLOCK_END (b
) > pc
)
1384 ps
= find_pc_psymtab (pc
);
1385 if (ps
&& ps
->readin
)
1386 fatal ("Internal error: pc in read in psymtab, but not in symtab.");
1389 s
= PSYMTAB_TO_SYMTAB (ps
);
1395 /* Find the source file and line number for a given PC value.
1396 Return a structure containing a symtab pointer, a line number,
1397 and a pc range for the entire source line.
1398 The value's .pc field is NOT the specified pc.
1399 NOTCURRENT nonzero means, if specified pc is on a line boundary,
1400 use the line that ends there. Otherwise, in that case, the line
1401 that begins there is used. */
1403 struct symtab_and_line
1404 find_pc_line (pc
, notcurrent
)
1409 register struct linetable
*l
;
1412 register struct linetable_entry
*item
;
1413 struct symtab_and_line val
;
1414 struct blockvector
*bv
;
1416 /* Info on best line seen so far, and where it starts, and its file. */
1419 CORE_ADDR best_pc
= 0;
1420 CORE_ADDR best_end
= 0;
1421 struct symtab
*best_symtab
= 0;
1423 /* Store here the first line number
1424 of a file which contains the line at the smallest pc after PC.
1425 If we don't find a line whose range contains PC,
1426 we will use a line one less than this,
1427 with a range from the start of that file to the first line's pc. */
1429 CORE_ADDR alt_pc
= 0;
1430 struct symtab
*alt_symtab
= 0;
1432 /* Info on best line seen in this file. */
1437 /* Info on first line of this file. */
1442 /* If this pc is not from the current frame,
1443 it is the address of the end of a call instruction.
1444 Quite likely that is the start of the following statement.
1445 But what we want is the statement containing the instruction.
1446 Fudge the pc to make sure we get that. */
1448 if (notcurrent
) pc
-= 1;
1450 s
= find_pc_symtab (pc
);
1460 bv
= BLOCKVECTOR (s
);
1462 /* Look at all the symtabs that share this blockvector.
1463 They all have the same apriori range, that we found was right;
1464 but they have different line tables. */
1466 for (; s
&& BLOCKVECTOR (s
) == bv
; s
= s
->next
)
1468 /* Find the best line in this symtab. */
1473 for (i
= 0; i
< len
; i
++)
1475 item
= &(l
->item
[i
]);
1479 first_line
= item
->line
;
1480 first_pc
= item
->pc
;
1482 /* Return the last line that did not start after PC. */
1485 prev_line
= item
->line
;
1492 /* Is this file's best line closer than the best in the other files?
1493 If so, record this file, and its best line, as best so far. */
1494 if (prev_line
>= 0 && prev_pc
> best_pc
)
1497 best_line
= prev_line
;
1500 best_end
= item
->pc
;
1504 /* Is this file's first line closer than the first lines of other files?
1505 If so, record this file, and its first line, as best alternate. */
1506 if (first_line
>= 0 && first_pc
> pc
1507 && (alt_pc
== 0 || first_pc
< alt_pc
))
1510 alt_line
= first_line
;
1514 if (best_symtab
== 0)
1516 val
.symtab
= alt_symtab
;
1517 val
.line
= alt_line
- 1;
1518 val
.pc
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
1523 val
.symtab
= best_symtab
;
1524 val
.line
= best_line
;
1526 val
.end
= (best_end
? best_end
1528 : BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
))));
1533 /* Find the PC value for a given source file and line number.
1534 Returns zero for invalid line number.
1535 The source file is specified with a struct symtab. */
1538 find_line_pc (symtab
, line
)
1539 struct symtab
*symtab
;
1542 register struct linetable
*l
;
1548 l
= LINETABLE (symtab
);
1549 ind
= find_line_common(l
, line
, &dummy
);
1550 return (ind
>= 0) ? l
->item
[ind
].pc
: 0;
1553 /* Find the range of pc values in a line.
1554 Store the starting pc of the line into *STARTPTR
1555 and the ending pc (start of next line) into *ENDPTR.
1556 Returns 1 to indicate success.
1557 Returns 0 if could not find the specified line. */
1560 find_line_pc_range (symtab
, thisline
, startptr
, endptr
)
1561 struct symtab
*symtab
;
1563 CORE_ADDR
*startptr
, *endptr
;
1565 register struct linetable
*l
;
1567 int exact_match
; /* did we get an exact linenumber match */
1572 l
= LINETABLE (symtab
);
1573 ind
= find_line_common (l
, thisline
, &exact_match
);
1576 *startptr
= l
->item
[ind
].pc
;
1577 /* If we have not seen an entry for the specified line,
1578 assume that means the specified line has zero bytes. */
1579 if (!exact_match
|| ind
== l
->nitems
-1)
1580 *endptr
= *startptr
;
1582 /* Perhaps the following entry is for the following line.
1583 It's worth a try. */
1584 if (ind
+1 < l
->nitems
1585 && l
->item
[ind
+1].line
== thisline
+ 1)
1586 *endptr
= l
->item
[ind
+1].pc
;
1588 *endptr
= find_line_pc (symtab
, thisline
+1);
1595 /* Given a line table and a line number, return the index into the line
1596 table for the pc of the nearest line whose number is >= the specified one.
1597 Return -1 if none is found. The value is >= 0 if it is an index.
1599 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
1602 find_line_common (l
, lineno
, exact_match
)
1603 register struct linetable
*l
;
1604 register int lineno
;
1610 /* BEST is the smallest linenumber > LINENO so far seen,
1611 or 0 if none has been seen so far.
1612 BEST_INDEX identifies the item for it. */
1614 int best_index
= -1;
1621 for (i
= 0; i
< len
; i
++)
1623 register struct linetable_entry
*item
= &(l
->item
[i
]);
1625 if (item
->line
== lineno
)
1631 if (item
->line
> lineno
&& (best
== 0 || item
->line
< best
))
1638 /* If we got here, we didn't get an exact match. */
1645 find_pc_line_pc_range (pc
, startptr
, endptr
)
1647 CORE_ADDR
*startptr
, *endptr
;
1649 struct symtab_and_line sal
;
1650 sal
= find_pc_line (pc
, 0);
1653 return sal
.symtab
!= 0;
1656 /* If P is of the form "operator[ \t]+..." where `...' is
1657 some legitimate operator text, return a pointer to the
1658 beginning of the substring of the operator text.
1659 Otherwise, return "". */
1661 operator_chars (p
, end
)
1666 if (strncmp (p
, "operator", 8))
1670 /* Don't get faked out by `operator' being part of a longer
1672 if ((*p
>= 'A' && *p
<= 'Z') || (*p
>= 'a' && *p
<= 'z')
1673 || *p
== '_' || *p
== '$' || *p
== '\0')
1676 /* Allow some whitespace between `operator' and the operator symbol. */
1677 while (*p
== ' ' || *p
== '\t')
1699 if (p
[1] == '=' || p
[1] == p
[0])
1710 error ("`operator ()' must be specified without whitespace in `()'");
1715 error ("`operator ?:' must be specified without whitespace in `?:'");
1720 error ("`operator []' must be specified without whitespace in `[]'");
1724 error ("`operator %s' not supported", p
);
1731 /* Recursive helper function for decode_line_1.
1732 * Look for methods named NAME in type T.
1733 * Return number of matches.
1734 * Put matches in PHYSNAMES and SYM_ARR (which better be big enough!).
1735 * These allocations seem to define "big enough":
1736 * sym_arr = (struct symbol **) alloca(TYPE_NFN_FIELDS_TOTAL (t) * sizeof(struct symbol*));
1737 * physnames = (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t) * sizeof(char*));
1741 find_methods(t
, name
, physnames
, sym_arr
)
1745 struct symbol
**sym_arr
;
1749 struct symbol
*sym_class
;
1750 char *class_name
= type_name_no_tag (t
);
1751 /* Ignore this class if it doesn't have a name.
1752 This prevents core dumps, but is just a workaround
1753 because we might not find the function in
1754 certain cases, such as
1755 struct D {virtual int f();}
1756 struct C : D {virtual int g();}
1757 (in this case g++ 1.35.1- does not put out a name
1758 for D as such, it defines type 19 (for example) in
1759 the same stab as C, and then does a
1760 .stabs "D:T19" and a .stabs "D:t19".
1762 "break C::f" should not be looking for field f in
1764 but just for the field f in the baseclasses of C
1765 (no matter what their names).
1767 However, I don't know how to replace the code below
1768 that depends on knowing the name of D. */
1770 && (sym_class
= lookup_symbol (class_name
,
1771 (struct block
*)NULL
,
1774 (struct symtab
**)NULL
)))
1777 t
= SYMBOL_TYPE (sym_class
);
1778 for (method_counter
= TYPE_NFN_FIELDS (t
) - 1;
1779 method_counter
>= 0;
1783 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, method_counter
);
1785 char *method_name
= TYPE_FN_FIELDLIST_NAME (t
, method_counter
);
1786 if (!strcmp (name
, method_name
))
1787 /* Find all the fields with that name. */
1788 for (field_counter
= TYPE_FN_FIELDLIST_LENGTH (t
, method_counter
) - 1;
1793 if (TYPE_FLAGS (TYPE_FN_FIELD_TYPE (f
, field_counter
)) & TYPE_FLAG_STUB
)
1794 check_stub_method (t
, method_counter
, field_counter
);
1795 phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, field_counter
);
1796 physnames
[i1
] = (char*) alloca (strlen (phys_name
) + 1);
1797 strcpy (physnames
[i1
], phys_name
);
1798 sym_arr
[i1
] = lookup_symbol (phys_name
,
1799 SYMBOL_BLOCK_VALUE (sym_class
),
1802 (struct symtab
**) NULL
);
1803 if (sym_arr
[i1
]) i1
++;
1807 /* Only search baseclasses if there is no match yet,
1808 * since names in derived classes override those in baseclasses.
1812 for (ibase
= 0; ibase
< TYPE_N_BASECLASSES (t
); ibase
++)
1813 i1
+= find_methods(TYPE_BASECLASS(t
, ibase
), name
,
1814 physnames
+ i1
, sym_arr
+ i1
);
1818 /* Parse a string that specifies a line number.
1819 Pass the address of a char * variable; that variable will be
1820 advanced over the characters actually parsed.
1824 LINENUM -- that line number in current file. PC returned is 0.
1825 FILE:LINENUM -- that line in that file. PC returned is 0.
1826 FUNCTION -- line number of openbrace of that function.
1827 PC returned is the start of the function.
1828 VARIABLE -- line number of definition of that variable.
1830 FILE:FUNCTION -- likewise, but prefer functions in that file.
1831 *EXPR -- line in which address EXPR appears.
1833 FUNCTION may be an undebuggable function found in misc_function_vector.
1835 If the argument FUNFIRSTLINE is nonzero, we want the first line
1836 of real code inside a function when a function is specified.
1838 DEFAULT_SYMTAB specifies the file to use if none is specified.
1839 It defaults to current_source_symtab.
1840 DEFAULT_LINE specifies the line number to use for relative
1841 line numbers (that start with signs). Defaults to current_source_line.
1843 Note that it is possible to return zero for the symtab
1844 if no file is validly specified. Callers must check that.
1845 Also, the line number returned may be invalid. */
1847 struct symtabs_and_lines
1848 decode_line_1 (argptr
, funfirstline
, default_symtab
, default_line
)
1851 struct symtab
*default_symtab
;
1854 struct symtabs_and_lines
decode_line_2 ();
1855 struct symtabs_and_lines values
;
1856 struct symtab_and_line val
;
1857 register char *p
, *p1
;
1859 register struct symtab
*s
;
1861 register struct symbol
*sym
;
1862 /* The symtab that SYM was found in. */
1863 struct symtab
*sym_symtab
;
1865 register CORE_ADDR pc
;
1868 struct symbol
*sym_class
;
1870 struct symbol
**sym_arr
;
1874 /* Defaults have defaults. */
1876 if (default_symtab
== 0)
1878 default_symtab
= current_source_symtab
;
1879 default_line
= current_source_line
;
1882 /* See if arg is *PC */
1884 if (**argptr
== '*')
1887 pc
= parse_and_eval_address_1 (argptr
);
1888 values
.sals
= (struct symtab_and_line
*)
1889 xmalloc (sizeof (struct symtab_and_line
));
1891 values
.sals
[0] = find_pc_line (pc
, 0);
1892 values
.sals
[0].pc
= pc
;
1896 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
1900 for (p
= *argptr
; *p
; p
++)
1902 if (p
[0] == ':' || p
[0] == ' ' || p
[0] == '\t')
1905 while (p
[0] == ' ' || p
[0] == '\t') p
++;
1907 q
= operator_chars (*argptr
, &q1
);
1914 /* Extract the class name. */
1916 while (p
!= *argptr
&& p
[-1] == ' ') --p
;
1917 copy
= (char *) alloca (p
- *argptr
+ 1);
1918 bcopy (*argptr
, copy
, p
- *argptr
);
1919 copy
[p
- *argptr
] = 0;
1921 /* Discard the class name from the arg. */
1923 while (*p
== ' ' || *p
== '\t') p
++;
1926 sym_class
= lookup_symbol (copy
, 0, STRUCT_NAMESPACE
, 0,
1927 (struct symtab
**)NULL
);
1930 (TYPE_CODE (SYMBOL_TYPE (sym_class
)) == TYPE_CODE_STRUCT
1931 || TYPE_CODE (SYMBOL_TYPE (sym_class
)) == TYPE_CODE_UNION
))
1933 /* Arg token is not digits => try it as a function name
1934 Find the next token (everything up to end or next whitespace). */
1936 while (*p
&& *p
!= ' ' && *p
!= '\t' && *p
!= ',' && *p
!=':') p
++;
1937 q
= operator_chars (*argptr
, &q1
);
1939 copy
= (char *) alloca (p
- *argptr
+ 1 + (q1
- q
));
1944 copy
[2] = CPLUS_MARKER
;
1945 bcopy (q
, copy
+ 3, q1
- q
);
1946 copy
[3 + (q1
- q
)] = '\0';
1951 bcopy (*argptr
, copy
, p
- *argptr
);
1952 copy
[p
- *argptr
] = '\0';
1955 /* no line number may be specified */
1956 while (*p
== ' ' || *p
== '\t') p
++;
1960 i1
= 0; /* counter for the symbol array */
1961 t
= SYMBOL_TYPE (sym_class
);
1962 sym_arr
= (struct symbol
**) alloca(TYPE_NFN_FIELDS_TOTAL (t
) * sizeof(struct symbol
*));
1963 physnames
= (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t
) * sizeof(char*));
1965 if (destructor_name_p (copy
, t
))
1967 /* destructors are a special case. */
1968 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, 0);
1969 int len
= TYPE_FN_FIELDLIST_LENGTH (t
, 0) - 1;
1970 char *phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, len
);
1971 physnames
[i1
] = (char *)alloca (strlen (phys_name
) + 1);
1972 strcpy (physnames
[i1
], phys_name
);
1974 lookup_symbol (phys_name
, SYMBOL_BLOCK_VALUE (sym_class
),
1975 VAR_NAMESPACE
, 0, (struct symtab
**)NULL
);
1976 if (sym_arr
[i1
]) i1
++;
1979 i1
= find_methods (t
, copy
, physnames
, sym_arr
);
1982 /* There is exactly one field with that name. */
1985 if (sym
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1987 /* Arg is the name of a function */
1988 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) + FUNCTION_START_OFFSET
;
1991 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
1993 values
.sals
[0] = find_pc_line (pc
, 0);
1994 values
.sals
[0].pc
= (values
.sals
[0].end
&& values
.sals
[0].pc
!= pc
) ? values
.sals
[0].end
: pc
;
2004 /* There is more than one field with that name
2005 (overloaded). Ask the user which one to use. */
2006 return decode_line_2 (sym_arr
, i1
, funfirstline
);
2012 if (OPNAME_PREFIX_P (copy
))
2014 tmp
= (char *)alloca (strlen (copy
+3) + 9);
2015 strcpy (tmp
, "operator ");
2016 strcat (tmp
, copy
+3);
2020 error ("that class does not have any method named %s", tmp
);
2024 /* The quotes are important if copy is empty. */
2025 error("No class, struct, or union named \"%s\"", copy
);
2030 /* Extract the file name. */
2032 while (p
!= *argptr
&& p
[-1] == ' ') --p
;
2033 copy
= (char *) alloca (p
- *argptr
+ 1 + (q1
- q
));
2038 copy
[2] = CPLUS_MARKER
;
2039 bcopy (q
, copy
+ 3, q1
-q
);
2040 copy
[3 + (q1
-q
)] = 0;
2045 bcopy (*argptr
, copy
, p
- *argptr
);
2046 copy
[p
- *argptr
] = 0;
2049 /* Find that file's data. */
2050 s
= lookup_symtab (copy
);
2053 if (symtab_list
== 0 && partial_symtab_list
== 0)
2054 error (no_symtab_msg
);
2055 error ("No source file named %s.", copy
);
2058 /* Discard the file name from the arg. */
2060 while (*p
== ' ' || *p
== '\t') p
++;
2064 /* S is specified file's symtab, or 0 if no file specified.
2065 arg no longer contains the file name. */
2067 /* Check whether arg is all digits (and sign) */
2070 if (*p
== '-' || *p
== '+') p
++;
2071 while (*p
>= '0' && *p
<= '9')
2074 if (p
!= *argptr
&& (*p
== 0 || *p
== ' ' || *p
== '\t' || *p
== ','))
2076 /* We found a token consisting of all digits -- at least one digit. */
2077 enum sign
{none
, plus
, minus
} sign
= none
;
2079 /* This is where we need to make sure that we have good defaults.
2080 We must guarantee that this section of code is never executed
2081 when we are called with just a function name, since
2082 select_source_symtab calls us with such an argument */
2084 if (s
== 0 && default_symtab
== 0)
2086 if (symtab_list
== 0 && partial_symtab_list
== 0)
2087 error (no_symtab_msg
);
2088 select_source_symtab (0);
2089 default_symtab
= current_source_symtab
;
2090 default_line
= current_source_line
;
2093 if (**argptr
== '+')
2094 sign
= plus
, (*argptr
)++;
2095 else if (**argptr
== '-')
2096 sign
= minus
, (*argptr
)++;
2097 val
.line
= atoi (*argptr
);
2104 val
.line
= default_line
+ val
.line
;
2110 val
.line
= default_line
- val
.line
;
2115 break; /* No need to adjust val.line. */
2118 while (*p
== ' ' || *p
== '\t') p
++;
2124 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
2125 values
.sals
[0] = val
;
2130 /* Arg token is not digits => try it as a variable name
2131 Find the next token (everything up to end or next whitespace). */
2133 while (*p
&& *p
!= ' ' && *p
!= '\t' && *p
!= ',') p
++;
2134 copy
= (char *) alloca (p
- *argptr
+ 1);
2135 bcopy (*argptr
, copy
, p
- *argptr
);
2136 copy
[p
- *argptr
] = 0;
2137 while (*p
== ' ' || *p
== '\t') p
++;
2140 /* Look up that token as a variable.
2141 If file specified, use that file's per-file block to start with. */
2143 sym
= lookup_symbol (copy
,
2144 (s
? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
)
2145 : get_selected_block ()),
2146 VAR_NAMESPACE
, 0, &sym_symtab
);
2150 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
2152 /* Arg is the name of a function */
2153 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) + FUNCTION_START_OFFSET
;
2156 val
= find_pc_line (pc
, 0);
2157 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2158 /* Convex: no need to suppress code on first line, if any */
2161 val
.pc
= (val
.end
&& val
.pc
!= pc
) ? val
.end
: pc
;
2163 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
2164 values
.sals
[0] = val
;
2167 /* I think this is always the same as the line that
2168 we calculate above, but the general principle is
2169 "trust the symbols more than stuff like
2171 if (SYMBOL_LINE (sym
) != 0)
2172 values
.sals
[0].line
= SYMBOL_LINE (sym
);
2176 else if (SYMBOL_LINE (sym
) != 0)
2178 /* We know its line number. */
2179 values
.sals
= (struct symtab_and_line
*)
2180 xmalloc (sizeof (struct symtab_and_line
));
2182 bzero (&values
.sals
[0], sizeof (values
.sals
[0]));
2183 values
.sals
[0].symtab
= sym_symtab
;
2184 values
.sals
[0].line
= SYMBOL_LINE (sym
);
2188 /* This can happen if it is compiled with a compiler which doesn't
2189 put out line numbers for variables. */
2190 error ("Line number not known for symbol \"%s\"", copy
);
2193 if (symtab_list
== 0 && partial_symtab_list
== 0)
2194 error (no_symtab_msg
);
2196 if ((i
= lookup_misc_func (copy
)) >= 0)
2200 val
.pc
= misc_function_vector
[i
].address
+ FUNCTION_START_OFFSET
;
2202 SKIP_PROLOGUE (val
.pc
);
2203 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
2204 values
.sals
[0] = val
;
2209 error ("Function %s not defined.", copy
);
2210 return values
; /* for lint */
2213 struct symtabs_and_lines
2214 decode_line_spec (string
, funfirstline
)
2218 struct symtabs_and_lines sals
;
2220 error ("Empty line specification.");
2221 sals
= decode_line_1 (&string
, funfirstline
,
2222 current_source_symtab
, current_source_line
);
2224 error ("Junk at end of line specification: %s", string
);
2228 /* Given a list of NELTS symbols in sym_arr (with corresponding
2229 mangled names in physnames), return a list of lines to operate on
2230 (ask user if necessary). */
2231 struct symtabs_and_lines
2232 decode_line_2 (sym_arr
, nelts
, funfirstline
)
2233 struct symbol
*sym_arr
[];
2238 struct symtabs_and_lines values
, return_values
;
2239 register CORE_ADDR pc
;
2240 char *args
, *arg1
, *command_line_input ();
2244 values
.sals
= (struct symtab_and_line
*) alloca (nelts
* sizeof(struct symtab_and_line
));
2245 return_values
.sals
= (struct symtab_and_line
*) xmalloc (nelts
* sizeof(struct symtab_and_line
));
2248 printf("[0] cancel\n[1] all\n");
2251 if (sym_arr
[i
] && SYMBOL_CLASS (sym_arr
[i
]) == LOC_BLOCK
)
2253 /* Arg is the name of a function */
2254 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym_arr
[i
]))
2255 + FUNCTION_START_OFFSET
;
2258 values
.sals
[i
] = find_pc_line (pc
, 0);
2259 values
.sals
[i
].pc
= (values
.sals
[i
].end
&& values
.sals
[i
].pc
!= pc
) ?
2260 values
.sals
[i
].end
: pc
;
2261 printf("[%d] file:%s; line number:%d\n",
2262 (i
+2), values
.sals
[i
].symtab
->filename
, values
.sals
[i
].line
);
2264 else printf ("?HERE\n");
2268 if ((prompt
= getenv ("PS2")) == NULL
)
2272 printf("%s ",prompt
);
2275 args
= command_line_input (0, 0);
2278 error_no_arg ("one or more choice numbers");
2286 while (*arg1
>= '0' && *arg1
<= '9') arg1
++;
2287 if (*arg1
&& *arg1
!= ' ' && *arg1
!= '\t')
2288 error ("Arguments must be choice numbers.");
2293 error ("cancelled");
2296 bcopy (values
.sals
, return_values
.sals
, (nelts
* sizeof(struct symtab_and_line
)));
2297 return_values
.nelts
= nelts
;
2298 return return_values
;
2301 if (num
> nelts
+ 2)
2303 printf ("No choice number %d.\n", num
);
2308 if (values
.sals
[num
].pc
)
2310 return_values
.sals
[i
++] = values
.sals
[num
];
2311 values
.sals
[num
].pc
= 0;
2315 printf ("duplicate request for %d ignored.\n", num
);
2320 while (*args
== ' ' || *args
== '\t') args
++;
2322 return_values
.nelts
= i
;
2323 return return_values
;
2326 /* Return the index of misc function named NAME. */
2329 lookup_misc_func (name
)
2330 register char *name
;
2334 for (i
= 0; i
< misc_function_count
; i
++)
2335 if (!strcmp (misc_function_vector
[i
].name
, name
))
2337 return -1; /* not found */
2340 /* Slave routine for sources_info. Force line breaks at ,'s.
2341 NAME is the name to print and *FIRST is nonzero if this is the first
2342 name printed. Set *FIRST to zero. */
2344 output_source_filename (name
, first
)
2349 /* Table of files printed so far. Since a single source file can
2350 result in several partial symbol tables, we need to avoid printing
2351 it more than once. Note: if some of the psymtabs are read in and
2352 some are not, it gets printed both under "Source files for which
2353 symbols have been read" and "Source files for which symbols will
2354 be read in on demand". I consider this a reasonable way to deal
2355 with the situation. I'm not sure whether this can also happen for
2356 symtabs; it doesn't hurt to check. */
2357 static char **tab
= NULL
;
2358 /* Allocated size of tab in elements.
2359 Start with one 256-byte block (when using GNU malloc.c).
2360 24 is the malloc overhead when range checking is in effect. */
2361 static int tab_alloc_size
= (256 - 24) / sizeof (char *);
2362 /* Current size of tab in elements. */
2363 static int tab_cur_size
;
2370 tab
= (char **) xmalloc (tab_alloc_size
* sizeof (*tab
));
2374 /* Is NAME in tab? */
2375 for (p
= tab
; p
< tab
+ tab_cur_size
; p
++)
2376 if (strcmp (*p
, name
) == 0)
2377 /* Yes; don't print it again. */
2379 /* No; add it to tab. */
2380 if (tab_cur_size
== tab_alloc_size
)
2382 tab_alloc_size
*= 2;
2383 tab
= (char **) xrealloc (tab
, tab_alloc_size
* sizeof (*tab
));
2385 tab
[tab_cur_size
++] = name
;
2394 printf_filtered (",");
2398 if (column
!= 0 && column
+ strlen (name
) >= 70)
2400 printf_filtered ("\n");
2403 else if (column
!= 0)
2405 printf_filtered (" ");
2408 fputs_filtered (name
, stdout
);
2409 column
+= strlen (name
);
2415 register struct symtab
*s
;
2416 register struct partial_symtab
*ps
;
2419 if (symtab_list
== 0 && partial_symtab_list
== 0)
2421 printf (no_symtab_msg
);
2425 printf_filtered ("Source files for which symbols have been read in:\n\n");
2428 for (s
= symtab_list
; s
; s
= s
->next
)
2429 output_source_filename (s
->filename
, &first
);
2430 printf_filtered ("\n\n");
2432 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2435 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
2437 output_source_filename (ps
->filename
, &first
);
2438 printf_filtered ("\n");
2441 /* List all symbols (if REGEXP is 0) or all symbols matching REGEXP.
2442 If CLASS is zero, list all symbols except functions and type names.
2443 If CLASS is 1, list only functions.
2444 If CLASS is 2, list only type names.
2446 BPT is non-zero if we should set a breakpoint at the functions
2450 list_symbols (regexp
, class, bpt
)
2455 register struct symtab
*s
;
2456 register struct partial_symtab
*ps
;
2457 register struct blockvector
*bv
;
2458 struct blockvector
*prev_bv
= 0;
2459 register struct block
*b
;
2461 register struct symbol
*sym
;
2462 struct partial_symbol
*psym
;
2464 static char *classnames
[]
2465 = {"variable", "function", "type", "method"};
2466 int found_in_file
= 0;
2469 if (0 != (val
= (char *) re_comp (regexp
)))
2470 error ("Invalid regexp (%s): %s", val
, regexp
);
2472 /* Search through the partial_symtab_list *first* for all symbols
2473 matching the regexp. That way we don't have to reproduce all of
2474 the machinery below. */
2475 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
2477 struct partial_symbol
*bound
, *gbound
, *sbound
;
2480 if (ps
->readin
) continue;
2482 gbound
= global_psymbols
.list
+ ps
->globals_offset
+ ps
->n_global_syms
;
2483 sbound
= static_psymbols
.list
+ ps
->statics_offset
+ ps
->n_static_syms
;
2486 /* Go through all of the symbols stored in a partial
2487 symtab in one loop. */
2488 psym
= global_psymbols
.list
+ ps
->globals_offset
;
2493 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
2495 psym
= static_psymbols
.list
+ ps
->statics_offset
;
2506 /* If it would match (logic taken from loop below)
2507 load the file and go on to the next one */
2508 if ((regexp
== 0 || re_exec (SYMBOL_NAME (psym
)))
2509 && ((class == 0 && SYMBOL_CLASS (psym
) != LOC_TYPEDEF
2510 && SYMBOL_CLASS (psym
) != LOC_BLOCK
)
2511 || (class == 1 && SYMBOL_CLASS (psym
) == LOC_BLOCK
)
2512 || (class == 2 && SYMBOL_CLASS (psym
) == LOC_TYPEDEF
)
2513 || (class == 3 && SYMBOL_CLASS (psym
) == LOC_BLOCK
)))
2515 (void) PSYMTAB_TO_SYMTAB(ps
);
2523 /* Here, *if* the class is correct (function only, right now), we
2524 search through the misc function vector for symbols that
2525 match, and call find_pc_symtab on them to force their symbols to
2526 be read. The symbol will then be found during the scan of symtabs
2531 for (i
= 0; i
< misc_function_count
; i
++)
2532 if (regexp
== 0 || re_exec (misc_function_vector
[i
].name
))
2534 (void) find_pc_symtab (misc_function_vector
[i
].address
);
2538 /* Printout here so as to get after the "Reading in symbols"
2539 messages which will be generated above. */
2541 printf_filtered (regexp
2542 ? "All %ss matching regular expression \"%s\":\n"
2543 : "All defined %ss:\n",
2547 for (s
= symtab_list
; s
; s
= s
->next
)
2550 bv
= BLOCKVECTOR (s
);
2551 /* Often many files share a blockvector.
2552 Scan each blockvector only once so that
2553 we don't get every symbol many times.
2554 It happens that the first symtab in the list
2555 for any given blockvector is the main file. */
2557 for (i
= GLOBAL_BLOCK
; i
<= STATIC_BLOCK
; i
++)
2559 b
= BLOCKVECTOR_BLOCK (bv
, i
);
2560 /* Skip the sort if this block is always sorted. */
2561 if (!BLOCK_SHOULD_SORT (b
))
2562 sort_block_syms (b
);
2563 for (j
= 0; j
< BLOCK_NSYMS (b
); j
++)
2566 sym
= BLOCK_SYM (b
, j
);
2567 if ((regexp
== 0 || re_exec (SYMBOL_NAME (sym
)))
2568 && ((class == 0 && SYMBOL_CLASS (sym
) != LOC_TYPEDEF
2569 && SYMBOL_CLASS (sym
) != LOC_BLOCK
)
2570 || (class == 1 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
2571 || (class == 2 && SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
2572 || (class == 3 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)))
2576 /* Set a breakpoint here, if it's a function */
2578 break_command (SYMBOL_NAME(sym
), 0);
2580 else if (!found_in_file
)
2582 fputs_filtered ("\nFile ", stdout
);
2583 fputs_filtered (s
->filename
, stdout
);
2584 fputs_filtered (":\n", stdout
);
2588 if (class != 2 && i
== STATIC_BLOCK
)
2589 printf_filtered ("static ");
2591 && SYMBOL_NAMESPACE (sym
) != STRUCT_NAMESPACE
)
2592 printf_filtered ("typedef ");
2596 type_print (SYMBOL_TYPE (sym
),
2597 (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
2598 ? "" : SYMBOL_NAME (sym
)),
2602 && SYMBOL_NAMESPACE (sym
) != STRUCT_NAMESPACE
2603 && (TYPE_NAME ((SYMBOL_TYPE (sym
))) == 0
2604 || 0 != strcmp (TYPE_NAME ((SYMBOL_TYPE (sym
))),
2605 SYMBOL_NAME (sym
))))
2607 fputs_filtered (" ", stdout
);
2608 fprint_symbol (stdout
, SYMBOL_NAME (sym
));
2611 printf_filtered (";\n");
2617 type_print_base (TYPE_FN_FIELD_TYPE(t
, i
), stdout
, 0, 0);
2618 type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t
, i
), stdout
, 0);
2619 sprintf (buf
, " %s::", type_name_no_tag (t
));
2620 type_print_method_args (TYPE_FN_FIELD_ARGS (t
, i
), buf
, name
, stdout
);
2631 variables_info (regexp
)
2634 list_symbols (regexp
, 0, 0);
2638 functions_info (regexp
)
2641 list_symbols (regexp
, 1, 0);
2648 list_symbols (regexp
, 2, 0);
2652 /* Tiemann says: "info methods was never implemented." */
2654 methods_info (regexp
)
2657 list_symbols (regexp
, 3, 0);
2661 /* Breakpoint all functions matching regular expression. */
2663 rbreak_command (regexp
)
2666 list_symbols (regexp
, 1, 1);
2669 /* Initialize the standard C scalar types. */
2673 init_type (code
, length
, uns
, name
)
2674 enum type_code code
;
2678 register struct type
*type
;
2680 type
= (struct type
*) xmalloc (sizeof (struct type
));
2681 bzero (type
, sizeof *type
);
2682 TYPE_MAIN_VARIANT (type
) = type
;
2683 TYPE_CODE (type
) = code
;
2684 TYPE_LENGTH (type
) = length
;
2685 TYPE_FLAGS (type
) = uns
? TYPE_FLAG_UNSIGNED
: 0;
2686 TYPE_FLAGS (type
) |= TYPE_FLAG_PERM
;
2687 TYPE_NFIELDS (type
) = 0;
2688 TYPE_NAME (type
) = name
;
2691 TYPE_NFN_FIELDS (type
) = 0;
2692 TYPE_N_BASECLASSES (type
) = 0;
2696 /* Return Nonzero if block a is lexically nested within block b,
2697 or if a and b have the same pc range.
2698 Return zero otherwise. */
2701 struct block
*a
, *b
;
2705 return BLOCK_START (a
) >= BLOCK_START (b
)
2706 && BLOCK_END (a
) <= BLOCK_END (b
);
2710 /* Helper routine for make_symbol_completion_list. */
2712 int return_val_size
, return_val_index
;
2716 completion_list_add_symbol (symname
)
2719 if (return_val_index
+ 3 > return_val_size
)
2721 (char **)xrealloc (return_val
,
2722 (return_val_size
*= 2) * sizeof (char *));
2724 return_val
[return_val_index
] =
2725 (char *)xmalloc (1 + strlen (symname
));
2727 strcpy (return_val
[return_val_index
], symname
);
2729 return_val
[++return_val_index
] = (char *)NULL
;
2732 /* Return a NULL terminated array of all symbols (regardless of class) which
2733 begin by matching TEXT. If the answer is no symbols, then the return value
2734 is an array which contains only a NULL pointer.
2736 Problem: All of the symbols have to be copied because readline
2737 frees them. I'm not going to worry about this; hopefully there
2738 won't be that many. */
2741 make_symbol_completion_list (text
)
2744 register struct symtab
*s
;
2745 register struct partial_symtab
*ps
;
2746 register struct block
*b
, *surrounding_static_block
= 0;
2747 extern struct block
*get_selected_block ();
2749 struct partial_symbol
*psym
;
2751 int text_len
= strlen (text
);
2752 return_val_size
= 100;
2753 return_val_index
= 0;
2755 (char **)xmalloc ((1 + return_val_size
) *sizeof (char *));
2756 return_val
[0] = (char *)NULL
;
2758 /* Look through the partial symtabs for all symbols which begin
2759 by matching TEXT. Add each one that you find to the list. */
2761 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
2763 /* If the psymtab's been read in we'll get it when we search
2764 through the blockvector. */
2765 if (ps
->readin
) continue;
2767 for (psym
= global_psymbols
.list
+ ps
->globals_offset
;
2768 psym
< (global_psymbols
.list
+ ps
->globals_offset
2769 + ps
->n_global_syms
);
2772 QUIT
; /* If interrupted, then quit. */
2773 if ((strncmp (SYMBOL_NAME (psym
), text
, text_len
) == 0))
2774 completion_list_add_symbol (SYMBOL_NAME (psym
));
2777 for (psym
= static_psymbols
.list
+ ps
->statics_offset
;
2778 psym
< (static_psymbols
.list
+ ps
->statics_offset
2779 + ps
->n_static_syms
);
2783 if ((strncmp (SYMBOL_NAME (psym
), text
, text_len
) == 0))
2784 completion_list_add_symbol (SYMBOL_NAME (psym
));
2788 /* At this point scan through the misc function vector and add each
2789 symbol you find to the list. Eventually we want to ignore
2790 anything that isn't a text symbol (everything else will be
2791 handled by the psymtab code above). */
2793 for (i
= 0; i
< misc_function_count
; i
++)
2794 if (!strncmp (text
, misc_function_vector
[i
].name
, text_len
))
2795 completion_list_add_symbol (misc_function_vector
[i
].name
);
2797 /* Search upwards from currently selected frame (so that we can
2798 complete on local vars. */
2799 for (b
= get_selected_block (); b
; b
= BLOCK_SUPERBLOCK (b
))
2801 if (!BLOCK_SUPERBLOCK (b
))
2802 surrounding_static_block
= b
; /* For elmin of dups */
2804 /* Also catch fields of types defined in this places which
2805 match our text string. Only complete on types visible
2806 from current context. */
2807 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2809 register struct symbol
*sym
= BLOCK_SYM (b
, i
);
2811 if (!strncmp (SYMBOL_NAME (sym
), text
, text_len
))
2812 completion_list_add_symbol (SYMBOL_NAME (sym
));
2814 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
2816 struct type
*t
= SYMBOL_TYPE (sym
);
2817 enum type_code c
= TYPE_CODE (t
);
2819 if (c
== TYPE_CODE_UNION
|| c
== TYPE_CODE_STRUCT
)
2820 for (j
= TYPE_N_BASECLASSES (t
); j
< TYPE_NFIELDS (t
); j
++)
2821 if (TYPE_FIELD_NAME (t
, j
) &&
2822 !strncmp (TYPE_FIELD_NAME (t
, j
), text
, text_len
))
2823 completion_list_add_symbol (TYPE_FIELD_NAME (t
, j
));
2828 /* Go through the symtabs and check the externs and statics for
2829 symbols which match. */
2831 for (s
= symtab_list
; s
; s
= s
->next
)
2833 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
2835 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2836 if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b
, i
)), text
, text_len
))
2837 completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b
, i
)));
2840 for (s
= symtab_list
; s
; s
= s
->next
)
2842 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
2844 /* Don't do this block twice. */
2845 if (b
== surrounding_static_block
) continue;
2847 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2848 if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b
, i
)), text
, text_len
))
2849 completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b
, i
)));
2852 return (return_val
);
2856 _initialize_symtab ()
2858 add_info ("variables", variables_info
,
2859 "All global and static variable names, or those matching REGEXP.");
2860 add_info ("functions", functions_info
,
2861 "All function names, or those matching REGEXP.");
2863 /* FIXME: This command has at least the following problems:
2864 1. It prints builtin types (in a very strange and confusing fashion).
2865 2. It doesn't print right, e.g. with
2866 typedef struct foo *FOO
2867 type_print prints "FOO" when we want to make it (in this situation)
2868 print "struct foo *".
2869 I also think "ptype" or "whatis" is more likely to be useful (but if
2870 there is much disagreement "info types" can be fixed). */
2871 add_info ("types", types_info
,
2872 "All types names, or those matching REGEXP.");
2875 add_info ("methods", methods_info
,
2876 "All method names, or those matching REGEXP::REGEXP.\n\
2877 If the class qualifier is ommited, it is assumed to be the current scope.\n\
2878 If the first REGEXP is ommited, then all methods matching the second REGEXP\n\
2881 add_info ("sources", sources_info
,
2882 "Source files in the program.");
2884 add_com ("rbreak", no_class
, rbreak_command
,
2885 "Set a breakpoint for all functions matching REGEXP.");
2887 /* FIXME: The code below assumes that the sizes of the basic data
2888 types are the same on the host and target machines!!! */
2890 builtin_type_void
= init_type (TYPE_CODE_VOID
, 1, 0, "void");
2892 builtin_type_float
= init_type (TYPE_CODE_FLT
, sizeof (float), 0, "float");
2893 builtin_type_double
= init_type (TYPE_CODE_FLT
, sizeof (double), 0, "double");
2895 builtin_type_char
= init_type (TYPE_CODE_INT
, sizeof (char), 0, "char");
2896 builtin_type_short
= init_type (TYPE_CODE_INT
, sizeof (short), 0, "short");
2897 builtin_type_long
= init_type (TYPE_CODE_INT
, sizeof (long), 0, "long");
2898 builtin_type_int
= init_type (TYPE_CODE_INT
, sizeof (int), 0, "int");
2900 builtin_type_unsigned_char
= init_type (TYPE_CODE_INT
, sizeof (char), 1, "unsigned char");
2901 builtin_type_unsigned_short
= init_type (TYPE_CODE_INT
, sizeof (short), 1, "unsigned short");
2902 builtin_type_unsigned_long
= init_type (TYPE_CODE_INT
, sizeof (long), 1, "unsigned long");
2903 builtin_type_unsigned_int
= init_type (TYPE_CODE_INT
, sizeof (int), 1, "unsigned int");
2905 builtin_type_long_long
=
2906 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
2908 builtin_type_unsigned_long_long
=
2909 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
2910 1, "unsigned long long");
2912 builtin_type_error
= init_type (TYPE_CODE_ERROR
, 0, 0, "<unknown type>");