1 /* Symbol table lookup for the GNU debugger, GDB.
2 Copyright (C) 1986, 1987, 1988, 1989 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. */
30 /* Allocate an obstack to hold objects that should be freed
31 when we load a new symbol table.
32 This includes the symbols made by dbxread
33 and the types that are not permanent. */
35 struct obstack obstack1
;
37 struct obstack
*symbol_obstack
= &obstack1
;
39 /* This obstack will be used for partial_symbol objects. It can
40 probably actually be the same as the symbol_obstack above, but I'd
41 like to keep them seperate for now. If I want to later, I'll
42 replace one with the other. */
44 struct obstack obstack2
;
46 struct obstack
*psymbol_obstack
= &obstack2
;
48 /* These variables point to the objects
49 representing the predefined C data types. */
51 struct type
*builtin_type_void
;
52 struct type
*builtin_type_char
;
53 struct type
*builtin_type_short
;
54 struct type
*builtin_type_int
;
55 struct type
*builtin_type_long
;
57 struct type
*builtin_type_long_long
;
59 struct type
*builtin_type_unsigned_char
;
60 struct type
*builtin_type_unsigned_short
;
61 struct type
*builtin_type_unsigned_int
;
62 struct type
*builtin_type_unsigned_long
;
64 struct type
*builtin_type_unsigned_long_long
;
66 struct type
*builtin_type_float
;
67 struct type
*builtin_type_double
;
69 /* Block in which the most recently searched-for symbol was found.
70 Might be better to make this a parameter to lookup_symbol and
72 struct block
*block_found
;
75 static int find_line_common ();
76 static int lookup_misc_func ();
77 struct partial_symtab
*lookup_partial_symtab ();
78 struct symtab
*psymtab_to_symtab ();
79 static struct partial_symbol
*lookup_partial_symbol ();
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
= index (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 s
= psymtab_to_symtab (ps
);
109 for (s
= symtab_list
; s
; s
= s
->next
)
111 int l
= strlen (s
->filename
);
113 if (s
->filename
[l
- len
-1] == '/'
114 && !strcmp (s
->filename
+ l
- len
, name
))
118 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
120 int l
= strlen (ps
->filename
);
122 if (ps
->filename
[l
- len
- 1] == '/'
123 && !strcmp (ps
->filename
+ l
- len
, name
))
126 fatal ("Internal: readin pst found when no symtab found.");
127 s
= psymtab_to_symtab (ps
);
135 /* Lookup the symbol table of a source file named NAME. Try a couple
136 of variations if the first lookup doesn't work. */
142 register struct symtab
*s
;
145 s
= lookup_symtab_1 (name
);
148 /* If name not found as specified, see if adding ".c" helps. */
150 copy
= (char *) alloca (strlen (name
) + 3);
153 s
= lookup_symtab_1 (copy
);
156 /* We didn't find anything; die. */
160 /* Lookup the partial symbol table of a source file named NAME. This
161 only returns true on an exact match (ie. this semantics are
162 different from lookup_symtab. */
164 struct partial_symtab
*
165 lookup_partial_symtab (name
)
168 register struct partial_symtab
*s
;
171 for (s
= partial_symtab_list
; s
; s
= s
->next
)
172 if (!strcmp (name
, s
->filename
))
178 /* Lookup a typedef or primitive type named NAME,
179 visible in lexical block BLOCK.
180 If NOERR is nonzero, return zero if NAME is not suitably defined. */
183 lookup_typename (name
, block
, noerr
)
188 register struct symbol
*sym
= lookup_symbol (name
, block
, VAR_NAMESPACE
, 0);
189 if (sym
== 0 || SYMBOL_CLASS (sym
) != LOC_TYPEDEF
)
191 if (!strcmp (name
, "int"))
192 return builtin_type_int
;
193 if (!strcmp (name
, "long"))
194 return builtin_type_long
;
195 if (!strcmp (name
, "short"))
196 return builtin_type_short
;
197 if (!strcmp (name
, "char"))
198 return builtin_type_char
;
199 if (!strcmp (name
, "float"))
200 return builtin_type_float
;
201 if (!strcmp (name
, "double"))
202 return builtin_type_double
;
203 if (!strcmp (name
, "void"))
204 return builtin_type_void
;
208 error ("No type named %s.", name
);
210 return SYMBOL_TYPE (sym
);
214 lookup_unsigned_typename (name
)
217 if (!strcmp (name
, "int"))
218 return builtin_type_unsigned_int
;
219 if (!strcmp (name
, "long"))
220 return builtin_type_unsigned_long
;
221 if (!strcmp (name
, "short"))
222 return builtin_type_unsigned_short
;
223 if (!strcmp (name
, "char"))
224 return builtin_type_unsigned_char
;
225 error ("No type named unsigned %s.", name
);
228 /* Lookup a structure type named "struct NAME",
229 visible in lexical block BLOCK. */
232 lookup_struct (name
, block
)
236 register struct symbol
*sym
237 = lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0);
240 error ("No struct type named %s.", name
);
241 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
242 error ("This context has class, union or enum %s, not a struct.", name
);
243 return SYMBOL_TYPE (sym
);
246 /* Lookup a union type named "union NAME",
247 visible in lexical block BLOCK. */
250 lookup_union (name
, block
)
254 register struct symbol
*sym
255 = lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0);
258 error ("No union type named %s.", name
);
259 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_UNION
)
260 error ("This context has class, struct or enum %s, not a union.", name
);
261 return SYMBOL_TYPE (sym
);
264 /* Lookup an enum type named "enum NAME",
265 visible in lexical block BLOCK. */
268 lookup_enum (name
, block
)
272 register struct symbol
*sym
273 = lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0);
275 error ("No enum type named %s.", name
);
276 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_ENUM
)
277 error ("This context has class, struct or union %s, not an enum.", name
);
278 return SYMBOL_TYPE (sym
);
281 /* Given a type TYPE, lookup the type of the component of type named
285 lookup_struct_elt_type (type
, name
)
293 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
294 && TYPE_CODE (type
) != TYPE_CODE_UNION
)
298 fprintf (stderr
, "Type ");
299 type_print (type
, "", stderr
, -1);
300 fprintf (stderr
, " is not a structure or union type.\n");
301 return_to_top_level ();
304 for (i
= TYPE_NFIELDS (type
) - 1; i
>= 0; i
--)
305 if (!strcmp (TYPE_FIELD_NAME (type
, i
), name
))
306 return TYPE_FIELD_TYPE (type
, i
);
310 fprintf (stderr
, "Type ");
311 type_print (type
, "", stderr
, -1);
312 fprintf (stderr
, " has no component named %s\n", name
);
313 return_to_top_level ();
316 /* Given a type TYPE, return a type of pointers to that type.
317 May need to construct such a type if this is the first use.
319 C++: use TYPE_MAIN_VARIANT and TYPE_CHAIN to keep pointer
320 to member types under control. */
323 lookup_pointer_type (type
)
326 register struct type
*ptype
= TYPE_POINTER_TYPE (type
);
327 if (ptype
) return TYPE_MAIN_VARIANT (ptype
);
329 /* This is the first time anyone wanted a pointer to a TYPE. */
330 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
331 ptype
= (struct type
*) xmalloc (sizeof (struct type
));
333 ptype
= (struct type
*) obstack_alloc (symbol_obstack
,
334 sizeof (struct type
));
336 bzero (ptype
, sizeof (struct type
));
337 TYPE_MAIN_VARIANT (ptype
) = ptype
;
338 TYPE_TARGET_TYPE (ptype
) = type
;
339 TYPE_POINTER_TYPE (type
) = ptype
;
340 /* New type is permanent if type pointed to is permanent. */
341 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
342 TYPE_FLAGS (ptype
) |= TYPE_FLAG_PERM
;
343 /* We assume the machine has only one representation for pointers! */
344 TYPE_LENGTH (ptype
) = sizeof (char *);
345 TYPE_CODE (ptype
) = TYPE_CODE_PTR
;
350 lookup_reference_type (type
)
353 register struct type
*rtype
= TYPE_REFERENCE_TYPE (type
);
354 if (rtype
) return TYPE_MAIN_VARIANT (rtype
);
356 /* This is the first time anyone wanted a pointer to a TYPE. */
357 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
358 rtype
= (struct type
*) xmalloc (sizeof (struct type
));
360 rtype
= (struct type
*) obstack_alloc (symbol_obstack
,
361 sizeof (struct type
));
363 bzero (rtype
, sizeof (struct type
));
364 TYPE_MAIN_VARIANT (rtype
) = rtype
;
365 TYPE_TARGET_TYPE (rtype
) = type
;
366 TYPE_REFERENCE_TYPE (type
) = rtype
;
367 /* New type is permanent if type pointed to is permanent. */
368 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
369 TYPE_FLAGS (rtype
) |= TYPE_FLAG_PERM
;
370 /* We assume the machine has only one representation for pointers! */
371 TYPE_LENGTH (rtype
) = sizeof (char *);
372 TYPE_CODE (rtype
) = TYPE_CODE_REF
;
377 /* Implement direct support for MEMBER_TYPE in GNU C++.
378 May need to construct such a type if this is the first use.
379 The TYPE is the type of the member. The DOMAIN is the type
380 of the aggregate that the member belongs to. */
383 lookup_member_type (type
, domain
)
384 struct type
*type
, *domain
;
386 register struct type
*mtype
= TYPE_MAIN_VARIANT (type
);
387 struct type
*main_type
;
392 if (TYPE_DOMAIN_TYPE (mtype
) == domain
)
394 mtype
= TYPE_NEXT_VARIANT (mtype
);
397 /* This is the first time anyone wanted this member type. */
398 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
399 mtype
= (struct type
*) xmalloc (sizeof (struct type
));
401 mtype
= (struct type
*) obstack_alloc (symbol_obstack
,
402 sizeof (struct type
));
404 bzero (mtype
, sizeof (struct type
));
409 TYPE_NEXT_VARIANT (mtype
) = TYPE_NEXT_VARIANT (main_type
);
410 TYPE_NEXT_VARIANT (main_type
) = mtype
;
412 TYPE_MAIN_VARIANT (mtype
) = main_type
;
413 TYPE_TARGET_TYPE (mtype
) = type
;
414 TYPE_DOMAIN_TYPE (mtype
) = domain
;
415 /* New type is permanent if type pointed to is permanent. */
416 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
417 TYPE_FLAGS (mtype
) |= TYPE_FLAG_PERM
;
419 /* In practice, this is never used. */
420 TYPE_LENGTH (mtype
) = 1;
421 TYPE_CODE (mtype
) = TYPE_CODE_MEMBER
;
424 /* Now splice in the new member pointer type. */
427 /* This type was not "smashed". */
428 TYPE_CHAIN (mtype
) = TYPE_CHAIN (main_type
);
429 TYPE_CHAIN (main_type
) = mtype
;
437 lookup_method_type (type
, domain
, args
)
438 struct type
*type
, *domain
, **args
;
440 register struct type
*mtype
= TYPE_MAIN_VARIANT (type
);
441 struct type
*main_type
;
446 if (TYPE_DOMAIN_TYPE (mtype
) == domain
)
448 struct type
**t1
= args
;
449 struct type
**t2
= TYPE_ARG_TYPES (mtype
);
453 for (i
= 0; t1
[i
] != 0 && t1
[i
]->code
!= TYPE_CODE_VOID
; i
++)
460 mtype
= TYPE_NEXT_VARIANT (mtype
);
463 /* This is the first time anyone wanted this member type. */
464 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
465 mtype
= (struct type
*) xmalloc (sizeof (struct type
));
467 mtype
= (struct type
*) obstack_alloc (symbol_obstack
,
468 sizeof (struct type
));
470 bzero (mtype
, sizeof (struct type
));
475 TYPE_NEXT_VARIANT (mtype
) = TYPE_NEXT_VARIANT (main_type
);
476 TYPE_NEXT_VARIANT (main_type
) = mtype
;
478 TYPE_MAIN_VARIANT (mtype
) = main_type
;
479 TYPE_TARGET_TYPE (mtype
) = type
;
480 TYPE_DOMAIN_TYPE (mtype
) = domain
;
481 TYPE_ARG_TYPES (mtype
) = args
;
482 /* New type is permanent if type pointed to is permanent. */
483 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
484 TYPE_FLAGS (mtype
) |= TYPE_FLAG_PERM
;
486 /* In practice, this is never used. */
487 TYPE_LENGTH (mtype
) = 1;
488 TYPE_CODE (mtype
) = TYPE_CODE_METHOD
;
491 /* Now splice in the new member pointer type. */
494 /* This type was not "smashed". */
495 TYPE_CHAIN (mtype
) = TYPE_CHAIN (main_type
);
496 TYPE_CHAIN (main_type
) = mtype
;
503 /* Given a type TYPE, return a type which has offset OFFSET,
504 via_virtual VIA_VIRTUAL, and via_public VIA_PUBLIC.
505 May need to construct such a type if none exists. */
507 lookup_basetype_type (type
, offset
, via_virtual
, via_public
)
510 int via_virtual
, via_public
;
512 register struct type
*btype
= TYPE_MAIN_VARIANT (type
);
513 struct type
*main_type
;
517 printf ("Internal error: type offset non-zero in lookup_basetype_type");
524 if (/* TYPE_OFFSET (btype) == offset
525 && */ TYPE_VIA_PUBLIC (btype
) == via_public
526 && TYPE_VIA_VIRTUAL (btype
) == via_virtual
)
528 btype
= TYPE_NEXT_VARIANT (btype
);
531 /* This is the first time anyone wanted this member type. */
532 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
533 btype
= (struct type
*) xmalloc (sizeof (struct type
));
535 btype
= (struct type
*) obstack_alloc (symbol_obstack
,
536 sizeof (struct type
));
541 bzero (btype
, sizeof (struct type
));
542 TYPE_MAIN_VARIANT (btype
) = main_type
;
546 bcopy (main_type
, btype
, sizeof (struct type
));
547 TYPE_NEXT_VARIANT (main_type
) = btype
;
549 /* TYPE_OFFSET (btype) = offset; */
551 TYPE_FLAGS (btype
) |= TYPE_FLAG_VIA_PUBLIC
;
553 TYPE_FLAGS (btype
) |= TYPE_FLAG_VIA_VIRTUAL
;
554 /* New type is permanent if type pointed to is permanent. */
555 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
556 TYPE_FLAGS (btype
) |= TYPE_FLAG_PERM
;
558 /* In practice, this is never used. */
559 TYPE_LENGTH (btype
) = 1;
560 TYPE_CODE (btype
) = TYPE_CODE_STRUCT
;
565 /* Given a type TYPE, return a type of functions that return that type.
566 May need to construct such a type if this is the first use. */
569 lookup_function_type (type
)
572 register struct type
*ptype
= TYPE_FUNCTION_TYPE (type
);
573 if (ptype
) return ptype
;
575 /* This is the first time anyone wanted a function returning a TYPE. */
576 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
577 ptype
= (struct type
*) xmalloc (sizeof (struct type
));
579 ptype
= (struct type
*) obstack_alloc (symbol_obstack
,
580 sizeof (struct type
));
582 bzero (ptype
, sizeof (struct type
));
583 TYPE_TARGET_TYPE (ptype
) = type
;
584 TYPE_FUNCTION_TYPE (type
) = ptype
;
585 /* New type is permanent if type returned is permanent. */
586 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
587 TYPE_FLAGS (ptype
) |= TYPE_FLAG_PERM
;
588 TYPE_LENGTH (ptype
) = 1;
589 TYPE_CODE (ptype
) = TYPE_CODE_FUNC
;
590 TYPE_NFIELDS (ptype
) = 0;
594 /* Create an array type. Elements will be of type TYPE, and there will
597 Eventually this should be extended to take two more arguments which
598 specify the bounds of the array and the type of the index.
599 It should also be changed to be a "lookup" function, with the
600 appropriate data structures added to the type field.
601 Then read array type should call here. */
604 create_array_type (element_type
, number
)
605 struct type
*element_type
;
608 struct type
*result_type
= (struct type
*)
609 obstack_alloc (symbol_obstack
, sizeof (struct type
));
611 bzero (result_type
, sizeof (struct type
));
613 TYPE_CODE (result_type
) = TYPE_CODE_ARRAY
;
614 TYPE_TARGET_TYPE (result_type
) = element_type
;
615 TYPE_LENGTH (result_type
) = number
* TYPE_LENGTH (element_type
);
616 TYPE_NFIELDS (result_type
) = 1;
617 TYPE_FIELDS (result_type
) =
618 (struct field
*) obstack_alloc (symbol_obstack
, sizeof (struct field
));
619 TYPE_FIELD_TYPE (result_type
, 0) = builtin_type_int
;
620 TYPE_VPTR_FIELDNO (result_type
) = -1;
626 /* Smash TYPE to be a type of pointers to TO_TYPE.
627 If TO_TYPE is not permanent and has no pointer-type yet,
628 record TYPE as its pointer-type. */
631 smash_to_pointer_type (type
, to_type
)
632 struct type
*type
, *to_type
;
634 int type_permanent
= (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
);
636 bzero (type
, sizeof (struct type
));
637 TYPE_TARGET_TYPE (type
) = to_type
;
638 /* We assume the machine has only one representation for pointers! */
639 TYPE_LENGTH (type
) = sizeof (char *);
640 TYPE_CODE (type
) = TYPE_CODE_PTR
;
642 TYPE_MAIN_VARIANT (type
) = type
;
645 TYPE_FLAGS (type
) |= TYPE_FLAG_PERM
;
647 if (TYPE_POINTER_TYPE (to_type
) == 0
648 && (!(TYPE_FLAGS (to_type
) & TYPE_FLAG_PERM
)
651 TYPE_POINTER_TYPE (to_type
) = type
;
655 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE. */
658 smash_to_member_type (type
, domain
, to_type
)
659 struct type
*type
, *domain
, *to_type
;
661 bzero (type
, sizeof (struct type
));
662 TYPE_TARGET_TYPE (type
) = to_type
;
663 TYPE_DOMAIN_TYPE (type
) = domain
;
665 /* In practice, this is never needed. */
666 TYPE_LENGTH (type
) = 1;
667 TYPE_CODE (type
) = TYPE_CODE_MEMBER
;
669 TYPE_MAIN_VARIANT (type
) = lookup_member_type (domain
, to_type
);
672 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE. */
675 smash_to_method_type (type
, domain
, to_type
, args
)
676 struct type
*type
, *domain
, *to_type
, **args
;
678 bzero (type
, sizeof (struct type
));
679 TYPE_TARGET_TYPE (type
) = to_type
;
680 TYPE_DOMAIN_TYPE (type
) = domain
;
681 TYPE_ARG_TYPES (type
) = args
;
683 /* In practice, this is never needed. */
684 TYPE_LENGTH (type
) = 1;
685 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
687 TYPE_MAIN_VARIANT (type
) = lookup_method_type (domain
, to_type
, args
);
690 /* Smash TYPE to be a type of reference to TO_TYPE.
691 If TO_TYPE is not permanent and has no pointer-type yet,
692 record TYPE as its pointer-type. */
695 smash_to_reference_type (type
, to_type
)
696 struct type
*type
, *to_type
;
698 int type_permanent
= (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
);
700 bzero (type
, sizeof (struct type
));
701 TYPE_TARGET_TYPE (type
) = to_type
;
702 /* We assume the machine has only one representation for pointers! */
703 TYPE_LENGTH (type
) = sizeof (char *);
704 TYPE_CODE (type
) = TYPE_CODE_REF
;
706 TYPE_MAIN_VARIANT (type
) = type
;
709 TYPE_FLAGS (type
) |= TYPE_FLAG_PERM
;
711 if (TYPE_REFERENCE_TYPE (to_type
) == 0
712 && (!(TYPE_FLAGS (to_type
) & TYPE_FLAG_PERM
)
715 TYPE_REFERENCE_TYPE (to_type
) = type
;
719 /* Smash TYPE to be a type of functions returning TO_TYPE.
720 If TO_TYPE is not permanent and has no function-type yet,
721 record TYPE as its function-type. */
724 smash_to_function_type (type
, to_type
)
725 struct type
*type
, *to_type
;
727 int type_permanent
= (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
);
729 bzero (type
, sizeof (struct type
));
730 TYPE_TARGET_TYPE (type
) = to_type
;
731 TYPE_LENGTH (type
) = 1;
732 TYPE_CODE (type
) = TYPE_CODE_FUNC
;
733 TYPE_NFIELDS (type
) = 0;
736 TYPE_FLAGS (type
) |= TYPE_FLAG_PERM
;
738 if (TYPE_FUNCTION_TYPE (to_type
) == 0
739 && (!(TYPE_FLAGS (to_type
) & TYPE_FLAG_PERM
)
742 TYPE_FUNCTION_TYPE (to_type
) = type
;
746 /* Find which partial symtab on the partial_symtab_list contains
747 PC. Return 0 if none. */
749 struct partial_symtab
*
751 register CORE_ADDR pc
;
753 register struct partial_symtab
*ps
;
755 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
756 if (pc
>= ps
->textlow
&& pc
< ps
->texthigh
)
762 /* Find which partial symbol within a psymtab contains PC. Return 0
763 if none. Check all psymtabs if PSYMTAB is 0. */
764 struct partial_symbol
*
765 find_pc_psymbol (psymtab
, pc
)
766 struct partial_symtab
*psymtab
;
769 struct partial_symbol
*best
, *p
;
773 psymtab
= find_pc_psymtab (pc
);
777 best_pc
= psymtab
->textlow
- 1;
779 for (p
= static_psymbols
.list
+ psymtab
->statics_offset
;
780 (p
- (static_psymbols
.list
+ psymtab
->statics_offset
)
781 < psymtab
->n_static_syms
);
783 if (SYMBOL_NAMESPACE (p
) == VAR_NAMESPACE
784 && SYMBOL_CLASS (p
) == LOC_BLOCK
785 && pc
>= SYMBOL_VALUE (p
)
786 && SYMBOL_VALUE (p
) > best_pc
)
788 best_pc
= SYMBOL_VALUE (p
);
791 if (best_pc
== psymtab
->textlow
- 1)
797 static struct symbol
*lookup_block_symbol ();
799 /* Find the definition for a specified symbol name NAME
800 in namespace NAMESPACE, visible from lexical block BLOCK.
801 Returns the struct symbol pointer, or zero if no symbol is found.
802 C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
803 NAME is a field of the current implied argument `this'. If so set
804 *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
805 BLOCK_FOUND is set to the block in which NAME is found (in the case of
806 a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
809 lookup_symbol (name
, block
, namespace, is_a_field_of_this
)
811 register struct block
*block
;
812 enum namespace namespace;
813 int *is_a_field_of_this
;
816 register struct symbol
*sym
;
817 register struct symtab
*s
;
818 register struct partial_symtab
*ps
;
819 struct blockvector
*bv
;
821 /* Search specified block and its superiors. */
825 sym
= lookup_block_symbol (block
, name
, namespace);
831 block
= BLOCK_SUPERBLOCK (block
);
834 /* C++: If requested to do so by the caller,
835 check to see if NAME is a field of `this'. */
836 if (is_a_field_of_this
)
838 int v
= (int) value_of_this (0);
840 *is_a_field_of_this
= 0;
841 if (v
&& check_field (v
, name
))
843 *is_a_field_of_this
= 1;
848 /* Now search all global blocks. Do the symtab's first, then
849 check the psymtab's */
851 for (s
= symtab_list
; s
; s
= s
->next
)
853 bv
= BLOCKVECTOR (s
);
854 block
= BLOCKVECTOR_BLOCK (bv
, 0);
855 sym
= lookup_block_symbol (block
, name
, namespace);
863 /* Check for the possibility of the symbol being a global function
864 that is stored on the misc function vector. Eventually, all
865 global symbols might be resolved in this way. */
867 if (namespace == VAR_NAMESPACE
)
869 int index
= lookup_misc_func (name
);
873 ps
= find_pc_psymtab (misc_function_vector
[index
].address
);
874 if (ps
&& !ps
->readin
)
876 s
= psymtab_to_symtab (ps
);
877 bv
= BLOCKVECTOR (s
);
878 block
= BLOCKVECTOR_BLOCK (bv
, 0);
879 sym
= lookup_block_symbol (block
, name
, namespace);
880 /* sym == 0 if symbol was found in the psymtab but not
882 Return 0 to use the misc_function definition of "foo_".
884 This happens for Fortran "foo_" symbols,
885 which are "foo" in the symtab.
887 This can also happen if "asm" is used to make a
888 regular symbol but not a debugging symbol, e.g.
898 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
899 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 1, namespace))
901 s
= psymtab_to_symtab(ps
);
902 bv
= BLOCKVECTOR (s
);
903 block
= BLOCKVECTOR_BLOCK (bv
, 0);
904 sym
= lookup_block_symbol (block
, name
, namespace);
906 fatal ("Internal: global symbol found in psymtab but not in symtab");
910 /* Now search all per-file blocks.
911 Not strictly correct, but more useful than an error.
912 Do the symtabs first, then check the psymtabs */
914 for (s
= symtab_list
; s
; s
= s
->next
)
916 bv
= BLOCKVECTOR (s
);
917 block
= BLOCKVECTOR_BLOCK (bv
, 1);
918 sym
= lookup_block_symbol (block
, name
, namespace);
926 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
927 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 0, namespace))
929 s
= psymtab_to_symtab(ps
);
930 bv
= BLOCKVECTOR (s
);
931 block
= BLOCKVECTOR_BLOCK (bv
, 1);
932 sym
= lookup_block_symbol (block
, name
, namespace);
934 fatal ("Internal: static symbol found in psymtab but not in symtab");
941 /* Look, in partial_symtab PST, for symbol NAME. Check the global
942 symbols if GLOBAL, the static symbols if not */
944 static struct partial_symbol
*
945 lookup_partial_symbol (pst
, name
, global
, namespace)
946 struct partial_symtab
*pst
;
949 enum namespace namespace;
951 struct partial_symbol
*start
, *psym
;
952 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
955 global_psymbols
.list
+ pst
->globals_offset
:
956 static_psymbols
.list
+ pst
->statics_offset
);
959 return (struct partial_symbol
*) 0;
961 if (global
) /* This means we can use a binary */
964 struct partial_symbol
*top
, *bottom
, *center
;
966 /* Binary search. This search is guarranteed to end with center
967 pointing at the earliest partial symbol with the correct
968 name. At that point *all* partial symbols with that name
969 will be checked against the correct namespace. */
971 top
= start
+ length
- 1;
974 center
= bottom
+ (top
- bottom
) / 2;
976 assert (center
< top
);
978 if (strcmp (SYMBOL_NAME (center
), name
) >= 0)
983 assert (top
== bottom
);
985 while (!strcmp (SYMBOL_NAME (top
), name
))
987 if (SYMBOL_NAMESPACE (top
) == namespace)
994 /* Can't use a binary search */
995 for (psym
= start
; psym
< start
+ length
; psym
++)
996 if (namespace == SYMBOL_NAMESPACE (psym
)
997 && !strcmp (name
, SYMBOL_NAME (psym
)))
1001 return (struct partial_symbol
*) 0;
1004 /* Look for a symbol in block BLOCK. */
1006 static struct symbol
*
1007 lookup_block_symbol (block
, name
, namespace)
1008 register struct block
*block
;
1010 enum namespace namespace;
1012 register int bot
, top
, inc
;
1013 register struct symbol
*sym
, *parameter_sym
;
1015 top
= BLOCK_NSYMS (block
);
1018 /* If the blocks's symbols were sorted, start with a binary search. */
1020 if (BLOCK_SHOULD_SORT (block
))
1022 /* First, advance BOT to not far before
1023 the first symbol whose name is NAME. */
1027 inc
= (top
- bot
+ 1);
1028 /* No need to keep binary searching for the last few bits worth. */
1031 inc
= (inc
>> 1) + bot
;
1032 sym
= BLOCK_SYM (block
, inc
);
1033 if (SYMBOL_NAME (sym
)[0] < name
[0])
1035 else if (SYMBOL_NAME (sym
)[0] > name
[0])
1037 else if (strcmp (SYMBOL_NAME (sym
), name
) < 0)
1043 /* Now scan forward until we run out of symbols,
1044 find one whose name is greater than NAME,
1045 or find one we want.
1046 If there is more than one symbol with the right name and namespace,
1047 we return the first one. dbxread.c is careful to make sure
1048 that if one is a register then it comes first. */
1050 top
= BLOCK_NSYMS (block
);
1053 sym
= BLOCK_SYM (block
, bot
);
1054 inc
= SYMBOL_NAME (sym
)[0] - name
[0];
1056 inc
= strcmp (SYMBOL_NAME (sym
), name
);
1057 if (inc
== 0 && SYMBOL_NAMESPACE (sym
) == namespace)
1066 /* Here if block isn't sorted.
1067 This loop is equivalent to the loop above,
1068 but hacked greatly for speed.
1070 Note that parameter symbols do not always show up last in the
1071 list; this loop makes sure to take anything else other than
1072 parameter symbols first; it only uses parameter symbols as a
1073 last resort. Note that this only takes up extra computation
1076 parameter_sym
= (struct symbol
*) 0;
1077 top
= BLOCK_NSYMS (block
);
1081 sym
= BLOCK_SYM (block
, bot
);
1082 if (SYMBOL_NAME (sym
)[0] == inc
1083 && !strcmp (SYMBOL_NAME (sym
), name
)
1084 && SYMBOL_NAMESPACE (sym
) == namespace)
1086 if (SYMBOL_CLASS (sym
) == LOC_ARG
1087 || SYMBOL_CLASS (sym
) == LOC_REF_ARG
1088 || SYMBOL_CLASS (sym
) == LOC_REGPARM
)
1089 parameter_sym
= sym
;
1095 return parameter_sym
; /* Will be 0 if not found. */
1098 /* Return the symbol for the function which contains a specified
1099 lexical block, described by a struct block BL. */
1105 while (BLOCK_FUNCTION (bl
) == 0 && BLOCK_SUPERBLOCK (bl
) != 0)
1106 bl
= BLOCK_SUPERBLOCK (bl
);
1108 return BLOCK_FUNCTION (bl
);
1111 /* Subroutine of find_pc_line */
1115 register CORE_ADDR pc
;
1117 register struct block
*b
;
1118 struct blockvector
*bv
;
1119 register struct symtab
*s
;
1120 register struct partial_symtab
*ps
;
1122 /* Search all symtabs for one whose file contains our pc */
1124 for (s
= symtab_list
; s
; s
= s
->next
)
1126 bv
= BLOCKVECTOR (s
);
1127 b
= BLOCKVECTOR_BLOCK (bv
, 0);
1128 if (BLOCK_START (b
) <= pc
1129 && BLOCK_END (b
) > pc
)
1135 ps
= find_pc_psymtab (pc
);
1136 if (ps
&& ps
->readin
)
1137 fatal ("Internal error: pc in read in psymtab, but not in symtab.");
1140 s
= psymtab_to_symtab (ps
);
1146 /* Find the source file and line number for a given PC value.
1147 Return a structure containing a symtab pointer, a line number,
1148 and a pc range for the entire source line.
1149 The value's .pc field is NOT the specified pc.
1150 NOTCURRENT nonzero means, if specified pc is on a line boundary,
1151 use the line that ends there. Otherwise, in that case, the line
1152 that begins there is used. */
1154 struct symtab_and_line
1155 find_pc_line (pc
, notcurrent
)
1160 register struct linetable
*l
;
1163 register struct linetable_entry
*item
;
1164 struct symtab_and_line value
;
1165 struct blockvector
*bv
;
1167 /* Info on best line seen so far, and where it starts, and its file. */
1170 CORE_ADDR best_pc
= 0;
1171 CORE_ADDR best_end
= 0;
1172 struct symtab
*best_symtab
= 0;
1174 /* Store here the first line number
1175 of a file which contains the line at the smallest pc after PC.
1176 If we don't find a line whose range contains PC,
1177 we will use a line one less than this,
1178 with a range from the start of that file to the first line's pc. */
1180 CORE_ADDR alt_pc
= 0;
1181 struct symtab
*alt_symtab
= 0;
1183 /* Info on best line seen in this file. */
1188 /* Info on first line of this file. */
1193 /* If this pc is not from the current frame,
1194 it is the address of the end of a call instruction.
1195 Quite likely that is the start of the following statement.
1196 But what we want is the statement containing the instruction.
1197 Fudge the pc to make sure we get that. */
1199 if (notcurrent
) pc
-= 1;
1201 s
= find_pc_symtab (pc
);
1211 bv
= BLOCKVECTOR (s
);
1213 /* Look at all the symtabs that share this blockvector.
1214 They all have the same apriori range, that we found was right;
1215 but they have different line tables. */
1217 for (; s
&& BLOCKVECTOR (s
) == bv
; s
= s
->next
)
1219 /* Find the best line in this symtab. */
1224 for (i
= 0; i
< len
; i
++)
1226 item
= &(l
->item
[i
]);
1230 first_line
= item
->line
;
1231 first_pc
= item
->pc
;
1233 /* Return the last line that did not start after PC. */
1236 prev_line
= item
->line
;
1243 /* Is this file's best line closer than the best in the other files?
1244 If so, record this file, and its best line, as best so far. */
1245 if (prev_line
>= 0 && prev_pc
> best_pc
)
1248 best_line
= prev_line
;
1251 best_end
= item
->pc
;
1255 /* Is this file's first line closer than the first lines of other files?
1256 If so, record this file, and its first line, as best alternate. */
1257 if (first_line
>= 0 && first_pc
> pc
1258 && (alt_pc
== 0 || first_pc
< alt_pc
))
1261 alt_line
= first_line
;
1265 if (best_symtab
== 0)
1267 value
.symtab
= alt_symtab
;
1268 value
.line
= alt_line
- 1;
1269 value
.pc
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, 0));
1274 value
.symtab
= best_symtab
;
1275 value
.line
= best_line
;
1277 value
.end
= (best_end
? best_end
1279 : BLOCK_END (BLOCKVECTOR_BLOCK (bv
, 0))));
1284 /* Find the PC value for a given source file and line number.
1285 Returns zero for invalid line number.
1286 The source file is specified with a struct symtab. */
1289 find_line_pc (symtab
, line
)
1290 struct symtab
*symtab
;
1293 register struct linetable
*l
;
1299 l
= LINETABLE (symtab
);
1300 index
= find_line_common(l
, line
, &dummy
);
1301 return index
? l
->item
[index
].pc
: 0;
1304 /* Find the range of pc values in a line.
1305 Store the starting pc of the line into *STARTPTR
1306 and the ending pc (start of next line) into *ENDPTR.
1307 Returns 1 to indicate success.
1308 Returns 0 if could not find the specified line. */
1311 find_line_pc_range (symtab
, thisline
, startptr
, endptr
)
1312 struct symtab
*symtab
;
1314 CORE_ADDR
*startptr
, *endptr
;
1316 register struct linetable
*l
;
1318 int exact_match
; /* did we get an exact linenumber match */
1319 register CORE_ADDR prev_pc
;
1325 l
= LINETABLE (symtab
);
1326 index
= find_line_common (l
, thisline
, &exact_match
);
1329 *startptr
= l
->item
[index
].pc
;
1330 /* If we have not seen an entry for the specified line,
1331 assume that means the specified line has zero bytes. */
1332 if (!exact_match
|| index
== l
->nitems
-1)
1333 *endptr
= *startptr
;
1335 /* Perhaps the following entry is for the following line.
1336 It's worth a try. */
1337 if (l
->item
[index
+1].line
== thisline
+ 1)
1338 *endptr
= l
->item
[index
+1].pc
;
1340 *endptr
= find_line_pc (symtab
, thisline
+1);
1347 /* Given a line table and a line number, return the index into the line
1348 table for the pc of the nearest line whose number is >= the specified one.
1349 Return 0 if none is found. The value is never zero is it is an index.
1351 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
1354 find_line_common (l
, lineno
, exact_match
)
1355 register struct linetable
*l
;
1356 register int lineno
;
1362 /* BEST is the smallest linenumber > LINENO so far seen,
1363 or 0 if none has been seen so far.
1364 BEST_INDEX identifies the item for it. */
1375 for (i
= 0; i
< len
; i
++)
1377 register struct linetable_entry
*item
= &(l
->item
[i
]);
1379 if (item
->line
== lineno
)
1385 if (item
->line
> lineno
&& (best
== 0 || item
->line
< best
))
1392 /* If we got here, we didn't get an exact match. */
1399 find_pc_line_pc_range (pc
, startptr
, endptr
)
1401 CORE_ADDR
*startptr
, *endptr
;
1403 struct symtab_and_line sal
;
1404 sal
= find_pc_line (pc
, 0);
1407 return sal
.symtab
!= 0;
1410 /* Parse a string that specifies a line number.
1411 Pass the address of a char * variable; that variable will be
1412 advanced over the characters actually parsed.
1416 LINENUM -- that line number in current file. PC returned is 0.
1417 FILE:LINENUM -- that line in that file. PC returned is 0.
1418 FUNCTION -- line number of openbrace of that function.
1419 PC returned is the start of the function.
1420 FILE:FUNCTION -- likewise, but prefer functions in that file.
1421 *EXPR -- line in which address EXPR appears.
1423 FUNCTION may be an undebuggable function found in misc_function_vector.
1425 If the argument FUNFIRSTLINE is nonzero, we want the first line
1426 of real code inside a function when a function is specified.
1428 DEFAULT_SYMTAB specifies the file to use if none is specified.
1429 It defaults to current_source_symtab.
1430 DEFAULT_LINE specifies the line number to use for relative
1431 line numbers (that start with signs). Defaults to current_source_line.
1433 Note that it is possible to return zero for the symtab
1434 if no file is validly specified. Callers must check that.
1435 Also, the line number returned may be invalid. */
1437 struct symtabs_and_lines
1438 decode_line_1 (argptr
, funfirstline
, default_symtab
, default_line
)
1441 struct symtab
*default_symtab
;
1444 struct symtabs_and_lines
decode_line_2 ();
1445 struct symtabs_and_lines values
;
1446 struct symtab_and_line value
;
1447 register char *p
, *p1
;
1448 register struct symtab
*s
;
1449 register struct symbol
*sym
;
1450 register CORE_ADDR pc
;
1453 struct symbol
*sym_class
;
1454 char *class_name
, *method_name
, *phys_name
;
1457 struct symbol
**sym_arr
;
1458 struct type
*t
, *field
;
1461 /* Defaults have defaults. */
1463 if (default_symtab
== 0)
1465 default_symtab
= current_source_symtab
;
1466 default_line
= current_source_line
;
1469 /* See if arg is *PC */
1471 if (**argptr
== '*')
1474 pc
= parse_and_eval_address_1 (argptr
);
1475 values
.sals
= (struct symtab_and_line
*)
1476 malloc (sizeof (struct symtab_and_line
));
1478 values
.sals
[0] = find_pc_line (pc
, 0);
1479 values
.sals
[0].pc
= pc
;
1483 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
1487 for (p
= *argptr
; *p
; p
++)
1489 if (p
[0] == ':' || p
[0] == ' ' || p
[0] == '\t')
1492 while (p
[0] == ' ' || p
[0] == '\t') p
++;
1500 /* Extract the class name. */
1502 while (p
!= *argptr
&& p
[-1] == ' ') --p
;
1503 copy
= (char *) alloca (p
- *argptr
+ 1);
1504 bcopy (*argptr
, copy
, p
- *argptr
);
1505 copy
[p
- *argptr
] = 0;
1507 /* Discard the class name from the arg. */
1509 while (*p
== ' ' || *p
== '\t') p
++;
1512 sym_class
= lookup_symbol (copy
, 0, STRUCT_NAMESPACE
, 0);
1515 (TYPE_CODE (SYMBOL_TYPE (sym_class
)) == TYPE_CODE_STRUCT
1516 || TYPE_CODE (SYMBOL_TYPE (sym_class
)) == TYPE_CODE_UNION
))
1518 /* Arg token is not digits => try it as a function name
1519 Find the next token (everything up to end or next whitespace). */
1521 while (*p
&& *p
!= ' ' && *p
!= '\t' && *p
!= ',' && *p
!=':') p
++;
1522 copy
= (char *) alloca (p
- *argptr
+ 1);
1523 bcopy (*argptr
, copy
, p
- *argptr
);
1524 copy
[p
- *argptr
] = '\0';
1526 /* no line number may be specified */
1527 while (*p
== ' ' || *p
== '\t') p
++;
1531 i1
= 0; /* counter for the symbol array */
1532 t
= SYMBOL_TYPE (sym_class
);
1533 sym_arr
= (struct symbol
**) alloca(TYPE_NFN_FIELDS_TOTAL (t
) * sizeof(struct symbol
*));
1534 physnames
= (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t
) * sizeof(char*));
1536 if (destructor_name_p (copy
, t
))
1538 /* destructors are a special case. */
1539 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, 0);
1540 int len
= TYPE_FN_FIELDLIST_LENGTH (t
, 0) - 1;
1541 phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, len
);
1542 physnames
[i1
] = (char *)alloca (strlen (phys_name
) + 1);
1543 strcpy (physnames
[i1
], phys_name
);
1544 sym_arr
[i1
] = lookup_symbol (phys_name
, SYMBOL_BLOCK_VALUE (sym_class
), VAR_NAMESPACE
, 0);
1545 if (sym_arr
[i1
]) i1
++;
1549 class_name
= TYPE_NAME (t
);
1550 /* Ignore this class if it doesn't have a name.
1551 This prevents core dumps, but is just a workaround
1552 because we might not find the function in
1553 certain cases, such as
1554 struct D {virtual int f();}
1555 struct C : D {virtual int g();}
1556 (in this case g++ 1.35.1- does not put out a name
1557 for D as such, it defines type 19 (for example) in
1558 the same stab as C, and then does a
1559 .stabs "D:T19" and a .stabs "D:t19".
1561 "break C::f" should not be looking for field f in
1563 but just for the field f in the baseclasses of C
1564 (no matter what their names).
1566 However, I don't know how to replace the code below
1567 that depends on knowing the name of D. */
1570 /* We just want the class name. In the context
1571 of C++, stripping off "struct " is always
1573 if (strncmp("struct ", class_name
, 7) == 0)
1575 if (strncmp("union ", class_name
, 6) == 0)
1578 sym_class
= lookup_symbol (class_name
, 0, STRUCT_NAMESPACE
, 0);
1579 for (method_counter
= TYPE_NFN_FIELDS (SYMBOL_TYPE (sym_class
)) - 1;
1580 method_counter
>= 0;
1584 struct fn_field
*f
=
1585 TYPE_FN_FIELDLIST1 (SYMBOL_TYPE (sym_class
), method_counter
);
1587 method_name
= TYPE_FN_FIELDLIST_NAME (SYMBOL_TYPE (sym_class
), method_counter
);
1588 if (!strcmp (copy
, method_name
))
1589 /* Find all the fields with that name. */
1590 for (field_counter
= TYPE_FN_FIELDLIST_LENGTH (SYMBOL_TYPE (sym_class
), method_counter
) - 1;
1594 phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, field_counter
);
1595 physnames
[i1
] = (char*) alloca (strlen (phys_name
) + 1);
1596 strcpy (physnames
[i1
], phys_name
);
1597 sym_arr
[i1
] = lookup_symbol (phys_name
, SYMBOL_BLOCK_VALUE (sym_class
), VAR_NAMESPACE
, 0);
1598 if (sym_arr
[i1
]) i1
++;
1602 if (TYPE_N_BASECLASSES (t
))
1603 t
= TYPE_BASECLASS(t
, 1);
1610 /* There is exactly one field with that name. */
1613 if (sym
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1615 /* Arg is the name of a function */
1616 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) + FUNCTION_START_OFFSET
;
1619 values
.sals
= (struct symtab_and_line
*)malloc (sizeof (struct symtab_and_line
));
1621 values
.sals
[0] = find_pc_line (pc
, 0);
1622 values
.sals
[0].pc
= (values
.sals
[0].end
&& values
.sals
[0].pc
!= pc
) ? values
.sals
[0].end
: pc
;
1632 /* There is more than one field with that name
1633 (overloaded). Ask the user which one to use. */
1634 return decode_line_2 (argptr
, sym_arr
, physnames
,
1638 error ("that class does not have any method named %s",copy
);
1641 error("no class, struct, or union named %s", copy
);
1646 /* Extract the file name. */
1648 while (p
!= *argptr
&& p
[-1] == ' ') --p
;
1649 copy
= (char *) alloca (p
- *argptr
+ 1);
1650 bcopy (*argptr
, copy
, p
- *argptr
);
1651 copy
[p
- *argptr
] = 0;
1653 /* Find that file's data. */
1654 s
= lookup_symtab (copy
);
1657 if (symtab_list
== 0 && partial_symtab_list
== 0)
1658 error ("No symbol table is loaded. Use the \"symbol-file\" command.");
1659 error ("No source file named %s.", copy
);
1662 /* Discard the file name from the arg. */
1664 while (*p
== ' ' || *p
== '\t') p
++;
1668 /* S is specified file's symtab, or 0 if no file specified.
1669 arg no longer contains the file name. */
1671 /* Check whether arg is all digits (and sign) */
1674 if (*p
== '-' || *p
== '+') p
++;
1675 while (*p
>= '0' && *p
<= '9')
1678 if (p
!= *argptr
&& (*p
== 0 || *p
== ' ' || *p
== '\t' || *p
== ','))
1680 /* We found a token consisting of all digits -- at least one digit. */
1681 enum sign
{none
, plus
, minus
} sign
= none
;
1683 /* This is where we need to make sure that we have good defaults.
1684 We must guarrantee that this section of code is never executed
1685 when we are called with just a function name, since
1686 select_source_symtab calls us with such an argument */
1688 if (s
== 0 && default_symtab
== 0)
1690 if (symtab_list
== 0 && partial_symtab_list
== 0)
1691 error ("No symbol table is loaded. Use the \"symbol-file\" command.");
1692 select_source_symtab (0);
1693 default_symtab
= current_source_symtab
;
1694 default_line
= current_source_line
;
1697 if (**argptr
== '+')
1698 sign
= plus
, (*argptr
)++;
1699 else if (**argptr
== '-')
1700 sign
= minus
, (*argptr
)++;
1701 value
.line
= atoi (*argptr
);
1708 value
.line
= default_line
+ value
.line
;
1714 value
.line
= default_line
- value
.line
;
1720 while (*p
== ' ' || *p
== '\t') p
++;
1726 values
.sals
= (struct symtab_and_line
*)malloc (sizeof (struct symtab_and_line
));
1727 values
.sals
[0] = value
;
1732 /* Arg token is not digits => try it as a function name
1733 Find the next token (everything up to end or next whitespace). */
1735 while (*p
&& *p
!= ' ' && *p
!= '\t' && *p
!= ',') p
++;
1736 copy
= (char *) alloca (p
- *argptr
+ 1);
1737 bcopy (*argptr
, copy
, p
- *argptr
);
1738 copy
[p
- *argptr
] = 0;
1739 while (*p
== ' ' || *p
== '\t') p
++;
1742 /* Look up that token as a function.
1743 If file specified, use that file's per-file block to start with. */
1745 sym
= lookup_symbol (copy
, s
? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), 1) : 0,
1748 if (sym
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1750 /* Arg is the name of a function */
1751 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) + FUNCTION_START_OFFSET
;
1754 value
= find_pc_line (pc
, 0);
1755 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
1756 /* Convex: no need to suppress code on first line, if any */
1759 value
.pc
= (value
.end
&& value
.pc
!= pc
) ? value
.end
: pc
;
1761 values
.sals
= (struct symtab_and_line
*)malloc (sizeof (struct symtab_and_line
));
1762 values
.sals
[0] = value
;
1768 error ("%s is not a function.", copy
);
1770 if ((i
= lookup_misc_func (copy
)) < 0)
1771 error ("Function %s not defined.", copy
);
1776 value
.pc
= misc_function_vector
[i
].address
+ FUNCTION_START_OFFSET
;
1778 SKIP_PROLOGUE (value
.pc
);
1779 values
.sals
= (struct symtab_and_line
*)malloc (sizeof (struct symtab_and_line
));
1780 values
.sals
[0] = value
;
1785 if (symtab_list
== 0 && partial_symtab_list
== 0)
1786 error ("No symbol table is loaded. Use the \"symbol-file\" command.");
1787 error ("Function %s not defined.", copy
);
1790 struct symtabs_and_lines
1791 decode_line_spec (string
, funfirstline
)
1795 struct symtabs_and_lines sals
;
1797 error ("Empty line specification.");
1798 sals
= decode_line_1 (&string
, funfirstline
,
1799 current_source_symtab
, current_source_line
);
1801 error ("Junk at end of line specification: %s", string
);
1805 /* Given a list of NELTS symbols in sym_arr (with corresponding
1806 mangled names in physnames), return a list of lines to operate on
1807 (ask user if necessary). */
1808 struct symtabs_and_lines
1809 decode_line_2 (argptr
, sym_arr
, physnames
, nelts
, funfirstline
)
1811 struct symbol
*sym_arr
[];
1817 struct symtabs_and_lines values
, return_values
;
1818 register CORE_ADDR pc
;
1819 char *args
, *arg1
, *command_line_input ();
1823 values
.sals
= (struct symtab_and_line
*) alloca (nelts
* sizeof(struct symtab_and_line
));
1824 return_values
.sals
= (struct symtab_and_line
*) malloc (nelts
* sizeof(struct symtab_and_line
));
1827 printf("[0] cancel\n[1] all\n");
1830 if (sym_arr
[i
] && SYMBOL_CLASS (sym_arr
[i
]) == LOC_BLOCK
)
1832 /* Arg is the name of a function */
1833 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym_arr
[i
]))
1834 + FUNCTION_START_OFFSET
;
1837 values
.sals
[i
] = find_pc_line (pc
, 0);
1838 printf("[%d] file:%s; line number:%d\n",
1839 (i
+2), values
.sals
[i
].symtab
->filename
, values
.sals
[i
].line
);
1841 else printf ("?HERE\n");
1845 if ((prompt
= getenv ("PS2")) == NULL
)
1849 printf("%s ",prompt
);
1852 args
= command_line_input (0, 0);
1855 error_no_arg ("one or more choice numbers");
1863 while (*arg1
>= '0' && *arg1
<= '9') arg1
++;
1864 if (*arg1
&& *arg1
!= ' ' && *arg1
!= '\t')
1865 error ("Arguments must be choice numbers.");
1870 error ("cancelled");
1873 bcopy (values
.sals
, return_values
.sals
, (nelts
* sizeof(struct symtab_and_line
)));
1874 return_values
.nelts
= nelts
;
1875 return return_values
;
1878 if (num
> nelts
+ 2)
1880 printf ("No choice number %d.\n", num
);
1885 if (values
.sals
[num
].pc
)
1887 return_values
.sals
[i
++] = values
.sals
[num
];
1888 values
.sals
[num
].pc
= 0;
1892 printf ("duplicate request for %d ignored.\n", num
);
1897 while (*args
== ' ' || *args
== '\t') args
++;
1899 return_values
.nelts
= i
;
1900 return return_values
;
1903 /* Return the index of misc function named NAME. */
1906 lookup_misc_func (name
)
1907 register char *name
;
1911 for (i
= 0; i
< misc_function_count
; i
++)
1912 if (!strcmp (misc_function_vector
[i
].name
, name
))
1914 return -1; /* not found */
1918 * Slave routine for sources_info. Force line breaks at ,'s.
1921 output_source_filename (name
, next
)
1925 static int column
= 0;
1927 if (column
!= 0 && column
+ strlen (name
) >= 70)
1929 printf_filtered ("\n");
1932 else if (column
!= 0)
1934 printf_filtered (" ");
1937 printf_filtered ("%s", name
);
1938 column
+= strlen (name
);
1941 printf_filtered (",");
1945 if (!next
) column
= 0;
1951 register struct symtab
*s
;
1952 register struct partial_symtab
*ps
;
1953 register int column
= 0;
1955 if (symtab_list
== 0 && partial_symtab_list
== 0)
1957 printf ("No symbol table is loaded.\n");
1961 printf_filtered ("Source files for which symbols have been read in:\n\n");
1963 for (s
= symtab_list
; s
; s
= s
->next
)
1964 output_source_filename (s
->filename
, s
->next
);
1965 printf_filtered ("\n\n");
1967 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
1969 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
1971 output_source_filename (ps
->filename
, ps
->next
);
1972 printf_filtered ("\n");
1975 /* List all symbols (if REGEXP is 0) or all symbols matching REGEXP.
1976 If CLASS is zero, list all symbols except functions and type names.
1977 If CLASS is 1, list only functions.
1978 If CLASS is 2, list only type names. */
1980 static void sort_block_syms ();
1983 list_symbols (regexp
, class)
1987 register struct symtab
*s
;
1988 register struct partial_symtab
*ps
;
1989 register struct blockvector
*bv
;
1990 struct blockvector
*prev_bv
= 0;
1991 register struct block
*b
;
1993 register struct symbol
*sym
;
1994 struct partial_symbol
*psym
;
1996 static char *classnames
[]
1997 = {"variable", "function", "type", "method"};
1998 int print_count
= 0;
1999 int found_in_file
= 0;
2002 if (val
= (char *) re_comp (regexp
))
2003 error ("Invalid regexp: %s", val
);
2005 /* Search through the partial_symtab_list *first* for all symbols
2006 matching the regexp. That way we don't have to reproduce all of
2007 the machinery below. */
2008 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
2010 struct partial_symbol
*bound
, *gbound
, *sbound
;
2013 if (ps
->readin
) continue;
2015 gbound
= global_psymbols
.list
+ ps
->globals_offset
+ ps
->n_global_syms
;
2016 sbound
= static_psymbols
.list
+ ps
->statics_offset
+ ps
->n_static_syms
;
2019 /* Go through all of the symbols stored in a partial
2020 symtab in one loop. */
2021 psym
= global_psymbols
.list
+ ps
->globals_offset
;
2026 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
2028 psym
= static_psymbols
.list
+ ps
->statics_offset
;
2038 /* If it would match (logic taken from loop below)
2039 load the file and go on to the next one */
2040 if ((regexp
== 0 || re_exec (SYMBOL_NAME (psym
)))
2041 && ((class == 0 && SYMBOL_CLASS (psym
) != LOC_TYPEDEF
2042 && SYMBOL_CLASS (psym
) != LOC_BLOCK
)
2043 || (class == 1 && SYMBOL_CLASS (psym
) == LOC_BLOCK
)
2044 || (class == 2 && SYMBOL_CLASS (psym
) == LOC_TYPEDEF
)
2045 || (class == 3 && SYMBOL_CLASS (psym
) == LOC_BLOCK
)))
2047 psymtab_to_symtab(ps
);
2055 /* Printout here so as to get after the "Reading in symbols"
2056 messages which will be generated above. */
2057 printf_filtered (regexp
2058 ? "All %ss matching regular expression \"%s\":\n"
2059 : "All defined %ss:\n",
2063 /* Here, *if* the class is correct (function only, right now), we
2064 should search through the misc function vector for symbols that
2065 match and call find_pc_psymtab on them. If find_pc_psymtab returns
2066 0, don't worry about it (already read in or no debugging info). */
2070 for (i
= 0; i
< misc_function_count
; i
++)
2071 if (regexp
== 0 || re_exec (misc_function_vector
[i
].name
))
2073 ps
= find_pc_psymtab (misc_function_vector
[i
].address
);
2074 if (ps
&& !ps
->readin
)
2075 psymtab_to_symtab (ps
);
2079 for (s
= symtab_list
; s
; s
= s
->next
)
2082 bv
= BLOCKVECTOR (s
);
2083 /* Often many files share a blockvector.
2084 Scan each blockvector only once so that
2085 we don't get every symbol many times.
2086 It happens that the first symtab in the list
2087 for any given blockvector is the main file. */
2089 for (i
= 0; i
< 2; i
++)
2091 b
= BLOCKVECTOR_BLOCK (bv
, i
);
2092 /* Skip the sort if this block is always sorted. */
2093 if (!BLOCK_SHOULD_SORT (b
))
2094 sort_block_syms (b
);
2095 for (j
= 0; j
< BLOCK_NSYMS (b
); j
++)
2098 sym
= BLOCK_SYM (b
, j
);
2099 if ((regexp
== 0 || re_exec (SYMBOL_NAME (sym
)))
2100 && ((class == 0 && SYMBOL_CLASS (sym
) != LOC_TYPEDEF
2101 && SYMBOL_CLASS (sym
) != LOC_BLOCK
)
2102 || (class == 1 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
2103 || (class == 2 && SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
2104 || (class == 3 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)))
2108 printf_filtered ("\nFile %s:\n", s
->filename
);
2112 if (class != 2 && i
== 1)
2113 printf_filtered ("static ");
2115 && SYMBOL_NAMESPACE (sym
) != STRUCT_NAMESPACE
)
2116 printf_filtered ("typedef ");
2120 type_print (SYMBOL_TYPE (sym
),
2121 (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
2122 ? "" : SYMBOL_NAME (sym
)),
2126 && SYMBOL_NAMESPACE (sym
) != STRUCT_NAMESPACE
2127 && (TYPE_NAME ((SYMBOL_TYPE (sym
))) == 0
2128 || 0 != strcmp (TYPE_NAME ((SYMBOL_TYPE (sym
))),
2129 SYMBOL_NAME (sym
))))
2130 printf_filtered (" %s", SYMBOL_NAME (sym
));
2132 printf_filtered (";\n");
2138 type_print_base (TYPE_FN_FIELD_TYPE(t
, i
), stdout
, 0, 0);
2139 type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t
, i
), stdout
, 0);
2140 sprintf (buf
, " %s::", TYPE_NAME (t
));
2141 type_print_method_args (TYPE_FN_FIELD_ARGS (t
, i
), buf
, name
, stdout
);
2152 variables_info (regexp
)
2155 list_symbols (regexp
, 0);
2159 functions_info (regexp
)
2162 list_symbols (regexp
, 1);
2169 list_symbols (regexp
, 2);
2173 /* Tiemann says: "info methods was never implemented." */
2175 methods_info (regexp
)
2178 list_symbols (regexp
, 3);
2182 /* Call sort_block_syms to sort alphabetically the symbols of one block. */
2185 compare_symbols (s1
, s2
)
2186 struct symbol
**s1
, **s2
;
2188 /* Names that are less should come first. */
2189 register int namediff
= strcmp (SYMBOL_NAME (*s1
), SYMBOL_NAME (*s2
));
2190 if (namediff
!= 0) return namediff
;
2191 /* For symbols of the same name, registers should come first. */
2192 return ((SYMBOL_CLASS (*s2
) == LOC_REGISTER
)
2193 - (SYMBOL_CLASS (*s1
) == LOC_REGISTER
));
2198 register struct block
*b
;
2200 qsort (&BLOCK_SYM (b
, 0), BLOCK_NSYMS (b
),
2201 sizeof (struct symbol
*), compare_symbols
);
2204 /* Initialize the standard C scalar types. */
2208 init_type (code
, length
, uns
, name
)
2209 enum type_code code
;
2213 register struct type
*type
;
2215 type
= (struct type
*) xmalloc (sizeof (struct type
));
2216 bzero (type
, sizeof *type
);
2217 TYPE_MAIN_VARIANT (type
) = type
;
2218 TYPE_CODE (type
) = code
;
2219 TYPE_LENGTH (type
) = length
;
2220 TYPE_FLAGS (type
) = uns
? TYPE_FLAG_UNSIGNED
: 0;
2221 TYPE_FLAGS (type
) |= TYPE_FLAG_PERM
;
2222 TYPE_NFIELDS (type
) = 0;
2223 TYPE_NAME (type
) = name
;
2226 TYPE_NFN_FIELDS (type
) = 0;
2227 TYPE_N_BASECLASSES (type
) = 0;
2228 TYPE_BASECLASSES (type
) = 0;
2232 /* Return Nonzero if block a is lexically nested within block b,
2233 or if a and b have the same pc range.
2234 Return zero otherwise. */
2237 struct block
*a
, *b
;
2241 return a
->startaddr
>= b
->startaddr
&& a
->endaddr
<= b
->endaddr
;
2245 /* Helper routine for make_symbol_completion_list. */
2247 int return_val_size
, return_val_index
;
2251 completion_list_add_symbol (symname
)
2254 if (return_val_index
+ 3 > return_val_size
)
2256 (char **)xrealloc (return_val
,
2257 (return_val_size
*= 2) * sizeof (char *));
2259 return_val
[return_val_index
] =
2260 (char *)xmalloc (1 + strlen (symname
));
2262 strcpy (return_val
[return_val_index
], symname
);
2264 return_val
[++return_val_index
] = (char *)NULL
;
2267 /* Return a NULL terminated array of all symbols (regardless of class) which
2268 begin by matching TEXT. If the answer is no symbols, then the return value
2269 is an array which contains only a NULL pointer.
2271 Problem: All of the symbols have to be copied because readline
2272 frees them. I'm not going to worry about this; hopefully there
2273 won't be that many. */
2276 make_symbol_completion_list (text
)
2279 register struct symtab
*s
;
2280 register struct partial_symtab
*ps
;
2281 register struct blockvector
*bv
;
2282 struct blockvector
*prev_bv
= 0;
2283 register struct block
*b
, *surrounding_static_block
;
2284 extern struct block
*get_selected_block ();
2286 register struct symbol
*sym
;
2287 struct partial_symbol
*psym
;
2289 int text_len
= strlen (text
);
2290 return_val_size
= 100;
2291 return_val_index
= 0;
2293 (char **)xmalloc ((1 + return_val_size
) *sizeof (char *));
2294 return_val
[0] = (char *)NULL
;
2296 /* Look through the partial symtabs for all symbols which begin
2297 by matching TEXT. Add each one that you find to the list. */
2299 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
2301 /* If the psymtab's been read in we'll get it when we search
2302 through the blockvector. */
2303 if (ps
->readin
) continue;
2305 for (psym
= global_psymbols
.list
+ ps
->globals_offset
;
2306 psym
< (global_psymbols
.list
+ ps
->globals_offset
2307 + ps
->n_global_syms
);
2310 QUIT
; /* If interrupted, then quit. */
2311 if ((strncmp (SYMBOL_NAME (psym
), text
, text_len
) == 0))
2312 completion_list_add_symbol (SYMBOL_NAME (psym
));
2315 for (psym
= static_psymbols
.list
+ ps
->statics_offset
;
2316 psym
< (static_psymbols
.list
+ ps
->statics_offset
2317 + ps
->n_static_syms
);
2321 if ((strncmp (SYMBOL_NAME (psym
), text
, text_len
) == 0))
2322 completion_list_add_symbol (SYMBOL_NAME (psym
));
2326 /* At this point scan through the misc function vector and add each
2327 symbol you find to the list. Eventually we want to ignore
2328 anything that isn't a text symbol (everything else will be
2329 handled by the psymtab code above). */
2331 for (i
= 0; i
< misc_function_count
; i
++)
2332 if (!strncmp (text
, misc_function_vector
[i
].name
, text_len
))
2333 completion_list_add_symbol (misc_function_vector
[i
].name
);
2335 /* Search upwards from currently selected frame (so that we can
2336 complete on local vars. */
2337 for (b
= get_selected_block (); b
; b
= BLOCK_SUPERBLOCK (b
))
2339 if (!BLOCK_SUPERBLOCK (b
))
2340 surrounding_static_block
= b
; /* For elmin of dups */
2342 /* Also catch fields of types defined in this places which
2343 match our text string. Only complete on types visible
2344 from current context. */
2345 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2347 register struct symbol
*sym
= BLOCK_SYM (b
, i
);
2349 if (!strncmp (SYMBOL_NAME (sym
), text
, text_len
))
2350 completion_list_add_symbol (SYMBOL_NAME (sym
));
2352 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
2354 struct type
*t
= SYMBOL_TYPE (sym
);
2355 enum type_code c
= TYPE_CODE (t
);
2357 if (c
== TYPE_CODE_UNION
|| c
== TYPE_CODE_STRUCT
)
2358 for (j
= 0; j
< TYPE_NFIELDS (t
); j
++)
2359 if (TYPE_FIELD_NAME (t
, j
) &&
2360 !strncmp (TYPE_FIELD_NAME (t
, j
), text
, text_len
))
2361 completion_list_add_symbol (TYPE_FIELD_NAME (t
, j
));
2366 /* Go through the symtabs and check the externs and statics for
2367 symbols which match. */
2369 for (s
= symtab_list
; s
; s
= s
->next
)
2371 struct block
*b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), 0);
2373 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2374 if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b
, i
)), text
, text_len
))
2375 completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b
, i
)));
2378 for (s
= symtab_list
; s
; s
= s
->next
)
2380 struct block
*b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), 1);
2382 /* Don't do this block twice. */
2383 if (b
== surrounding_static_block
) continue;
2385 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2386 if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b
, i
)), text
, text_len
))
2387 completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b
, i
)));
2390 return (return_val
);
2394 _initialize_symtab ()
2396 add_info ("variables", variables_info
,
2397 "All global and static variable names, or those matching REGEXP.");
2398 add_info ("functions", functions_info
,
2399 "All function names, or those matching REGEXP.");
2400 add_info ("types", types_info
,
2401 "All types names, or those matching REGEXP.");
2403 add_info ("methods", methods_info
,
2404 "All method names, or those matching REGEXP::REGEXP.\n\
2405 If the class qualifier is ommited, it is assumed to be the current scope.\n\
2406 If the first REGEXP is ommited, then all methods matching the second REGEXP\n\
2409 add_info ("sources", sources_info
,
2410 "Source files in the program.");
2412 obstack_init (symbol_obstack
);
2413 obstack_init (psymbol_obstack
);
2415 builtin_type_void
= init_type (TYPE_CODE_VOID
, 1, 0, "void");
2417 builtin_type_float
= init_type (TYPE_CODE_FLT
, sizeof (float), 0, "float");
2418 builtin_type_double
= init_type (TYPE_CODE_FLT
, sizeof (double), 0, "double");
2420 builtin_type_char
= init_type (TYPE_CODE_INT
, sizeof (char), 0, "char");
2421 builtin_type_short
= init_type (TYPE_CODE_INT
, sizeof (short), 0, "short");
2422 builtin_type_long
= init_type (TYPE_CODE_INT
, sizeof (long), 0, "long");
2423 builtin_type_int
= init_type (TYPE_CODE_INT
, sizeof (int), 0, "int");
2425 builtin_type_unsigned_char
= init_type (TYPE_CODE_INT
, sizeof (char), 1, "unsigned char");
2426 builtin_type_unsigned_short
= init_type (TYPE_CODE_INT
, sizeof (short), 1, "unsigned short");
2427 builtin_type_unsigned_long
= init_type (TYPE_CODE_INT
, sizeof (long), 1, "unsigned long");
2428 builtin_type_unsigned_int
= init_type (TYPE_CODE_INT
, sizeof (int), 1, "unsigned int");
2430 builtin_type_long_long
=
2431 init_type (TYPE_CODE_INT
, sizeof (long long), 0, "long long");
2432 builtin_type_unsigned_long_long
=
2433 init_type (TYPE_CODE_INT
, sizeof (long long), 1, "unsigned long long");