1 /* Symbol table lookup for the GNU debugger, GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
36 #include <sys/types.h>
41 extern char *getenv ();
43 extern char *cplus_demangle ();
44 extern struct value
*value_of_this ();
45 extern void break_command ();
46 extern void select_source_symtab ();
48 /* Functions this file defines */
49 static int find_line_common ();
50 struct partial_symtab
*lookup_partial_symtab ();
51 static struct partial_symbol
*lookup_partial_symbol ();
52 static struct partial_symbol
*lookup_demangled_partial_symbol ();
53 static struct symbol
*lookup_demangled_block_symbol ();
55 /* The single non-language-specific builtin type */
56 struct type
*builtin_type_error
;
58 /* Block in which the most recently searched-for symbol was found.
59 Might be better to make this a parameter to lookup_symbol and
61 struct block
*block_found
;
63 char no_symtab_msg
[] = "No symbol table is loaded. Use the \"file\" command.";
65 /* Check for a symtab of a specific name; first in symtabs, then in
66 psymtabs. *If* there is no '/' in the name, a match after a '/'
67 in the symtab filename will also work. */
69 static struct symtab
*
70 lookup_symtab_1 (name
)
73 register struct symtab
*s
;
74 register struct partial_symtab
*ps
;
75 register char *slash
= strchr (name
, '/');
76 register int len
= strlen (name
);
78 for (s
= symtab_list
; s
; s
= s
->next
)
79 if (!strcmp (name
, s
->filename
))
82 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
83 if (!strcmp (name
, ps
->filename
))
86 fatal ("Internal: readin pst found when no symtab found.");
87 return PSYMTAB_TO_SYMTAB (ps
);
92 for (s
= symtab_list
; s
; s
= s
->next
)
94 int l
= strlen (s
->filename
);
96 if (s
->filename
[l
- len
-1] == '/'
97 && !strcmp (s
->filename
+ l
- len
, name
))
101 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
103 int l
= strlen (ps
->filename
);
105 if (ps
->filename
[l
- len
- 1] == '/'
106 && !strcmp (ps
->filename
+ l
- len
, name
))
109 fatal ("Internal: readin pst found when no symtab found.");
110 return PSYMTAB_TO_SYMTAB (ps
);
117 /* Lookup the symbol table of a source file named NAME. Try a couple
118 of variations if the first lookup doesn't work. */
124 register struct symtab
*s
;
127 s
= lookup_symtab_1 (name
);
130 /* If name not found as specified, see if adding ".c" helps. */
132 copy
= (char *) alloca (strlen (name
) + 3);
135 s
= lookup_symtab_1 (copy
);
138 /* We didn't find anything; die. */
142 /* Lookup the partial symbol table of a source file named NAME. This
143 only returns true on an exact match (ie. this semantics are
144 different from lookup_symtab. */
146 struct partial_symtab
*
147 lookup_partial_symtab (name
)
150 register struct partial_symtab
*s
;
152 for (s
= partial_symtab_list
; s
; s
= s
->next
)
153 if (!strcmp (name
, s
->filename
))
159 /* Return a typename for a struct/union/enum type
160 without the tag qualifier. If the type has a NULL name,
163 type_name_no_tag (type
)
164 register struct type
*type
;
166 register char *name
= TYPE_NAME (type
);
172 switch (TYPE_CODE (type
))
174 case TYPE_CODE_STRUCT
:
176 case TYPE_CODE_UNION
:
183 name
= strchr (name
, ' ');
187 return TYPE_NAME (type
);
190 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
192 If this is a stubbed struct (i.e. declared as struct foo *), see if
193 we can find a full definition in some other file. If so, copy this
194 definition, so we can use it in future. If not, set a flag so we
195 don't waste too much time in future.
197 This used to be coded as a macro, but I don't think it is called
198 often enough to merit such treatment.
201 struct complaint stub_noname_complaint
=
202 {"stub type has NULL name", 0, 0};
205 check_stub_type(type
)
208 if (TYPE_FLAGS(type
) & TYPE_FLAG_STUB
)
210 char* name
= type_name_no_tag (type
);
214 complain (&stub_noname_complaint
, 0);
217 sym
= lookup_symbol (name
, 0, STRUCT_NAMESPACE
, 0,
218 (struct symtab
**)NULL
);
220 bcopy (SYMBOL_TYPE(sym
), type
, sizeof (struct type
));
224 /* Demangle a GDB method stub type. */
226 gdb_mangle_typename (type
)
229 static struct type
*last_type
;
230 static char *mangled_typename
;
232 if (type
!= last_type
)
234 /* Need a new type prefix. */
236 char *newname
= type_name_no_tag (type
);
240 if (mangled_typename
)
241 free (mangled_typename
);
243 len
= strlen (newname
);
244 sprintf (buf
, "__%d", len
);
245 mangled_typename
= (char *)xmalloc (strlen (buf
) + len
+ 1);
246 strcpy (mangled_typename
, buf
);
247 strcat (mangled_typename
, newname
);
248 /* Now we have built "__#newname". */
250 return mangled_typename
;
253 /* Lookup a primitive type named NAME.
254 Return zero if NAME is not a primitive type.*/
257 lookup_primitive_typename (name
)
262 for (p
= current_language
->la_builtin_type_vector
; *p
; p
++)
263 if(!strcmp((**p
)->name
, name
))
268 /* Lookup a typedef or primitive type named NAME,
269 visible in lexical block BLOCK.
270 If NOERR is nonzero, return zero if NAME is not suitably defined. */
273 lookup_typename (name
, block
, noerr
)
278 register struct symbol
*sym
=
279 lookup_symbol (name
, block
, VAR_NAMESPACE
, 0, (struct symtab
**)NULL
);
280 if (sym
== 0 || SYMBOL_CLASS (sym
) != LOC_TYPEDEF
)
283 tmp
= lookup_primitive_typename (name
);
286 else if (!tmp
&& noerr
)
289 error ("No type named %s.", name
);
291 return SYMBOL_TYPE (sym
);
295 lookup_unsigned_typename (name
)
298 char *uns
= alloca (strlen(name
) + 10);
300 strcpy (uns
, "unsigned ");
301 strcpy (uns
+9, name
);
302 return lookup_typename (uns
, (struct block
*)0, 0);
305 /* Lookup a structure type named "struct NAME",
306 visible in lexical block BLOCK. */
309 lookup_struct (name
, block
)
313 register struct symbol
*sym
314 = lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0, (struct symtab
**)NULL
);
317 error ("No struct type named %s.", name
);
318 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
319 error ("This context has class, union or enum %s, not a struct.", name
);
320 return SYMBOL_TYPE (sym
);
323 /* Lookup a union type named "union NAME",
324 visible in lexical block BLOCK. */
327 lookup_union (name
, block
)
331 register struct symbol
*sym
332 = lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0, (struct symtab
**)NULL
);
335 error ("No union type named %s.", name
);
336 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_UNION
)
337 error ("This context has class, struct or enum %s, not a union.", name
);
338 return SYMBOL_TYPE (sym
);
341 /* Lookup an enum type named "enum NAME",
342 visible in lexical block BLOCK. */
345 lookup_enum (name
, block
)
349 register struct symbol
*sym
350 = lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0, (struct symtab
**)NULL
);
352 error ("No enum type named %s.", name
);
353 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_ENUM
)
354 error ("This context has class, struct or union %s, not an enum.", name
);
355 return SYMBOL_TYPE (sym
);
358 /* Given a type TYPE, lookup the type of the component of type named
360 If NOERR is nonzero, return zero if NAME is not suitably defined. */
363 lookup_struct_elt_type (type
, name
, noerr
)
370 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
371 && TYPE_CODE (type
) != TYPE_CODE_UNION
)
373 target_terminal_ours ();
375 fprintf (stderr
, "Type ");
376 type_print (type
, "", stderr
, -1);
377 error (" is not a structure or union type.");
380 check_stub_type (type
);
382 for (i
= TYPE_NFIELDS (type
) - 1; i
>= TYPE_N_BASECLASSES (type
); i
--)
384 char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
386 if (t_field_name
&& !strcmp (t_field_name
, name
))
387 return TYPE_FIELD_TYPE (type
, i
);
389 /* OK, it's not in this class. Recursively check the baseclasses. */
390 for (i
= TYPE_N_BASECLASSES (type
) - 1; i
>= 0; i
--)
392 struct type
*t
= lookup_struct_elt_type (TYPE_BASECLASS (type
, i
),
401 target_terminal_ours ();
403 fprintf (stderr
, "Type ");
404 type_print (type
, "", stderr
, -1);
405 fprintf (stderr
, " has no component named ");
406 fputs_filtered (name
, stderr
);
408 return (struct type
*)-1; /* For lint */
411 /* Given a type TYPE, return a type of pointers to that type.
412 May need to construct such a type if this is the first use.
414 C++: use TYPE_MAIN_VARIANT and TYPE_CHAIN to keep pointer
415 to member types under control. */
418 lookup_pointer_type (type
)
421 register struct type
*ptype
= TYPE_POINTER_TYPE (type
);
422 if (ptype
) return TYPE_MAIN_VARIANT (ptype
);
424 /* This is the first time anyone wanted a pointer to a TYPE. */
425 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
426 ptype
= (struct type
*) xmalloc (sizeof (struct type
));
428 ptype
= (struct type
*) obstack_alloc (symbol_obstack
,
429 sizeof (struct type
));
431 bzero (ptype
, sizeof (struct type
));
432 TYPE_MAIN_VARIANT (ptype
) = ptype
;
433 TYPE_TARGET_TYPE (ptype
) = type
;
434 TYPE_POINTER_TYPE (type
) = ptype
;
435 /* New type is permanent if type pointed to is permanent. */
436 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
437 TYPE_FLAGS (ptype
) |= TYPE_FLAG_PERM
;
438 /* We assume the machine has only one representation for pointers! */
439 TYPE_LENGTH (ptype
) = sizeof (char *);
440 TYPE_CODE (ptype
) = TYPE_CODE_PTR
;
445 lookup_reference_type (type
)
448 register struct type
*rtype
= TYPE_REFERENCE_TYPE (type
);
449 if (rtype
) return TYPE_MAIN_VARIANT (rtype
);
451 /* This is the first time anyone wanted a pointer to a TYPE. */
452 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
453 rtype
= (struct type
*) xmalloc (sizeof (struct type
));
455 rtype
= (struct type
*) obstack_alloc (symbol_obstack
,
456 sizeof (struct type
));
458 bzero (rtype
, sizeof (struct type
));
459 TYPE_MAIN_VARIANT (rtype
) = rtype
;
460 TYPE_TARGET_TYPE (rtype
) = type
;
461 TYPE_REFERENCE_TYPE (type
) = rtype
;
462 /* New type is permanent if type pointed to is permanent. */
463 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
464 TYPE_FLAGS (rtype
) |= TYPE_FLAG_PERM
;
465 /* We assume the machine has only one representation for pointers! */
466 TYPE_LENGTH (rtype
) = sizeof (char *);
467 TYPE_CODE (rtype
) = TYPE_CODE_REF
;
472 /* Implement direct support for MEMBER_TYPE in GNU C++.
473 May need to construct such a type if this is the first use.
474 The TYPE is the type of the member. The DOMAIN is the type
475 of the aggregate that the member belongs to. */
478 lookup_member_type (type
, domain
)
479 struct type
*type
, *domain
;
481 register struct type
*mtype
= TYPE_MAIN_VARIANT (type
);
482 struct type
*main_type
;
487 if (TYPE_DOMAIN_TYPE (mtype
) == domain
)
489 mtype
= TYPE_NEXT_VARIANT (mtype
);
492 /* This is the first time anyone wanted this member type. */
493 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
494 mtype
= (struct type
*) xmalloc (sizeof (struct type
));
496 mtype
= (struct type
*) obstack_alloc (symbol_obstack
,
497 sizeof (struct type
));
499 bzero (mtype
, sizeof (struct type
));
504 TYPE_NEXT_VARIANT (mtype
) = TYPE_NEXT_VARIANT (main_type
);
505 TYPE_NEXT_VARIANT (main_type
) = mtype
;
507 TYPE_MAIN_VARIANT (mtype
) = main_type
;
508 TYPE_TARGET_TYPE (mtype
) = type
;
509 TYPE_DOMAIN_TYPE (mtype
) = domain
;
510 /* New type is permanent if type pointed to is permanent. */
511 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
512 TYPE_FLAGS (mtype
) |= TYPE_FLAG_PERM
;
514 /* In practice, this is never used. */
515 TYPE_LENGTH (mtype
) = 1;
516 TYPE_CODE (mtype
) = TYPE_CODE_MEMBER
;
519 /* Now splice in the new member pointer type. */
522 /* This type was not "smashed". */
523 TYPE_CHAIN (mtype
) = TYPE_CHAIN (main_type
);
524 TYPE_CHAIN (main_type
) = mtype
;
531 /* Allocate a stub method whose return type is
532 TYPE. We will fill in arguments later. This always
533 returns a fresh type. If we unify this type with
534 an existing type later, the storage allocated
535 here can be freed. */
537 allocate_stub_method (type
)
540 struct type
*mtype
= (struct type
*)xmalloc (sizeof (struct type
));
541 bzero (mtype
, sizeof (struct type
));
542 TYPE_MAIN_VARIANT (mtype
) = mtype
;
543 TYPE_TARGET_TYPE (mtype
) = type
;
544 TYPE_FLAGS (mtype
) = TYPE_FLAG_STUB
;
545 TYPE_CODE (mtype
) = TYPE_CODE_METHOD
;
546 TYPE_LENGTH (mtype
) = 1;
550 /* Lookup a method type returning type TYPE, belonging
551 to class DOMAIN, and taking a list of arguments ARGS.
552 If one is not found, allocate a new one. */
555 lookup_method_type (type
, domain
, args
)
556 struct type
*type
, *domain
, **args
;
558 register struct type
*mtype
= TYPE_MAIN_VARIANT (type
);
559 struct type
*main_type
;
564 if (TYPE_DOMAIN_TYPE (mtype
) == domain
)
566 struct type
**t1
= args
;
567 struct type
**t2
= TYPE_ARG_TYPES (mtype
);
571 for (i
= 0; t1
[i
] != 0 && t1
[i
]->code
!= TYPE_CODE_VOID
; i
++)
578 mtype
= TYPE_NEXT_VARIANT (mtype
);
581 /* This is the first time anyone wanted this member type. */
582 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
583 mtype
= (struct type
*) xmalloc (sizeof (struct type
));
585 mtype
= (struct type
*) obstack_alloc (symbol_obstack
,
586 sizeof (struct type
));
588 bzero (mtype
, sizeof (struct type
));
593 TYPE_NEXT_VARIANT (mtype
) = TYPE_NEXT_VARIANT (main_type
);
594 TYPE_NEXT_VARIANT (main_type
) = mtype
;
596 TYPE_MAIN_VARIANT (mtype
) = main_type
;
597 TYPE_TARGET_TYPE (mtype
) = type
;
598 TYPE_DOMAIN_TYPE (mtype
) = domain
;
599 TYPE_ARG_TYPES (mtype
) = args
;
600 /* New type is permanent if type pointed to is permanent. */
601 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
602 TYPE_FLAGS (mtype
) |= TYPE_FLAG_PERM
;
604 /* In practice, this is never used. */
605 TYPE_LENGTH (mtype
) = 1;
606 TYPE_CODE (mtype
) = TYPE_CODE_METHOD
;
609 /* Now splice in the new member pointer type. */
612 /* This type was not "smashed". */
613 TYPE_CHAIN (mtype
) = TYPE_CHAIN (main_type
);
614 TYPE_CHAIN (main_type
) = mtype
;
622 /* Given a type TYPE, return a type which has offset OFFSET,
623 via_virtual VIA_VIRTUAL, and via_public VIA_PUBLIC.
624 May need to construct such a type if none exists. */
626 lookup_basetype_type (type
, offset
, via_virtual
, via_public
)
629 int via_virtual
, via_public
;
631 register struct type
*btype
= TYPE_MAIN_VARIANT (type
);
632 struct type
*main_type
;
636 printf ("Internal error: type offset non-zero in lookup_basetype_type");
643 if (/* TYPE_OFFSET (btype) == offset
644 && */ TYPE_VIA_PUBLIC (btype
) == via_public
645 && TYPE_VIA_VIRTUAL (btype
) == via_virtual
)
647 btype
= TYPE_NEXT_VARIANT (btype
);
650 /* This is the first time anyone wanted this member type. */
651 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
652 btype
= (struct type
*) xmalloc (sizeof (struct type
));
654 btype
= (struct type
*) obstack_alloc (symbol_obstack
,
655 sizeof (struct type
));
660 bzero (btype
, sizeof (struct type
));
661 TYPE_MAIN_VARIANT (btype
) = main_type
;
665 bcopy (main_type
, btype
, sizeof (struct type
));
666 TYPE_NEXT_VARIANT (main_type
) = btype
;
668 /* TYPE_OFFSET (btype) = offset; */
670 TYPE_FLAGS (btype
) |= TYPE_FLAG_VIA_PUBLIC
;
672 TYPE_FLAGS (btype
) |= TYPE_FLAG_VIA_VIRTUAL
;
673 /* New type is permanent if type pointed to is permanent. */
674 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
675 TYPE_FLAGS (btype
) |= TYPE_FLAG_PERM
;
677 /* In practice, this is never used. */
678 TYPE_LENGTH (btype
) = 1;
679 TYPE_CODE (btype
) = TYPE_CODE_STRUCT
;
685 /* Given a type TYPE, return a type of functions that return that type.
686 May need to construct such a type if this is the first use. */
689 lookup_function_type (type
)
692 register struct type
*ptype
= TYPE_FUNCTION_TYPE (type
);
693 if (ptype
) return ptype
;
695 /* This is the first time anyone wanted a function returning a TYPE. */
696 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
697 ptype
= (struct type
*) xmalloc (sizeof (struct type
));
699 ptype
= (struct type
*) obstack_alloc (symbol_obstack
,
700 sizeof (struct type
));
702 bzero (ptype
, sizeof (struct type
));
703 TYPE_TARGET_TYPE (ptype
) = type
;
704 TYPE_FUNCTION_TYPE (type
) = ptype
;
705 /* New type is permanent if type returned is permanent. */
706 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
707 TYPE_FLAGS (ptype
) |= TYPE_FLAG_PERM
;
708 TYPE_LENGTH (ptype
) = 1;
709 TYPE_CODE (ptype
) = TYPE_CODE_FUNC
;
710 TYPE_NFIELDS (ptype
) = 0;
714 /* Create an array type. Elements will be of type TYPE, and there will
717 Eventually this should be extended to take two more arguments which
718 specify the bounds of the array and the type of the index.
719 It should also be changed to be a "lookup" function, with the
720 appropriate data structures added to the type field.
721 Then read array type should call here. */
724 create_array_type (element_type
, number
)
725 struct type
*element_type
;
728 struct type
*result_type
= (struct type
*)
729 obstack_alloc (symbol_obstack
, sizeof (struct type
));
730 struct type
*range_type
;
732 bzero (result_type
, sizeof (struct type
));
734 TYPE_CODE (result_type
) = TYPE_CODE_ARRAY
;
735 TYPE_TARGET_TYPE (result_type
) = element_type
;
736 TYPE_LENGTH (result_type
) = number
* TYPE_LENGTH (element_type
);
737 TYPE_NFIELDS (result_type
) = 1;
738 TYPE_FIELDS (result_type
) =
739 (struct field
*) obstack_alloc (symbol_obstack
, sizeof (struct field
));
742 /* Create range type. */
743 range_type
= (struct type
*) obstack_alloc (symbol_obstack
,
744 sizeof (struct type
));
745 TYPE_CODE (range_type
) = TYPE_CODE_RANGE
;
746 TYPE_TARGET_TYPE (range_type
) = builtin_type_int
; /* FIXME */
748 /* This should never be needed. */
749 TYPE_LENGTH (range_type
) = sizeof (int);
751 TYPE_NFIELDS (range_type
) = 2;
752 TYPE_FIELDS (range_type
) =
753 (struct field
*) obstack_alloc (symbol_obstack
,
754 2 * sizeof (struct field
));
755 TYPE_FIELD_BITPOS (range_type
, 0) = 0; /* FIXME */
756 TYPE_FIELD_BITPOS (range_type
, 1) = number
-1; /* FIXME */
757 TYPE_FIELD_TYPE (range_type
, 0) = builtin_type_int
; /* FIXME */
758 TYPE_FIELD_TYPE (range_type
, 1) = builtin_type_int
; /* FIXME */
760 TYPE_FIELD_TYPE(result_type
,0)=range_type
;
761 TYPE_VPTR_FIELDNO (result_type
) = -1;
767 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE. */
770 smash_to_member_type (type
, domain
, to_type
)
771 struct type
*type
, *domain
, *to_type
;
773 bzero (type
, sizeof (struct type
));
774 TYPE_TARGET_TYPE (type
) = to_type
;
775 TYPE_DOMAIN_TYPE (type
) = domain
;
777 /* In practice, this is never needed. */
778 TYPE_LENGTH (type
) = 1;
779 TYPE_CODE (type
) = TYPE_CODE_MEMBER
;
781 TYPE_MAIN_VARIANT (type
) = lookup_member_type (domain
, to_type
);
784 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE. */
787 smash_to_method_type (type
, domain
, to_type
, args
)
788 struct type
*type
, *domain
, *to_type
, **args
;
790 bzero (type
, sizeof (struct type
));
791 TYPE_TARGET_TYPE (type
) = to_type
;
792 TYPE_DOMAIN_TYPE (type
) = domain
;
793 TYPE_ARG_TYPES (type
) = args
;
795 /* In practice, this is never needed. */
796 TYPE_LENGTH (type
) = 1;
797 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
799 TYPE_MAIN_VARIANT (type
) = lookup_method_type (domain
, to_type
, args
);
802 /* Find which partial symtab on the partial_symtab_list contains
803 PC. Return 0 if none. */
805 struct partial_symtab
*
807 register CORE_ADDR pc
;
809 register struct partial_symtab
*ps
;
811 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
812 if (pc
>= ps
->textlow
&& pc
< ps
->texthigh
)
818 /* Find which partial symbol within a psymtab contains PC. Return 0
819 if none. Check all psymtabs if PSYMTAB is 0. */
820 struct partial_symbol
*
821 find_pc_psymbol (psymtab
, pc
)
822 struct partial_symtab
*psymtab
;
825 struct partial_symbol
*best
, *p
;
829 psymtab
= find_pc_psymtab (pc
);
833 best_pc
= psymtab
->textlow
- 1;
835 for (p
= static_psymbols
.list
+ psymtab
->statics_offset
;
836 (p
- (static_psymbols
.list
+ psymtab
->statics_offset
)
837 < psymtab
->n_static_syms
);
839 if (SYMBOL_NAMESPACE (p
) == VAR_NAMESPACE
840 && SYMBOL_CLASS (p
) == LOC_BLOCK
841 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
842 && SYMBOL_VALUE_ADDRESS (p
) > best_pc
)
844 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
847 if (best_pc
== psymtab
->textlow
- 1)
853 /* Find the definition for a specified symbol name NAME
854 in namespace NAMESPACE, visible from lexical block BLOCK.
855 Returns the struct symbol pointer, or zero if no symbol is found.
856 If SYMTAB is non-NULL, store the symbol table in which the
857 symbol was found there, or NULL if not found.
858 C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
859 NAME is a field of the current implied argument `this'. If so set
860 *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
861 BLOCK_FOUND is set to the block in which NAME is found (in the case of
862 a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
865 lookup_symbol (name
, block
, namespace, is_a_field_of_this
, symtab
)
867 register struct block
*block
;
868 enum namespace namespace;
869 int *is_a_field_of_this
;
870 struct symtab
**symtab
;
872 register struct symbol
*sym
;
873 register struct symtab
*s
;
874 register struct partial_symtab
*ps
;
875 struct blockvector
*bv
;
877 /* Search specified block and its superiors. */
881 sym
= lookup_block_symbol (block
, name
, namespace);
887 /* Search the list of symtabs for one which contains the
888 address of the start of this block. */
890 for (s
= symtab_list
; s
; s
= s
->next
)
892 bv
= BLOCKVECTOR (s
);
893 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
894 if (BLOCK_START (b
) <= BLOCK_START (block
)
895 && BLOCK_END (b
) > BLOCK_START (block
))
903 block
= BLOCK_SUPERBLOCK (block
);
906 /* But that doesn't do any demangling for the STATIC_BLOCK.
907 I'm not sure whether demangling is needed in the case of
908 nested function in inner blocks; if so this needs to be changed.
910 Don't need to mess with the psymtabs; if we have a block,
911 that file is read in. If we don't, then we deal later with
912 all the psymtab stuff that needs checking. */
913 if (namespace == VAR_NAMESPACE
&& block
!= NULL
)
916 /* Find the right symtab. */
917 for (s
= symtab_list
; s
; s
= s
->next
)
919 bv
= BLOCKVECTOR (s
);
920 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
921 if (BLOCK_START (b
) <= BLOCK_START (block
)
922 && BLOCK_END (b
) > BLOCK_START (block
))
924 sym
= lookup_demangled_block_symbol (b
, name
);
937 /* C++: If requested to do so by the caller,
938 check to see if NAME is a field of `this'. */
939 if (is_a_field_of_this
)
941 struct value
*v
= value_of_this (0);
943 *is_a_field_of_this
= 0;
944 if (v
&& check_field (v
, name
))
946 *is_a_field_of_this
= 1;
953 /* Now search all global blocks. Do the symtab's first, then
954 check the psymtab's */
956 for (s
= symtab_list
; s
; s
= s
->next
)
958 bv
= BLOCKVECTOR (s
);
959 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
960 sym
= lookup_block_symbol (block
, name
, namespace);
970 /* Check for the possibility of the symbol being a global function
971 that is stored on the misc function vector. Eventually, all
972 global symbols might be resolved in this way. */
974 if (namespace == VAR_NAMESPACE
)
976 int ind
= lookup_misc_func (name
);
978 /* Look for a mangled C++ name for NAME. */
981 int name_len
= strlen (name
);
983 for (ind
= misc_function_count
; --ind
>= 0; )
984 /* Assume orginal name is prefix of mangled name. */
985 if (!strncmp (misc_function_vector
[ind
].name
, name
, name_len
))
988 cplus_demangle(misc_function_vector
[ind
].name
, -1);
989 if (demangled
!= NULL
)
991 int cond
= strcmp (demangled
, name
);
997 /* Loop terminates on no match with ind == -1. */
1002 s
= find_pc_symtab (misc_function_vector
[ind
].address
);
1003 /* If S is zero, there are no debug symbols for this file.
1004 Skip this stuff and check for matching static symbols below. */
1007 bv
= BLOCKVECTOR (s
);
1008 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1009 sym
= lookup_block_symbol (block
, misc_function_vector
[ind
].name
,
1011 /* sym == 0 if symbol was found in the misc_function_vector
1012 but not in the symtab.
1013 Return 0 to use the misc_function definition of "foo_".
1015 This happens for Fortran "foo_" symbols,
1016 which are "foo" in the symtab.
1018 This can also happen if "asm" is used to make a
1019 regular symbol but not a debugging symbol, e.g.
1020 asm(".globl _main");
1031 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
1032 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 1, namespace))
1034 s
= PSYMTAB_TO_SYMTAB(ps
);
1035 bv
= BLOCKVECTOR (s
);
1036 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1037 sym
= lookup_block_symbol (block
, name
, namespace);
1039 fatal ("Internal: global symbol found in psymtab but not in symtab");
1045 /* Now search all per-file blocks.
1046 Not strictly correct, but more useful than an error.
1047 Do the symtabs first, then check the psymtabs */
1049 for (s
= symtab_list
; s
; s
= s
->next
)
1051 bv
= BLOCKVECTOR (s
);
1052 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1053 sym
= lookup_block_symbol (block
, name
, namespace);
1056 block_found
= block
;
1063 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
1064 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 0, namespace))
1066 s
= PSYMTAB_TO_SYMTAB(ps
);
1067 bv
= BLOCKVECTOR (s
);
1068 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1069 sym
= lookup_block_symbol (block
, name
, namespace);
1071 fatal ("Internal: static symbol found in psymtab but not in symtab");
1077 /* Now search all per-file blocks for static mangled symbols.
1078 Do the symtabs first, then check the psymtabs. */
1080 if (namespace == VAR_NAMESPACE
)
1082 for (s
= symtab_list
; s
; s
= s
->next
)
1084 bv
= BLOCKVECTOR (s
);
1085 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1086 sym
= lookup_demangled_block_symbol (block
, name
);
1089 block_found
= block
;
1096 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
1097 if (!ps
->readin
&& lookup_demangled_partial_symbol (ps
, name
))
1099 s
= PSYMTAB_TO_SYMTAB(ps
);
1100 bv
= BLOCKVECTOR (s
);
1101 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1102 sym
= lookup_demangled_block_symbol (block
, name
);
1104 fatal ("Internal: static symbol found in psymtab but not in symtab");
1116 /* Look for a static demangled symbol in block BLOCK. */
1118 static struct symbol
*
1119 lookup_demangled_block_symbol (block
, name
)
1120 register struct block
*block
;
1123 register int bot
, top
, inc
;
1124 register struct symbol
*sym
;
1127 top
= BLOCK_NSYMS (block
);
1132 sym
= BLOCK_SYM (block
, bot
);
1133 if (SYMBOL_NAME (sym
)[0] == inc
1134 && SYMBOL_NAMESPACE (sym
) == VAR_NAMESPACE
)
1136 char *demangled
= cplus_demangle(SYMBOL_NAME (sym
), -1);
1137 if (demangled
!= NULL
)
1139 int cond
= strcmp (demangled
, name
);
1151 /* Look, in partial_symtab PST, for static mangled symbol NAME. */
1153 static struct partial_symbol
*
1154 lookup_demangled_partial_symbol (pst
, name
)
1155 struct partial_symtab
*pst
;
1158 struct partial_symbol
*start
, *psym
;
1159 int length
= pst
->n_static_syms
;
1160 register int inc
= name
[0];
1163 return (struct partial_symbol
*) 0;
1165 start
= static_psymbols
.list
+ pst
->statics_offset
;
1166 for (psym
= start
; psym
< start
+ length
; psym
++)
1168 if (SYMBOL_NAME (psym
)[0] == inc
1169 && SYMBOL_NAMESPACE (psym
) == VAR_NAMESPACE
)
1171 char *demangled
= cplus_demangle(SYMBOL_NAME (psym
), -1);
1172 if (demangled
!= NULL
)
1174 int cond
= strcmp (demangled
, name
);
1182 return (struct partial_symbol
*) 0;
1185 /* Look, in partial_symtab PST, for symbol NAME. Check the global
1186 symbols if GLOBAL, the static symbols if not */
1188 static struct partial_symbol
*
1189 lookup_partial_symbol (pst
, name
, global
, namespace)
1190 struct partial_symtab
*pst
;
1193 enum namespace namespace;
1195 struct partial_symbol
*start
, *psym
;
1196 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
1199 return (struct partial_symbol
*) 0;
1202 global_psymbols
.list
+ pst
->globals_offset
:
1203 static_psymbols
.list
+ pst
->statics_offset
);
1205 if (global
) /* This means we can use a binary */
1208 struct partial_symbol
*top
, *bottom
, *center
;
1210 /* Binary search. This search is guaranteed to end with center
1211 pointing at the earliest partial symbol with the correct
1212 name. At that point *all* partial symbols with that name
1213 will be checked against the correct namespace. */
1215 top
= start
+ length
- 1;
1216 while (top
> bottom
)
1218 center
= bottom
+ (top
- bottom
) / 2;
1220 assert (center
< top
);
1222 if (strcmp (SYMBOL_NAME (center
), name
) >= 0)
1225 bottom
= center
+ 1;
1227 assert (top
== bottom
);
1229 while (!strcmp (SYMBOL_NAME (top
), name
))
1231 if (SYMBOL_NAMESPACE (top
) == namespace)
1238 /* Can't use a binary search */
1239 for (psym
= start
; psym
< start
+ length
; psym
++)
1240 if (namespace == SYMBOL_NAMESPACE (psym
)
1241 && !strcmp (name
, SYMBOL_NAME (psym
)))
1245 return (struct partial_symbol
*) 0;
1248 /* Look for a symbol in block BLOCK. */
1251 lookup_block_symbol (block
, name
, namespace)
1252 register struct block
*block
;
1254 enum namespace namespace;
1256 register int bot
, top
, inc
;
1257 register struct symbol
*sym
, *parameter_sym
;
1259 top
= BLOCK_NSYMS (block
);
1262 /* If the blocks's symbols were sorted, start with a binary search. */
1264 if (BLOCK_SHOULD_SORT (block
))
1266 /* First, advance BOT to not far before
1267 the first symbol whose name is NAME. */
1271 inc
= (top
- bot
+ 1);
1272 /* No need to keep binary searching for the last few bits worth. */
1275 inc
= (inc
>> 1) + bot
;
1276 sym
= BLOCK_SYM (block
, inc
);
1277 if (SYMBOL_NAME (sym
)[0] < name
[0])
1279 else if (SYMBOL_NAME (sym
)[0] > name
[0])
1281 else if (strcmp (SYMBOL_NAME (sym
), name
) < 0)
1287 /* Now scan forward until we run out of symbols,
1288 find one whose name is greater than NAME,
1289 or find one we want.
1290 If there is more than one symbol with the right name and namespace,
1291 we return the first one. dbxread.c is careful to make sure
1292 that if one is a register then it comes first. */
1294 top
= BLOCK_NSYMS (block
);
1297 sym
= BLOCK_SYM (block
, bot
);
1298 inc
= SYMBOL_NAME (sym
)[0] - name
[0];
1300 inc
= strcmp (SYMBOL_NAME (sym
), name
);
1301 if (inc
== 0 && SYMBOL_NAMESPACE (sym
) == namespace)
1310 /* Here if block isn't sorted.
1311 This loop is equivalent to the loop above,
1312 but hacked greatly for speed.
1314 Note that parameter symbols do not always show up last in the
1315 list; this loop makes sure to take anything else other than
1316 parameter symbols first; it only uses parameter symbols as a
1317 last resort. Note that this only takes up extra computation
1320 parameter_sym
= (struct symbol
*) 0;
1321 top
= BLOCK_NSYMS (block
);
1325 sym
= BLOCK_SYM (block
, bot
);
1326 if (SYMBOL_NAME (sym
)[0] == inc
1327 && !strcmp (SYMBOL_NAME (sym
), name
)
1328 && SYMBOL_NAMESPACE (sym
) == namespace)
1330 if (SYMBOL_CLASS (sym
) == LOC_ARG
1331 || SYMBOL_CLASS (sym
) == LOC_LOCAL_ARG
1332 || SYMBOL_CLASS (sym
) == LOC_REF_ARG
1333 || SYMBOL_CLASS (sym
) == LOC_REGPARM
)
1334 parameter_sym
= sym
;
1340 return parameter_sym
; /* Will be 0 if not found. */
1343 /* Return the symbol for the function which contains a specified
1344 lexical block, described by a struct block BL. */
1350 while (BLOCK_FUNCTION (bl
) == 0 && BLOCK_SUPERBLOCK (bl
) != 0)
1351 bl
= BLOCK_SUPERBLOCK (bl
);
1353 return BLOCK_FUNCTION (bl
);
1356 /* Subroutine of find_pc_line */
1360 register CORE_ADDR pc
;
1362 register struct block
*b
;
1363 struct blockvector
*bv
;
1364 register struct symtab
*s
;
1365 register struct partial_symtab
*ps
;
1367 /* Search all symtabs for one whose file contains our pc */
1369 for (s
= symtab_list
; s
; s
= s
->next
)
1371 bv
= BLOCKVECTOR (s
);
1372 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1373 if (BLOCK_START (b
) <= pc
1374 && BLOCK_END (b
) > pc
)
1380 ps
= find_pc_psymtab (pc
);
1381 if (ps
&& ps
->readin
)
1383 "(Internal error: pc in read in psymtab, but not in symtab.)\n");
1386 s
= PSYMTAB_TO_SYMTAB (ps
);
1392 /* Find the source file and line number for a given PC value.
1393 Return a structure containing a symtab pointer, a line number,
1394 and a pc range for the entire source line.
1395 The value's .pc field is NOT the specified pc.
1396 NOTCURRENT nonzero means, if specified pc is on a line boundary,
1397 use the line that ends there. Otherwise, in that case, the line
1398 that begins there is used. */
1400 struct symtab_and_line
1401 find_pc_line (pc
, notcurrent
)
1406 register struct linetable
*l
;
1409 register struct linetable_entry
*item
;
1410 struct symtab_and_line val
;
1411 struct blockvector
*bv
;
1413 /* Info on best line seen so far, and where it starts, and its file. */
1416 CORE_ADDR best_pc
= 0;
1417 CORE_ADDR best_end
= 0;
1418 struct symtab
*best_symtab
= 0;
1420 /* Store here the first line number
1421 of a file which contains the line at the smallest pc after PC.
1422 If we don't find a line whose range contains PC,
1423 we will use a line one less than this,
1424 with a range from the start of that file to the first line's pc. */
1426 CORE_ADDR alt_pc
= 0;
1427 struct symtab
*alt_symtab
= 0;
1429 /* Info on best line seen in this file. */
1434 /* Info on first line of this file. */
1439 /* If this pc is not from the current frame,
1440 it is the address of the end of a call instruction.
1441 Quite likely that is the start of the following statement.
1442 But what we want is the statement containing the instruction.
1443 Fudge the pc to make sure we get that. */
1445 if (notcurrent
) pc
-= 1;
1447 s
= find_pc_symtab (pc
);
1457 bv
= BLOCKVECTOR (s
);
1459 /* Look at all the symtabs that share this blockvector.
1460 They all have the same apriori range, that we found was right;
1461 but they have different line tables. */
1463 for (; s
&& BLOCKVECTOR (s
) == bv
; s
= s
->next
)
1465 /* Find the best line in this symtab. */
1470 for (i
= 0; i
< len
; i
++)
1472 item
= &(l
->item
[i
]);
1476 first_line
= item
->line
;
1477 first_pc
= item
->pc
;
1479 /* Return the last line that did not start after PC. */
1482 prev_line
= item
->line
;
1489 /* Is this file's best line closer than the best in the other files?
1490 If so, record this file, and its best line, as best so far. */
1491 if (prev_line
>= 0 && prev_pc
> best_pc
)
1494 best_line
= prev_line
;
1497 best_end
= item
->pc
;
1501 /* Is this file's first line closer than the first lines of other files?
1502 If so, record this file, and its first line, as best alternate. */
1503 if (first_line
>= 0 && first_pc
> pc
1504 && (alt_pc
== 0 || first_pc
< alt_pc
))
1507 alt_line
= first_line
;
1511 if (best_symtab
== 0)
1513 val
.symtab
= alt_symtab
;
1514 val
.line
= alt_line
- 1;
1515 val
.pc
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
1520 val
.symtab
= best_symtab
;
1521 val
.line
= best_line
;
1523 val
.end
= (best_end
? best_end
1525 : BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
))));
1530 /* Find the PC value for a given source file and line number.
1531 Returns zero for invalid line number.
1532 The source file is specified with a struct symtab. */
1535 find_line_pc (symtab
, line
)
1536 struct symtab
*symtab
;
1539 register struct linetable
*l
;
1545 l
= LINETABLE (symtab
);
1546 ind
= find_line_common(l
, line
, &dummy
);
1547 return (ind
>= 0) ? l
->item
[ind
].pc
: 0;
1550 /* Find the range of pc values in a line.
1551 Store the starting pc of the line into *STARTPTR
1552 and the ending pc (start of next line) into *ENDPTR.
1553 Returns 1 to indicate success.
1554 Returns 0 if could not find the specified line. */
1557 find_line_pc_range (symtab
, thisline
, startptr
, endptr
)
1558 struct symtab
*symtab
;
1560 CORE_ADDR
*startptr
, *endptr
;
1562 register struct linetable
*l
;
1564 int exact_match
; /* did we get an exact linenumber match */
1569 l
= LINETABLE (symtab
);
1570 ind
= find_line_common (l
, thisline
, &exact_match
);
1573 *startptr
= l
->item
[ind
].pc
;
1574 /* If we have not seen an entry for the specified line,
1575 assume that means the specified line has zero bytes. */
1576 if (!exact_match
|| ind
== l
->nitems
-1)
1577 *endptr
= *startptr
;
1579 /* Perhaps the following entry is for the following line.
1580 It's worth a try. */
1581 if (ind
+1 < l
->nitems
1582 && l
->item
[ind
+1].line
== thisline
+ 1)
1583 *endptr
= l
->item
[ind
+1].pc
;
1585 *endptr
= find_line_pc (symtab
, thisline
+1);
1592 /* Given a line table and a line number, return the index into the line
1593 table for the pc of the nearest line whose number is >= the specified one.
1594 Return -1 if none is found. The value is >= 0 if it is an index.
1596 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
1599 find_line_common (l
, lineno
, exact_match
)
1600 register struct linetable
*l
;
1601 register int lineno
;
1607 /* BEST is the smallest linenumber > LINENO so far seen,
1608 or 0 if none has been seen so far.
1609 BEST_INDEX identifies the item for it. */
1611 int best_index
= -1;
1618 for (i
= 0; i
< len
; i
++)
1620 register struct linetable_entry
*item
= &(l
->item
[i
]);
1622 if (item
->line
== lineno
)
1628 if (item
->line
> lineno
&& (best
== 0 || item
->line
< best
))
1635 /* If we got here, we didn't get an exact match. */
1642 find_pc_line_pc_range (pc
, startptr
, endptr
)
1644 CORE_ADDR
*startptr
, *endptr
;
1646 struct symtab_and_line sal
;
1647 sal
= find_pc_line (pc
, 0);
1650 return sal
.symtab
!= 0;
1653 /* If P is of the form "operator[ \t]+..." where `...' is
1654 some legitimate operator text, return a pointer to the
1655 beginning of the substring of the operator text.
1656 Otherwise, return "". */
1658 operator_chars (p
, end
)
1663 if (strncmp (p
, "operator", 8))
1667 /* Don't get faked out by `operator' being part of a longer
1669 if ((*p
>= 'A' && *p
<= 'Z') || (*p
>= 'a' && *p
<= 'z')
1670 || *p
== '_' || *p
== '$' || *p
== '\0')
1673 /* Allow some whitespace between `operator' and the operator symbol. */
1674 while (*p
== ' ' || *p
== '\t')
1696 if (p
[1] == '=' || p
[1] == p
[0])
1707 error ("`operator ()' must be specified without whitespace in `()'");
1712 error ("`operator ?:' must be specified without whitespace in `?:'");
1717 error ("`operator []' must be specified without whitespace in `[]'");
1721 error ("`operator %s' not supported", p
);
1728 /* Recursive helper function for decode_line_1.
1729 * Look for methods named NAME in type T.
1730 * Return number of matches.
1731 * Put matches in PHYSNAMES and SYM_ARR (which better be big enough!).
1732 * These allocations seem to define "big enough":
1733 * sym_arr = (struct symbol **) alloca(TYPE_NFN_FIELDS_TOTAL (t) * sizeof(struct symbol*));
1734 * physnames = (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t) * sizeof(char*));
1738 find_methods(t
, name
, physnames
, sym_arr
)
1742 struct symbol
**sym_arr
;
1746 struct symbol
*sym_class
;
1747 char *class_name
= type_name_no_tag (t
);
1748 /* Ignore this class if it doesn't have a name.
1749 This prevents core dumps, but is just a workaround
1750 because we might not find the function in
1751 certain cases, such as
1752 struct D {virtual int f();}
1753 struct C : D {virtual int g();}
1754 (in this case g++ 1.35.1- does not put out a name
1755 for D as such, it defines type 19 (for example) in
1756 the same stab as C, and then does a
1757 .stabs "D:T19" and a .stabs "D:t19".
1759 "break C::f" should not be looking for field f in
1761 but just for the field f in the baseclasses of C
1762 (no matter what their names).
1764 However, I don't know how to replace the code below
1765 that depends on knowing the name of D. */
1767 && (sym_class
= lookup_symbol (class_name
,
1768 (struct block
*)NULL
,
1771 (struct symtab
**)NULL
)))
1774 t
= SYMBOL_TYPE (sym_class
);
1775 for (method_counter
= TYPE_NFN_FIELDS (t
) - 1;
1776 method_counter
>= 0;
1780 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, method_counter
);
1782 char *method_name
= TYPE_FN_FIELDLIST_NAME (t
, method_counter
);
1783 if (!strcmp (name
, method_name
))
1784 /* Find all the fields with that name. */
1785 for (field_counter
= TYPE_FN_FIELDLIST_LENGTH (t
, method_counter
) - 1;
1790 if (TYPE_FLAGS (TYPE_FN_FIELD_TYPE (f
, field_counter
)) & TYPE_FLAG_STUB
)
1791 check_stub_method (t
, method_counter
, field_counter
);
1792 phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, field_counter
);
1793 physnames
[i1
] = (char*) alloca (strlen (phys_name
) + 1);
1794 strcpy (physnames
[i1
], phys_name
);
1795 sym_arr
[i1
] = lookup_symbol (phys_name
,
1796 SYMBOL_BLOCK_VALUE (sym_class
),
1799 (struct symtab
**) NULL
);
1800 if (sym_arr
[i1
]) i1
++;
1804 /* Only search baseclasses if there is no match yet,
1805 * since names in derived classes override those in baseclasses.
1809 for (ibase
= 0; ibase
< TYPE_N_BASECLASSES (t
); ibase
++)
1810 i1
+= find_methods(TYPE_BASECLASS(t
, ibase
), name
,
1811 physnames
+ i1
, sym_arr
+ i1
);
1815 /* Parse a string that specifies a line number.
1816 Pass the address of a char * variable; that variable will be
1817 advanced over the characters actually parsed.
1821 LINENUM -- that line number in current file. PC returned is 0.
1822 FILE:LINENUM -- that line in that file. PC returned is 0.
1823 FUNCTION -- line number of openbrace of that function.
1824 PC returned is the start of the function.
1825 VARIABLE -- line number of definition of that variable.
1827 FILE:FUNCTION -- likewise, but prefer functions in that file.
1828 *EXPR -- line in which address EXPR appears.
1830 FUNCTION may be an undebuggable function found in misc_function_vector.
1832 If the argument FUNFIRSTLINE is nonzero, we want the first line
1833 of real code inside a function when a function is specified.
1835 DEFAULT_SYMTAB specifies the file to use if none is specified.
1836 It defaults to current_source_symtab.
1837 DEFAULT_LINE specifies the line number to use for relative
1838 line numbers (that start with signs). Defaults to current_source_line.
1840 Note that it is possible to return zero for the symtab
1841 if no file is validly specified. Callers must check that.
1842 Also, the line number returned may be invalid. */
1844 struct symtabs_and_lines
1845 decode_line_1 (argptr
, funfirstline
, default_symtab
, default_line
)
1848 struct symtab
*default_symtab
;
1851 struct symtabs_and_lines
decode_line_2 ();
1852 struct symtabs_and_lines values
;
1853 struct symtab_and_line val
;
1854 register char *p
, *p1
;
1856 register struct symtab
*s
;
1858 register struct symbol
*sym
;
1859 /* The symtab that SYM was found in. */
1860 struct symtab
*sym_symtab
;
1862 register CORE_ADDR pc
;
1865 struct symbol
*sym_class
;
1867 struct symbol
**sym_arr
;
1871 /* Defaults have defaults. */
1873 if (default_symtab
== 0)
1875 default_symtab
= current_source_symtab
;
1876 default_line
= current_source_line
;
1879 /* See if arg is *PC */
1881 if (**argptr
== '*')
1884 pc
= parse_and_eval_address_1 (argptr
);
1885 values
.sals
= (struct symtab_and_line
*)
1886 xmalloc (sizeof (struct symtab_and_line
));
1888 values
.sals
[0] = find_pc_line (pc
, 0);
1889 values
.sals
[0].pc
= pc
;
1893 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
1897 for (p
= *argptr
; *p
; p
++)
1899 if (p
[0] == ':' || p
[0] == ' ' || p
[0] == '\t')
1902 while (p
[0] == ' ' || p
[0] == '\t') p
++;
1904 q
= operator_chars (*argptr
, &q1
);
1911 /* Extract the class name. */
1913 while (p
!= *argptr
&& p
[-1] == ' ') --p
;
1914 copy
= (char *) alloca (p
- *argptr
+ 1);
1915 bcopy (*argptr
, copy
, p
- *argptr
);
1916 copy
[p
- *argptr
] = 0;
1918 /* Discard the class name from the arg. */
1920 while (*p
== ' ' || *p
== '\t') p
++;
1923 sym_class
= lookup_symbol (copy
, 0, STRUCT_NAMESPACE
, 0,
1924 (struct symtab
**)NULL
);
1927 (TYPE_CODE (SYMBOL_TYPE (sym_class
)) == TYPE_CODE_STRUCT
1928 || TYPE_CODE (SYMBOL_TYPE (sym_class
)) == TYPE_CODE_UNION
))
1930 /* Arg token is not digits => try it as a function name
1931 Find the next token (everything up to end or next whitespace). */
1933 while (*p
&& *p
!= ' ' && *p
!= '\t' && *p
!= ',' && *p
!=':') p
++;
1934 q
= operator_chars (*argptr
, &q1
);
1936 copy
= (char *) alloca (p
- *argptr
+ 1 + (q1
- q
));
1941 copy
[2] = CPLUS_MARKER
;
1942 bcopy (q
, copy
+ 3, q1
- q
);
1943 copy
[3 + (q1
- q
)] = '\0';
1948 bcopy (*argptr
, copy
, p
- *argptr
);
1949 copy
[p
- *argptr
] = '\0';
1952 /* no line number may be specified */
1953 while (*p
== ' ' || *p
== '\t') p
++;
1957 i1
= 0; /* counter for the symbol array */
1958 t
= SYMBOL_TYPE (sym_class
);
1959 sym_arr
= (struct symbol
**) alloca(TYPE_NFN_FIELDS_TOTAL (t
) * sizeof(struct symbol
*));
1960 physnames
= (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t
) * sizeof(char*));
1962 if (destructor_name_p (copy
, t
))
1964 /* destructors are a special case. */
1965 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, 0);
1966 int len
= TYPE_FN_FIELDLIST_LENGTH (t
, 0) - 1;
1967 char *phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, len
);
1968 physnames
[i1
] = (char *)alloca (strlen (phys_name
) + 1);
1969 strcpy (physnames
[i1
], phys_name
);
1971 lookup_symbol (phys_name
, SYMBOL_BLOCK_VALUE (sym_class
),
1972 VAR_NAMESPACE
, 0, (struct symtab
**)NULL
);
1973 if (sym_arr
[i1
]) i1
++;
1976 i1
= find_methods (t
, copy
, physnames
, sym_arr
);
1979 /* There is exactly one field with that name. */
1982 if (sym
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1984 /* Arg is the name of a function */
1985 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) + FUNCTION_START_OFFSET
;
1988 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
1990 values
.sals
[0] = find_pc_line (pc
, 0);
1991 values
.sals
[0].pc
= (values
.sals
[0].end
&& values
.sals
[0].pc
!= pc
) ? values
.sals
[0].end
: pc
;
2001 /* There is more than one field with that name
2002 (overloaded). Ask the user which one to use. */
2003 return decode_line_2 (sym_arr
, i1
, funfirstline
);
2009 if (OPNAME_PREFIX_P (copy
))
2011 tmp
= (char *)alloca (strlen (copy
+3) + 9);
2012 strcpy (tmp
, "operator ");
2013 strcat (tmp
, copy
+3);
2017 error ("that class does not have any method named %s", tmp
);
2021 /* The quotes are important if copy is empty. */
2022 error("No class, struct, or union named \"%s\"", copy
);
2027 /* Extract the file name. */
2029 while (p
!= *argptr
&& p
[-1] == ' ') --p
;
2030 copy
= (char *) alloca (p
- *argptr
+ 1 + (q1
- q
));
2035 copy
[2] = CPLUS_MARKER
;
2036 bcopy (q
, copy
+ 3, q1
-q
);
2037 copy
[3 + (q1
-q
)] = 0;
2042 bcopy (*argptr
, copy
, p
- *argptr
);
2043 copy
[p
- *argptr
] = 0;
2046 /* Find that file's data. */
2047 s
= lookup_symtab (copy
);
2050 if (symtab_list
== 0 && partial_symtab_list
== 0)
2051 error (no_symtab_msg
);
2052 error ("No source file named %s.", copy
);
2055 /* Discard the file name from the arg. */
2057 while (*p
== ' ' || *p
== '\t') p
++;
2061 /* S is specified file's symtab, or 0 if no file specified.
2062 arg no longer contains the file name. */
2064 /* Check whether arg is all digits (and sign) */
2067 if (*p
== '-' || *p
== '+') p
++;
2068 while (*p
>= '0' && *p
<= '9')
2071 if (p
!= *argptr
&& (*p
== 0 || *p
== ' ' || *p
== '\t' || *p
== ','))
2073 /* We found a token consisting of all digits -- at least one digit. */
2074 enum sign
{none
, plus
, minus
} sign
= none
;
2076 /* This is where we need to make sure that we have good defaults.
2077 We must guarantee that this section of code is never executed
2078 when we are called with just a function name, since
2079 select_source_symtab calls us with such an argument */
2081 if (s
== 0 && default_symtab
== 0)
2083 select_source_symtab (0);
2084 default_symtab
= current_source_symtab
;
2085 default_line
= current_source_line
;
2088 if (**argptr
== '+')
2089 sign
= plus
, (*argptr
)++;
2090 else if (**argptr
== '-')
2091 sign
= minus
, (*argptr
)++;
2092 val
.line
= atoi (*argptr
);
2099 val
.line
= default_line
+ val
.line
;
2105 val
.line
= default_line
- val
.line
;
2110 break; /* No need to adjust val.line. */
2113 while (*p
== ' ' || *p
== '\t') p
++;
2119 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
2120 values
.sals
[0] = val
;
2125 /* Arg token is not digits => try it as a variable name
2126 Find the next token (everything up to end or next whitespace). */
2128 while (*p
&& *p
!= ' ' && *p
!= '\t' && *p
!= ',') p
++;
2129 copy
= (char *) alloca (p
- *argptr
+ 1);
2130 bcopy (*argptr
, copy
, p
- *argptr
);
2131 copy
[p
- *argptr
] = 0;
2132 while (*p
== ' ' || *p
== '\t') p
++;
2135 /* Look up that token as a variable.
2136 If file specified, use that file's per-file block to start with. */
2138 sym
= lookup_symbol (copy
,
2139 (s
? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
)
2140 : get_selected_block ()),
2141 VAR_NAMESPACE
, 0, &sym_symtab
);
2145 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
2147 /* Arg is the name of a function */
2148 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) + FUNCTION_START_OFFSET
;
2151 val
= find_pc_line (pc
, 0);
2152 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2153 /* Convex: no need to suppress code on first line, if any */
2156 val
.pc
= (val
.end
&& val
.pc
!= pc
) ? val
.end
: pc
;
2158 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
2159 values
.sals
[0] = val
;
2162 /* I think this is always the same as the line that
2163 we calculate above, but the general principle is
2164 "trust the symbols more than stuff like
2166 if (SYMBOL_LINE (sym
) != 0)
2167 values
.sals
[0].line
= SYMBOL_LINE (sym
);
2171 else if (SYMBOL_LINE (sym
) != 0)
2173 /* We know its line number. */
2174 values
.sals
= (struct symtab_and_line
*)
2175 xmalloc (sizeof (struct symtab_and_line
));
2177 bzero (&values
.sals
[0], sizeof (values
.sals
[0]));
2178 values
.sals
[0].symtab
= sym_symtab
;
2179 values
.sals
[0].line
= SYMBOL_LINE (sym
);
2183 /* This can happen if it is compiled with a compiler which doesn't
2184 put out line numbers for variables. */
2185 error ("Line number not known for symbol \"%s\"", copy
);
2188 if ((i
= lookup_misc_func (copy
)) >= 0)
2192 val
.pc
= misc_function_vector
[i
].address
+ FUNCTION_START_OFFSET
;
2194 SKIP_PROLOGUE (val
.pc
);
2195 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
2196 values
.sals
[0] = val
;
2201 if (symtab_list
== 0 && partial_symtab_list
== 0 && misc_function_count
== 0)
2202 error (no_symtab_msg
);
2204 error ("Function %s not defined.", copy
);
2205 return values
; /* for lint */
2208 struct symtabs_and_lines
2209 decode_line_spec (string
, funfirstline
)
2213 struct symtabs_and_lines sals
;
2215 error ("Empty line specification.");
2216 sals
= decode_line_1 (&string
, funfirstline
,
2217 current_source_symtab
, current_source_line
);
2219 error ("Junk at end of line specification: %s", string
);
2223 /* Given a list of NELTS symbols in sym_arr (with corresponding
2224 mangled names in physnames), return a list of lines to operate on
2225 (ask user if necessary). */
2226 struct symtabs_and_lines
2227 decode_line_2 (sym_arr
, nelts
, funfirstline
)
2228 struct symbol
*sym_arr
[];
2232 struct symtabs_and_lines values
, return_values
;
2233 register CORE_ADDR pc
;
2234 char *args
, *arg1
, *command_line_input ();
2238 values
.sals
= (struct symtab_and_line
*) alloca (nelts
* sizeof(struct symtab_and_line
));
2239 return_values
.sals
= (struct symtab_and_line
*) xmalloc (nelts
* sizeof(struct symtab_and_line
));
2242 printf("[0] cancel\n[1] all\n");
2245 if (sym_arr
[i
] && SYMBOL_CLASS (sym_arr
[i
]) == LOC_BLOCK
)
2247 /* Arg is the name of a function */
2248 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym_arr
[i
]))
2249 + FUNCTION_START_OFFSET
;
2252 values
.sals
[i
] = find_pc_line (pc
, 0);
2253 values
.sals
[i
].pc
= (values
.sals
[i
].end
&& values
.sals
[i
].pc
!= pc
) ?
2254 values
.sals
[i
].end
: pc
;
2255 printf("[%d] file:%s; line number:%d\n",
2256 (i
+2), values
.sals
[i
].symtab
->filename
, values
.sals
[i
].line
);
2258 else printf ("?HERE\n");
2262 if ((prompt
= getenv ("PS2")) == NULL
)
2266 printf("%s ",prompt
);
2269 args
= command_line_input (0, 0);
2272 error_no_arg ("one or more choice numbers");
2280 while (*arg1
>= '0' && *arg1
<= '9') arg1
++;
2281 if (*arg1
&& *arg1
!= ' ' && *arg1
!= '\t')
2282 error ("Arguments must be choice numbers.");
2287 error ("cancelled");
2290 bcopy (values
.sals
, return_values
.sals
, (nelts
* sizeof(struct symtab_and_line
)));
2291 return_values
.nelts
= nelts
;
2292 return return_values
;
2295 if (num
> nelts
+ 2)
2297 printf ("No choice number %d.\n", num
);
2302 if (values
.sals
[num
].pc
)
2304 return_values
.sals
[i
++] = values
.sals
[num
];
2305 values
.sals
[num
].pc
= 0;
2309 printf ("duplicate request for %d ignored.\n", num
);
2314 while (*args
== ' ' || *args
== '\t') args
++;
2316 return_values
.nelts
= i
;
2317 return return_values
;
2320 /* Return the index of misc function named NAME. */
2323 lookup_misc_func (name
)
2324 register char *name
;
2328 for (i
= 0; i
< misc_function_count
; i
++)
2329 if (!strcmp (misc_function_vector
[i
].name
, name
))
2331 return -1; /* not found */
2334 /* Slave routine for sources_info. Force line breaks at ,'s.
2335 NAME is the name to print and *FIRST is nonzero if this is the first
2336 name printed. Set *FIRST to zero. */
2338 output_source_filename (name
, first
)
2343 /* Table of files printed so far. Since a single source file can
2344 result in several partial symbol tables, we need to avoid printing
2345 it more than once. Note: if some of the psymtabs are read in and
2346 some are not, it gets printed both under "Source files for which
2347 symbols have been read" and "Source files for which symbols will
2348 be read in on demand". I consider this a reasonable way to deal
2349 with the situation. I'm not sure whether this can also happen for
2350 symtabs; it doesn't hurt to check. */
2351 static char **tab
= NULL
;
2352 /* Allocated size of tab in elements.
2353 Start with one 256-byte block (when using GNU malloc.c).
2354 24 is the malloc overhead when range checking is in effect. */
2355 static int tab_alloc_size
= (256 - 24) / sizeof (char *);
2356 /* Current size of tab in elements. */
2357 static int tab_cur_size
;
2364 tab
= (char **) xmalloc (tab_alloc_size
* sizeof (*tab
));
2368 /* Is NAME in tab? */
2369 for (p
= tab
; p
< tab
+ tab_cur_size
; p
++)
2370 if (strcmp (*p
, name
) == 0)
2371 /* Yes; don't print it again. */
2373 /* No; add it to tab. */
2374 if (tab_cur_size
== tab_alloc_size
)
2376 tab_alloc_size
*= 2;
2377 tab
= (char **) xrealloc (tab
, tab_alloc_size
* sizeof (*tab
));
2379 tab
[tab_cur_size
++] = name
;
2388 printf_filtered (",");
2392 if (column
!= 0 && column
+ strlen (name
) >= 70)
2394 printf_filtered ("\n");
2397 else if (column
!= 0)
2399 printf_filtered (" ");
2402 fputs_filtered (name
, stdout
);
2403 column
+= strlen (name
);
2409 register struct symtab
*s
;
2410 register struct partial_symtab
*ps
;
2413 if (symtab_list
== 0 && partial_symtab_list
== 0)
2415 printf (no_symtab_msg
);
2419 printf_filtered ("Source files for which symbols have been read in:\n\n");
2422 for (s
= symtab_list
; s
; s
= s
->next
)
2423 output_source_filename (s
->filename
, &first
);
2424 printf_filtered ("\n\n");
2426 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2429 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
2431 output_source_filename (ps
->filename
, &first
);
2432 printf_filtered ("\n");
2435 /* List all symbols (if REGEXP is 0) or all symbols matching REGEXP.
2436 If CLASS is zero, list all symbols except functions and type names.
2437 If CLASS is 1, list only functions.
2438 If CLASS is 2, list only type names.
2439 If CLASS is 3, list only method names.
2441 BPT is non-zero if we should set a breakpoint at the functions
2445 list_symbols (regexp
, class, bpt
)
2450 register struct symtab
*s
;
2451 register struct partial_symtab
*ps
;
2452 register struct blockvector
*bv
;
2453 struct blockvector
*prev_bv
= 0;
2454 register struct block
*b
;
2456 register struct symbol
*sym
;
2457 struct partial_symbol
*psym
;
2459 static char *classnames
[]
2460 = {"variable", "function", "type", "method"};
2461 int found_in_file
= 0;
2463 static enum misc_function_type types
[]
2464 = {mf_data
, mf_text
, mf_abs
, mf_unknown
};
2465 static enum misc_function_type types2
[]
2466 = {mf_bss
, mf_text
, mf_abs
, mf_unknown
};
2467 enum misc_function_type ourtype
= types
[class];
2468 enum misc_function_type ourtype2
= types2
[class];
2471 if (0 != (val
= re_comp (regexp
)))
2472 error ("Invalid regexp (%s): %s", val
, regexp
);
2474 /* Search through the partial_symtab_list *first* for all symbols
2475 matching the regexp. That way we don't have to reproduce all of
2476 the machinery below. */
2477 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
2479 struct partial_symbol
*bound
, *gbound
, *sbound
;
2482 if (ps
->readin
) continue;
2484 gbound
= global_psymbols
.list
+ ps
->globals_offset
+ ps
->n_global_syms
;
2485 sbound
= static_psymbols
.list
+ ps
->statics_offset
+ ps
->n_static_syms
;
2488 /* Go through all of the symbols stored in a partial
2489 symtab in one loop. */
2490 psym
= global_psymbols
.list
+ ps
->globals_offset
;
2495 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
2497 psym
= static_psymbols
.list
+ ps
->statics_offset
;
2508 /* If it would match (logic taken from loop below)
2509 load the file and go on to the next one */
2510 if ((regexp
== 0 || re_exec (SYMBOL_NAME (psym
)))
2511 && ((class == 0 && SYMBOL_CLASS (psym
) != LOC_TYPEDEF
2512 && SYMBOL_CLASS (psym
) != LOC_BLOCK
)
2513 || (class == 1 && SYMBOL_CLASS (psym
) == LOC_BLOCK
)
2514 || (class == 2 && SYMBOL_CLASS (psym
) == LOC_TYPEDEF
)
2515 || (class == 3 && SYMBOL_CLASS (psym
) == LOC_BLOCK
)))
2517 (void) PSYMTAB_TO_SYMTAB(ps
);
2525 /* Here, we search through the misc function vector for functions that
2526 match, and call find_pc_symtab on them to force their symbols to
2527 be read. The symbol will then be found during the scan of symtabs
2528 below. If find_pc_symtab fails, set found_misc so that we will
2529 rescan to print any matching symbols without debug info. */
2532 for (i
= 0; i
< misc_function_count
; i
++) {
2533 if (misc_function_vector
[i
].type
!= ourtype
2534 && misc_function_vector
[i
].type
!= ourtype2
)
2536 if (regexp
== 0 || re_exec (misc_function_vector
[i
].name
)) {
2537 if (0 == find_pc_symtab (misc_function_vector
[i
].address
))
2543 /* Printout here so as to get after the "Reading in symbols"
2544 messages which will be generated above. */
2546 printf_filtered (regexp
2547 ? "All %ss matching regular expression \"%s\":\n"
2548 : "All defined %ss:\n",
2552 for (s
= symtab_list
; s
; s
= s
->next
)
2555 bv
= BLOCKVECTOR (s
);
2556 /* Often many files share a blockvector.
2557 Scan each blockvector only once so that
2558 we don't get every symbol many times.
2559 It happens that the first symtab in the list
2560 for any given blockvector is the main file. */
2562 for (i
= GLOBAL_BLOCK
; i
<= STATIC_BLOCK
; i
++)
2564 b
= BLOCKVECTOR_BLOCK (bv
, i
);
2565 /* Skip the sort if this block is always sorted. */
2566 if (!BLOCK_SHOULD_SORT (b
))
2567 sort_block_syms (b
);
2568 for (j
= 0; j
< BLOCK_NSYMS (b
); j
++)
2571 sym
= BLOCK_SYM (b
, j
);
2572 if ((regexp
== 0 || re_exec (SYMBOL_NAME (sym
)))
2573 && ((class == 0 && SYMBOL_CLASS (sym
) != LOC_TYPEDEF
2574 && SYMBOL_CLASS (sym
) != LOC_BLOCK
)
2575 || (class == 1 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
2576 || (class == 2 && SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
2577 || (class == 3 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)))
2581 /* Set a breakpoint here, if it's a function */
2583 break_command (SYMBOL_NAME(sym
), 0);
2585 else if (!found_in_file
)
2587 fputs_filtered ("\nFile ", stdout
);
2588 fputs_filtered (s
->filename
, stdout
);
2589 fputs_filtered (":\n", stdout
);
2593 if (class != 2 && i
== STATIC_BLOCK
)
2594 printf_filtered ("static ");
2596 /* Typedef that is not a C++ class */
2598 && SYMBOL_NAMESPACE (sym
) != STRUCT_NAMESPACE
)
2600 /* We haven't integrated this from A. Beers yet */
2601 error ("typedef_print(SYMBOL_TYPE(sym),sym,stdout);");
2603 typedef_print(SYMBOL_TYPE(sym
),sym
,stdout
);
2605 /* variable, func, or typedef-that-is-c++-class */
2606 else if (class < 2 ||
2608 SYMBOL_NAMESPACE(sym
) == STRUCT_NAMESPACE
))
2610 type_print (SYMBOL_TYPE (sym
),
2611 (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
2612 ? "" : SYMBOL_NAME (sym
)),
2615 printf_filtered (";\n");
2621 type_print_base (TYPE_FN_FIELD_TYPE(t
, i
), stdout
, 0, 0);
2622 type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t
, i
), stdout
, 0);
2623 sprintf (buf
, " %s::", type_name_no_tag (t
));
2624 type_print_method_args (TYPE_FN_FIELD_ARGS (t
, i
), buf
, name
, stdout
);
2634 /* If there are no eyes, avoid all contact. I mean, if there are
2635 no debug symbols, then print directly from the misc_function_vector. */
2637 if (found_misc
|| class != 1) {
2639 for (i
= 0; i
< misc_function_count
; i
++) {
2640 if (misc_function_vector
[i
].type
!= ourtype
2641 && misc_function_vector
[i
].type
!= ourtype2
)
2643 if (regexp
== 0 || re_exec (misc_function_vector
[i
].name
)) {
2644 /* Functions: Look up by address. */
2646 if (0 != find_pc_symtab (misc_function_vector
[i
].address
))
2648 /* Variables/Absolutes: Look up by name */
2649 if (0 != lookup_symbol (misc_function_vector
[i
].name
,
2650 (struct block
*)0, VAR_NAMESPACE
, 0, (struct symtab
**)0))
2652 if (!found_in_file
) {
2653 printf_filtered ("\nNon-debugging symbols:\n");
2656 printf_filtered (" %08x %s\n",
2657 misc_function_vector
[i
].address
,
2658 misc_function_vector
[i
].name
);
2665 variables_info (regexp
)
2668 list_symbols (regexp
, 0, 0);
2672 functions_info (regexp
)
2675 list_symbols (regexp
, 1, 0);
2682 list_symbols (regexp
, 2, 0);
2686 /* Tiemann says: "info methods was never implemented." */
2688 methods_info (regexp
)
2691 list_symbols (regexp
, 3, 0);
2695 /* Breakpoint all functions matching regular expression. */
2697 rbreak_command (regexp
)
2700 list_symbols (regexp
, 1, 1);
2703 /* Helper function to initialize the standard scalar types. */
2706 init_type (code
, length
, uns
, name
)
2707 enum type_code code
;
2711 register struct type
*type
;
2713 type
= (struct type
*) xmalloc (sizeof (struct type
));
2714 bzero (type
, sizeof *type
);
2715 TYPE_MAIN_VARIANT (type
) = type
;
2716 TYPE_CODE (type
) = code
;
2717 TYPE_LENGTH (type
) = length
;
2718 TYPE_FLAGS (type
) = uns
? TYPE_FLAG_UNSIGNED
: 0;
2719 TYPE_FLAGS (type
) |= TYPE_FLAG_PERM
;
2720 TYPE_NFIELDS (type
) = 0;
2721 TYPE_NAME (type
) = name
;
2724 TYPE_NFN_FIELDS (type
) = 0;
2725 TYPE_N_BASECLASSES (type
) = 0;
2729 /* Return Nonzero if block a is lexically nested within block b,
2730 or if a and b have the same pc range.
2731 Return zero otherwise. */
2734 struct block
*a
, *b
;
2738 return BLOCK_START (a
) >= BLOCK_START (b
)
2739 && BLOCK_END (a
) <= BLOCK_END (b
);
2743 /* Helper routine for make_symbol_completion_list. */
2745 int return_val_size
, return_val_index
;
2749 completion_list_add_symbol (symname
)
2752 if (return_val_index
+ 3 > return_val_size
)
2754 (char **)xrealloc (return_val
,
2755 (return_val_size
*= 2) * sizeof (char *));
2757 return_val
[return_val_index
] =
2758 (char *)xmalloc (1 + strlen (symname
));
2760 strcpy (return_val
[return_val_index
], symname
);
2762 return_val
[++return_val_index
] = (char *)NULL
;
2765 /* Return a NULL terminated array of all symbols (regardless of class) which
2766 begin by matching TEXT. If the answer is no symbols, then the return value
2767 is an array which contains only a NULL pointer.
2769 Problem: All of the symbols have to be copied because readline
2770 frees them. I'm not going to worry about this; hopefully there
2771 won't be that many. */
2774 make_symbol_completion_list (text
)
2777 register struct symtab
*s
;
2778 register struct partial_symtab
*ps
;
2779 register struct block
*b
, *surrounding_static_block
= 0;
2780 extern struct block
*get_selected_block ();
2782 struct partial_symbol
*psym
;
2784 int text_len
= strlen (text
);
2785 return_val_size
= 100;
2786 return_val_index
= 0;
2788 (char **)xmalloc ((1 + return_val_size
) *sizeof (char *));
2789 return_val
[0] = (char *)NULL
;
2791 /* Look through the partial symtabs for all symbols which begin
2792 by matching TEXT. Add each one that you find to the list. */
2794 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
2796 /* If the psymtab's been read in we'll get it when we search
2797 through the blockvector. */
2798 if (ps
->readin
) continue;
2800 for (psym
= global_psymbols
.list
+ ps
->globals_offset
;
2801 psym
< (global_psymbols
.list
+ ps
->globals_offset
2802 + ps
->n_global_syms
);
2805 QUIT
; /* If interrupted, then quit. */
2806 if ((strncmp (SYMBOL_NAME (psym
), text
, text_len
) == 0))
2807 completion_list_add_symbol (SYMBOL_NAME (psym
));
2810 for (psym
= static_psymbols
.list
+ ps
->statics_offset
;
2811 psym
< (static_psymbols
.list
+ ps
->statics_offset
2812 + ps
->n_static_syms
);
2816 if ((strncmp (SYMBOL_NAME (psym
), text
, text_len
) == 0))
2817 completion_list_add_symbol (SYMBOL_NAME (psym
));
2821 /* At this point scan through the misc function vector and add each
2822 symbol you find to the list. Eventually we want to ignore
2823 anything that isn't a text symbol (everything else will be
2824 handled by the psymtab code above). */
2826 for (i
= 0; i
< misc_function_count
; i
++)
2827 if (!strncmp (text
, misc_function_vector
[i
].name
, text_len
))
2828 completion_list_add_symbol (misc_function_vector
[i
].name
);
2830 /* Search upwards from currently selected frame (so that we can
2831 complete on local vars. */
2832 for (b
= get_selected_block (); b
; b
= BLOCK_SUPERBLOCK (b
))
2834 if (!BLOCK_SUPERBLOCK (b
))
2835 surrounding_static_block
= b
; /* For elmin of dups */
2837 /* Also catch fields of types defined in this places which
2838 match our text string. Only complete on types visible
2839 from current context. */
2840 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2842 register struct symbol
*sym
= BLOCK_SYM (b
, i
);
2844 if (!strncmp (SYMBOL_NAME (sym
), text
, text_len
))
2845 completion_list_add_symbol (SYMBOL_NAME (sym
));
2847 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
2849 struct type
*t
= SYMBOL_TYPE (sym
);
2850 enum type_code c
= TYPE_CODE (t
);
2852 if (c
== TYPE_CODE_UNION
|| c
== TYPE_CODE_STRUCT
)
2853 for (j
= TYPE_N_BASECLASSES (t
); j
< TYPE_NFIELDS (t
); j
++)
2854 if (TYPE_FIELD_NAME (t
, j
) &&
2855 !strncmp (TYPE_FIELD_NAME (t
, j
), text
, text_len
))
2856 completion_list_add_symbol (TYPE_FIELD_NAME (t
, j
));
2861 /* Go through the symtabs and check the externs and statics for
2862 symbols which match. */
2864 for (s
= symtab_list
; s
; s
= s
->next
)
2866 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
2868 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2869 if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b
, i
)), text
, text_len
))
2870 completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b
, i
)));
2873 for (s
= symtab_list
; s
; s
= s
->next
)
2875 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
2877 /* Don't do this block twice. */
2878 if (b
== surrounding_static_block
) continue;
2880 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2881 if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b
, i
)), text
, text_len
))
2882 completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b
, i
)));
2885 return (return_val
);
2889 /* Add the type of the symbol sym to the type of the current
2890 function whose block we are in (assumed). The type of
2891 this current function is contained in *TYPE.
2893 This basically works as follows: When we find a function
2894 symbol (N_FUNC with a 'f' or 'F' in the symbol name), we record
2895 a pointer to its type in the global in_function_type. Every
2896 time we come across a parameter symbol ('p' in its name), then
2897 this procedure adds the name and type of that parameter
2898 to the function type pointed to by *TYPE. (Which should correspond
2899 to in_function_type if it was called correctly).
2901 Note that since we are modifying a type, the result of
2902 lookup_function_type() should be bcopy()ed before calling
2903 this. When not in strict typing mode, the expression
2904 evaluator can choose to ignore this.
2906 Assumption: All of a function's parameter symbols will
2907 appear before another function symbol is found. The parameters
2908 appear in the same order in the argument list as they do in the
2912 add_param_to_type (type
,sym
)
2916 int num
= ++(TYPE_NFIELDS(*type
));
2918 if(TYPE_NFIELDS(*type
)-1)
2919 TYPE_FIELDS(*type
) =
2920 (struct field
*)xrealloc((char *)(TYPE_FIELDS(*type
)),
2921 num
*sizeof(struct field
));
2923 TYPE_FIELDS(*type
) =
2924 (struct field
*)xmalloc(num
*sizeof(struct field
));
2926 TYPE_FIELD_BITPOS(*type
,num
-1) = num
-1;
2927 TYPE_FIELD_BITSIZE(*type
,num
-1) = 0;
2928 TYPE_FIELD_TYPE(*type
,num
-1) = SYMBOL_TYPE(sym
);
2929 TYPE_FIELD_NAME(*type
,num
-1) = SYMBOL_NAME(sym
);
2934 _initialize_symtab ()
2936 add_info ("variables", variables_info
,
2937 "All global and static variable names, or those matching REGEXP.");
2938 add_info ("functions", functions_info
,
2939 "All function names, or those matching REGEXP.");
2941 /* FIXME: This command has at least the following problems:
2942 1. It prints builtin types (in a very strange and confusing fashion).
2943 2. It doesn't print right, e.g. with
2944 typedef struct foo *FOO
2945 type_print prints "FOO" when we want to make it (in this situation)
2946 print "struct foo *".
2947 I also think "ptype" or "whatis" is more likely to be useful (but if
2948 there is much disagreement "info types" can be fixed). */
2949 add_info ("types", types_info
,
2950 "All types names, or those matching REGEXP.");
2953 add_info ("methods", methods_info
,
2954 "All method names, or those matching REGEXP::REGEXP.\n\
2955 If the class qualifier is ommited, it is assumed to be the current scope.\n\
2956 If the first REGEXP is ommited, then all methods matching the second REGEXP\n\
2959 add_info ("sources", sources_info
,
2960 "Source files in the program.");
2962 add_com ("rbreak", no_class
, rbreak_command
,
2963 "Set a breakpoint for all functions matching REGEXP.");
2965 /* Initialize the one built-in type that isn't language dependent... */
2966 builtin_type_error
= init_type (TYPE_CODE_ERROR
, 0, 0, "<unknown type>");