1 /* Symbol table lookup for the GNU debugger, GDB.
2 Copyright (C) 1986, 1987, 1988, 1989, 1990 Free Software Foundation, Inc.
4 This file is part of GDB.
6 GDB is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 1, or (at your option)
11 GDB is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GDB; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
34 #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 /* These variables point to the objects
56 representing the predefined C data types. */
58 struct type
*builtin_type_void
;
59 struct type
*builtin_type_char
;
60 struct type
*builtin_type_short
;
61 struct type
*builtin_type_int
;
62 struct type
*builtin_type_long
;
64 struct type
*builtin_type_long_long
;
66 struct type
*builtin_type_unsigned_char
;
67 struct type
*builtin_type_unsigned_short
;
68 struct type
*builtin_type_unsigned_int
;
69 struct type
*builtin_type_unsigned_long
;
71 struct type
*builtin_type_unsigned_long_long
;
73 struct type
*builtin_type_float
;
74 struct type
*builtin_type_double
;
75 struct type
*builtin_type_error
;
77 /* Block in which the most recently searched-for symbol was found.
78 Might be better to make this a parameter to lookup_symbol and
80 struct block
*block_found
;
82 char no_symtab_msg
[] = "No symbol table is loaded. Use the \"file\" command.";
84 /* Check for a symtab of a specific name; first in symtabs, then in
85 psymtabs. *If* there is no '/' in the name, a match after a '/'
86 in the symtab filename will also work. */
88 static struct symtab
*
89 lookup_symtab_1 (name
)
92 register struct symtab
*s
;
93 register struct partial_symtab
*ps
;
94 register char *slash
= strchr (name
, '/');
95 register int len
= strlen (name
);
97 for (s
= symtab_list
; s
; s
= s
->next
)
98 if (!strcmp (name
, s
->filename
))
101 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
102 if (!strcmp (name
, ps
->filename
))
105 fatal ("Internal: readin pst found when no symtab found.");
106 return PSYMTAB_TO_SYMTAB (ps
);
111 for (s
= symtab_list
; s
; s
= s
->next
)
113 int l
= strlen (s
->filename
);
115 if (s
->filename
[l
- len
-1] == '/'
116 && !strcmp (s
->filename
+ l
- len
, name
))
120 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
122 int l
= strlen (ps
->filename
);
124 if (ps
->filename
[l
- len
- 1] == '/'
125 && !strcmp (ps
->filename
+ l
- len
, name
))
128 fatal ("Internal: readin pst found when no symtab found.");
129 return PSYMTAB_TO_SYMTAB (ps
);
136 /* Lookup the symbol table of a source file named NAME. Try a couple
137 of variations if the first lookup doesn't work. */
143 register struct symtab
*s
;
146 s
= lookup_symtab_1 (name
);
149 /* If name not found as specified, see if adding ".c" helps. */
151 copy
= (char *) alloca (strlen (name
) + 3);
154 s
= lookup_symtab_1 (copy
);
157 /* We didn't find anything; die. */
161 /* Lookup the partial symbol table of a source file named NAME. This
162 only returns true on an exact match (ie. this semantics are
163 different from lookup_symtab. */
165 struct partial_symtab
*
166 lookup_partial_symtab (name
)
169 register struct partial_symtab
*s
;
171 for (s
= partial_symtab_list
; s
; s
= s
->next
)
172 if (!strcmp (name
, s
->filename
))
178 /* Return a typename for a struct/union/enum type
179 without the tag qualifier. If the type has a NULL name,
182 type_name_no_tag (type
)
183 register struct type
*type
;
185 register char *name
= TYPE_NAME (type
);
191 switch (TYPE_CODE (type
))
193 case TYPE_CODE_STRUCT
:
195 case TYPE_CODE_UNION
:
202 name
= strchr (name
, ' ');
206 return TYPE_NAME (type
);
209 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
211 If this is a stubbed struct (i.e. declared as struct foo *), see if
212 we can find a full definition in some other file. If so, copy this
213 definition, so we can use it in future. If not, set a flag so we
214 don't waste too much time in future.
216 This used to be coded as a macro, but I don't think it is called
217 often enough to merit such treatment.
220 struct complaint stub_noname_complaint
=
221 {"stub type has NULL name", 0, 0};
224 check_stub_type(type
)
227 if (TYPE_FLAGS(type
) & TYPE_FLAG_STUB
)
229 char* name
= type_name_no_tag (type
);
233 complain (&stub_noname_complaint
, 0, 0);
236 if (sym
= lookup_symbol (name
, 0, STRUCT_NAMESPACE
, 0,
237 (struct symtab
**)NULL
) )
238 bcopy (SYMBOL_TYPE(sym
), type
, sizeof (struct type
));
242 /* Demangle a GDB method stub type. */
244 gdb_mangle_typename (type
)
247 static struct type
*last_type
;
248 static char *mangled_typename
;
250 if (type
!= last_type
)
252 /* Need a new type prefix. */
254 char *newname
= type_name_no_tag (type
);
258 if (mangled_typename
)
259 free (mangled_typename
);
261 len
= strlen (newname
);
262 sprintf (buf
, "__%d", len
);
263 mangled_typename
= (char *)xmalloc (strlen (buf
) + len
+ 1);
264 strcpy (mangled_typename
, buf
);
265 strcat (mangled_typename
, newname
);
266 /* Now we have built "__#newname". */
268 return mangled_typename
;
271 /* Lookup a primitive type named NAME.
272 Return zero if NAME is not a primitive type.*/
275 lookup_primitive_typename (name
)
278 if (!strcmp (name
, "int"))
279 return builtin_type_int
;
280 if (!strcmp (name
, "long"))
281 return builtin_type_long
;
282 if (!strcmp (name
, "short"))
283 return builtin_type_short
;
284 if (!strcmp (name
, "char"))
285 return builtin_type_char
;
286 if (!strcmp (name
, "float"))
287 return builtin_type_float
;
288 if (!strcmp (name
, "double"))
289 return builtin_type_double
;
290 if (!strcmp (name
, "void"))
291 return builtin_type_void
;
295 /* Lookup a typedef or primitive type named NAME,
296 visible in lexical block BLOCK.
297 If NOERR is nonzero, return zero if NAME is not suitably defined. */
300 lookup_typename (name
, block
, noerr
)
305 register struct symbol
*sym
=
306 lookup_symbol (name
, block
, VAR_NAMESPACE
, 0, (struct symtab
**)NULL
);
307 if (sym
== 0 || SYMBOL_CLASS (sym
) != LOC_TYPEDEF
)
310 tmp
= lookup_primitive_typename (name
);
313 error ("No type named %s.", name
);
315 return SYMBOL_TYPE (sym
);
319 lookup_unsigned_typename (name
)
322 if (!strcmp (name
, "int"))
323 return builtin_type_unsigned_int
;
324 if (!strcmp (name
, "long"))
325 return builtin_type_unsigned_long
;
326 if (!strcmp (name
, "short"))
327 return builtin_type_unsigned_short
;
328 if (!strcmp (name
, "char"))
329 return builtin_type_unsigned_char
;
330 error ("No type named unsigned %s.", name
);
331 return (struct type
*)-1; /* for lint */
334 /* Lookup a structure type named "struct NAME",
335 visible in lexical block BLOCK. */
338 lookup_struct (name
, block
)
342 register struct symbol
*sym
343 = lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0, (struct symtab
**)NULL
);
346 error ("No struct type named %s.", name
);
347 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
348 error ("This context has class, union or enum %s, not a struct.", name
);
349 return SYMBOL_TYPE (sym
);
352 /* Lookup a union type named "union NAME",
353 visible in lexical block BLOCK. */
356 lookup_union (name
, block
)
360 register struct symbol
*sym
361 = lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0, (struct symtab
**)NULL
);
364 error ("No union type named %s.", name
);
365 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_UNION
)
366 error ("This context has class, struct or enum %s, not a union.", name
);
367 return SYMBOL_TYPE (sym
);
370 /* Lookup an enum type named "enum NAME",
371 visible in lexical block BLOCK. */
374 lookup_enum (name
, block
)
378 register struct symbol
*sym
379 = lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0, (struct symtab
**)NULL
);
381 error ("No enum type named %s.", name
);
382 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_ENUM
)
383 error ("This context has class, struct or union %s, not an enum.", name
);
384 return SYMBOL_TYPE (sym
);
387 /* Given a type TYPE, lookup the type of the component of type named
391 lookup_struct_elt_type (type
, name
)
397 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
398 && TYPE_CODE (type
) != TYPE_CODE_UNION
)
400 target_terminal_ours ();
402 fprintf (stderr
, "Type ");
403 type_print (type
, "", stderr
, -1);
404 error (" is not a structure or union type.");
407 for (i
= TYPE_NFIELDS (type
) - 1; i
>= TYPE_N_BASECLASSES (type
); i
--)
408 if (!strcmp (TYPE_FIELD_NAME (type
, i
), name
))
409 return TYPE_FIELD_TYPE (type
, i
);
411 target_terminal_ours ();
413 fprintf (stderr
, "Type ");
414 type_print (type
, "", stderr
, -1);
415 fprintf (stderr
, " has no component named ");
416 fputs_filtered (name
, stderr
);
418 return (struct type
*)-1; /* For lint */
421 /* Given a type TYPE, return a type of pointers to that type.
422 May need to construct such a type if this is the first use.
424 C++: use TYPE_MAIN_VARIANT and TYPE_CHAIN to keep pointer
425 to member types under control. */
428 lookup_pointer_type (type
)
431 register struct type
*ptype
= TYPE_POINTER_TYPE (type
);
432 if (ptype
) return TYPE_MAIN_VARIANT (ptype
);
434 /* This is the first time anyone wanted a pointer to a TYPE. */
435 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
436 ptype
= (struct type
*) xmalloc (sizeof (struct type
));
438 ptype
= (struct type
*) obstack_alloc (symbol_obstack
,
439 sizeof (struct type
));
441 bzero (ptype
, sizeof (struct type
));
442 TYPE_MAIN_VARIANT (ptype
) = ptype
;
443 TYPE_TARGET_TYPE (ptype
) = type
;
444 TYPE_POINTER_TYPE (type
) = ptype
;
445 /* New type is permanent if type pointed to is permanent. */
446 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
447 TYPE_FLAGS (ptype
) |= TYPE_FLAG_PERM
;
448 /* We assume the machine has only one representation for pointers! */
449 TYPE_LENGTH (ptype
) = sizeof (char *);
450 TYPE_CODE (ptype
) = TYPE_CODE_PTR
;
455 lookup_reference_type (type
)
458 register struct type
*rtype
= TYPE_REFERENCE_TYPE (type
);
459 if (rtype
) return TYPE_MAIN_VARIANT (rtype
);
461 /* This is the first time anyone wanted a pointer to a TYPE. */
462 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
463 rtype
= (struct type
*) xmalloc (sizeof (struct type
));
465 rtype
= (struct type
*) obstack_alloc (symbol_obstack
,
466 sizeof (struct type
));
468 bzero (rtype
, sizeof (struct type
));
469 TYPE_MAIN_VARIANT (rtype
) = rtype
;
470 TYPE_TARGET_TYPE (rtype
) = type
;
471 TYPE_REFERENCE_TYPE (type
) = rtype
;
472 /* New type is permanent if type pointed to is permanent. */
473 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
474 TYPE_FLAGS (rtype
) |= TYPE_FLAG_PERM
;
475 /* We assume the machine has only one representation for pointers! */
476 TYPE_LENGTH (rtype
) = sizeof (char *);
477 TYPE_CODE (rtype
) = TYPE_CODE_REF
;
482 /* Implement direct support for MEMBER_TYPE in GNU C++.
483 May need to construct such a type if this is the first use.
484 The TYPE is the type of the member. The DOMAIN is the type
485 of the aggregate that the member belongs to. */
488 lookup_member_type (type
, domain
)
489 struct type
*type
, *domain
;
491 register struct type
*mtype
= TYPE_MAIN_VARIANT (type
);
492 struct type
*main_type
;
497 if (TYPE_DOMAIN_TYPE (mtype
) == domain
)
499 mtype
= TYPE_NEXT_VARIANT (mtype
);
502 /* This is the first time anyone wanted this member type. */
503 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
504 mtype
= (struct type
*) xmalloc (sizeof (struct type
));
506 mtype
= (struct type
*) obstack_alloc (symbol_obstack
,
507 sizeof (struct type
));
509 bzero (mtype
, sizeof (struct type
));
514 TYPE_NEXT_VARIANT (mtype
) = TYPE_NEXT_VARIANT (main_type
);
515 TYPE_NEXT_VARIANT (main_type
) = mtype
;
517 TYPE_MAIN_VARIANT (mtype
) = main_type
;
518 TYPE_TARGET_TYPE (mtype
) = type
;
519 TYPE_DOMAIN_TYPE (mtype
) = domain
;
520 /* New type is permanent if type pointed to is permanent. */
521 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
522 TYPE_FLAGS (mtype
) |= TYPE_FLAG_PERM
;
524 /* In practice, this is never used. */
525 TYPE_LENGTH (mtype
) = 1;
526 TYPE_CODE (mtype
) = TYPE_CODE_MEMBER
;
529 /* Now splice in the new member pointer type. */
532 /* This type was not "smashed". */
533 TYPE_CHAIN (mtype
) = TYPE_CHAIN (main_type
);
534 TYPE_CHAIN (main_type
) = mtype
;
542 lookup_method_type (type
, domain
, args
)
543 struct type
*type
, *domain
, **args
;
545 register struct type
*mtype
= TYPE_MAIN_VARIANT (type
);
546 struct type
*main_type
;
551 if (TYPE_DOMAIN_TYPE (mtype
) == domain
)
553 struct type
**t1
= args
;
554 struct type
**t2
= TYPE_ARG_TYPES (mtype
);
558 for (i
= 0; t1
[i
] != 0 && t1
[i
]->code
!= TYPE_CODE_VOID
; i
++)
565 mtype
= TYPE_NEXT_VARIANT (mtype
);
568 /* This is the first time anyone wanted this member type. */
569 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
570 mtype
= (struct type
*) xmalloc (sizeof (struct type
));
572 mtype
= (struct type
*) obstack_alloc (symbol_obstack
,
573 sizeof (struct type
));
575 bzero (mtype
, sizeof (struct type
));
580 TYPE_NEXT_VARIANT (mtype
) = TYPE_NEXT_VARIANT (main_type
);
581 TYPE_NEXT_VARIANT (main_type
) = mtype
;
583 TYPE_MAIN_VARIANT (mtype
) = main_type
;
584 TYPE_TARGET_TYPE (mtype
) = type
;
585 TYPE_DOMAIN_TYPE (mtype
) = domain
;
586 TYPE_ARG_TYPES (mtype
) = args
;
587 /* New type is permanent if type pointed to is permanent. */
588 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
589 TYPE_FLAGS (mtype
) |= TYPE_FLAG_PERM
;
591 /* In practice, this is never used. */
592 TYPE_LENGTH (mtype
) = 1;
593 TYPE_CODE (mtype
) = TYPE_CODE_METHOD
;
596 /* Now splice in the new member pointer type. */
599 /* This type was not "smashed". */
600 TYPE_CHAIN (mtype
) = TYPE_CHAIN (main_type
);
601 TYPE_CHAIN (main_type
) = mtype
;
609 /* Given a type TYPE, return a type which has offset OFFSET,
610 via_virtual VIA_VIRTUAL, and via_public VIA_PUBLIC.
611 May need to construct such a type if none exists. */
613 lookup_basetype_type (type
, offset
, via_virtual
, via_public
)
616 int via_virtual
, via_public
;
618 register struct type
*btype
= TYPE_MAIN_VARIANT (type
);
619 struct type
*main_type
;
623 printf ("Internal error: type offset non-zero in lookup_basetype_type");
630 if (/* TYPE_OFFSET (btype) == offset
631 && */ TYPE_VIA_PUBLIC (btype
) == via_public
632 && TYPE_VIA_VIRTUAL (btype
) == via_virtual
)
634 btype
= TYPE_NEXT_VARIANT (btype
);
637 /* This is the first time anyone wanted this member type. */
638 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
639 btype
= (struct type
*) xmalloc (sizeof (struct type
));
641 btype
= (struct type
*) obstack_alloc (symbol_obstack
,
642 sizeof (struct type
));
647 bzero (btype
, sizeof (struct type
));
648 TYPE_MAIN_VARIANT (btype
) = main_type
;
652 bcopy (main_type
, btype
, sizeof (struct type
));
653 TYPE_NEXT_VARIANT (main_type
) = btype
;
655 /* TYPE_OFFSET (btype) = offset; */
657 TYPE_FLAGS (btype
) |= TYPE_FLAG_VIA_PUBLIC
;
659 TYPE_FLAGS (btype
) |= TYPE_FLAG_VIA_VIRTUAL
;
660 /* New type is permanent if type pointed to is permanent. */
661 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
662 TYPE_FLAGS (btype
) |= TYPE_FLAG_PERM
;
664 /* In practice, this is never used. */
665 TYPE_LENGTH (btype
) = 1;
666 TYPE_CODE (btype
) = TYPE_CODE_STRUCT
;
672 /* Given a type TYPE, return a type of functions that return that type.
673 May need to construct such a type if this is the first use. */
676 lookup_function_type (type
)
679 register struct type
*ptype
= TYPE_FUNCTION_TYPE (type
);
680 if (ptype
) return ptype
;
682 /* This is the first time anyone wanted a function returning a TYPE. */
683 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
684 ptype
= (struct type
*) xmalloc (sizeof (struct type
));
686 ptype
= (struct type
*) obstack_alloc (symbol_obstack
,
687 sizeof (struct type
));
689 bzero (ptype
, sizeof (struct type
));
690 TYPE_TARGET_TYPE (ptype
) = type
;
691 TYPE_FUNCTION_TYPE (type
) = ptype
;
692 /* New type is permanent if type returned is permanent. */
693 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
694 TYPE_FLAGS (ptype
) |= TYPE_FLAG_PERM
;
695 TYPE_LENGTH (ptype
) = 1;
696 TYPE_CODE (ptype
) = TYPE_CODE_FUNC
;
697 TYPE_NFIELDS (ptype
) = 0;
701 /* Create an array type. Elements will be of type TYPE, and there will
704 Eventually this should be extended to take two more arguments which
705 specify the bounds of the array and the type of the index.
706 It should also be changed to be a "lookup" function, with the
707 appropriate data structures added to the type field.
708 Then read array type should call here. */
711 create_array_type (element_type
, number
)
712 struct type
*element_type
;
715 struct type
*result_type
= (struct type
*)
716 obstack_alloc (symbol_obstack
, sizeof (struct type
));
718 bzero (result_type
, sizeof (struct type
));
720 TYPE_CODE (result_type
) = TYPE_CODE_ARRAY
;
721 TYPE_TARGET_TYPE (result_type
) = element_type
;
722 TYPE_LENGTH (result_type
) = number
* TYPE_LENGTH (element_type
);
723 TYPE_NFIELDS (result_type
) = 1;
724 TYPE_FIELDS (result_type
) =
725 (struct field
*) obstack_alloc (symbol_obstack
, sizeof (struct field
));
726 TYPE_FIELD_TYPE (result_type
, 0) = builtin_type_int
;
727 TYPE_VPTR_FIELDNO (result_type
) = -1;
733 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE. */
736 smash_to_member_type (type
, domain
, to_type
)
737 struct type
*type
, *domain
, *to_type
;
739 bzero (type
, sizeof (struct type
));
740 TYPE_TARGET_TYPE (type
) = to_type
;
741 TYPE_DOMAIN_TYPE (type
) = domain
;
743 /* In practice, this is never needed. */
744 TYPE_LENGTH (type
) = 1;
745 TYPE_CODE (type
) = TYPE_CODE_MEMBER
;
747 TYPE_MAIN_VARIANT (type
) = lookup_member_type (domain
, to_type
);
750 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE. */
753 smash_to_method_type (type
, domain
, to_type
, args
)
754 struct type
*type
, *domain
, *to_type
, **args
;
756 bzero (type
, sizeof (struct type
));
757 TYPE_TARGET_TYPE (type
) = to_type
;
758 TYPE_DOMAIN_TYPE (type
) = domain
;
759 TYPE_ARG_TYPES (type
) = args
;
761 /* In practice, this is never needed. */
762 TYPE_LENGTH (type
) = 1;
763 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
765 TYPE_MAIN_VARIANT (type
) = lookup_method_type (domain
, to_type
, args
);
768 /* Find which partial symtab on the partial_symtab_list contains
769 PC. Return 0 if none. */
771 struct partial_symtab
*
773 register CORE_ADDR pc
;
775 register struct partial_symtab
*ps
;
777 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
778 if (pc
>= ps
->textlow
&& pc
< ps
->texthigh
)
784 /* Find which partial symbol within a psymtab contains PC. Return 0
785 if none. Check all psymtabs if PSYMTAB is 0. */
786 struct partial_symbol
*
787 find_pc_psymbol (psymtab
, pc
)
788 struct partial_symtab
*psymtab
;
791 struct partial_symbol
*best
, *p
;
795 psymtab
= find_pc_psymtab (pc
);
799 best_pc
= psymtab
->textlow
- 1;
801 for (p
= static_psymbols
.list
+ psymtab
->statics_offset
;
802 (p
- (static_psymbols
.list
+ psymtab
->statics_offset
)
803 < psymtab
->n_static_syms
);
805 if (SYMBOL_NAMESPACE (p
) == VAR_NAMESPACE
806 && SYMBOL_CLASS (p
) == LOC_BLOCK
807 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
808 && SYMBOL_VALUE_ADDRESS (p
) > best_pc
)
810 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
813 if (best_pc
== psymtab
->textlow
- 1)
819 /* Find the definition for a specified symbol name NAME
820 in namespace NAMESPACE, visible from lexical block BLOCK.
821 Returns the struct symbol pointer, or zero if no symbol is found.
822 If SYMTAB is non-NULL, store the symbol table in which the
823 symbol was found there, or NULL if not found.
824 C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
825 NAME is a field of the current implied argument `this'. If so set
826 *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
827 BLOCK_FOUND is set to the block in which NAME is found (in the case of
828 a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
831 lookup_symbol (name
, block
, namespace, is_a_field_of_this
, symtab
)
833 register struct block
*block
;
834 enum namespace namespace;
835 int *is_a_field_of_this
;
836 struct symtab
**symtab
;
838 register struct symbol
*sym
;
839 register struct symtab
*s
;
840 register struct partial_symtab
*ps
;
841 struct blockvector
*bv
;
843 /* Search specified block and its superiors. */
847 sym
= lookup_block_symbol (block
, name
, namespace);
853 /* Search the list of symtabs for one which contains the
854 address of the start of this block. */
856 for (s
= symtab_list
; s
; s
= s
->next
)
858 bv
= BLOCKVECTOR (s
);
859 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
860 if (BLOCK_START (b
) <= BLOCK_START (block
)
861 && BLOCK_END (b
) > BLOCK_START (block
))
869 block
= BLOCK_SUPERBLOCK (block
);
872 /* But that doesn't do any demangling for the STATIC_BLOCK.
873 I'm not sure whether demangling is needed in the case of
874 nested function in inner blocks; if so this needs to be changed.
876 Don't need to mess with the psymtabs; if we have a block,
877 that file is read in. If we don't, then we deal later with
878 all the psymtab stuff that needs checking. */
879 if (namespace == VAR_NAMESPACE
&& block
!= NULL
)
882 /* Find the right symtab. */
883 for (s
= symtab_list
; s
; s
= s
->next
)
885 bv
= BLOCKVECTOR (s
);
886 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
887 if (BLOCK_START (b
) <= BLOCK_START (block
)
888 && BLOCK_END (b
) > BLOCK_START (block
))
890 sym
= lookup_demangled_block_symbol (b
, name
);
903 /* C++: If requested to do so by the caller,
904 check to see if NAME is a field of `this'. */
905 if (is_a_field_of_this
)
907 struct value
*v
= value_of_this (0);
909 *is_a_field_of_this
= 0;
910 if (v
&& check_field (v
, name
))
912 *is_a_field_of_this
= 1;
919 /* Now search all global blocks. Do the symtab's first, then
920 check the psymtab's */
922 for (s
= symtab_list
; s
; s
= s
->next
)
924 bv
= BLOCKVECTOR (s
);
925 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
926 sym
= lookup_block_symbol (block
, name
, namespace);
936 /* Check for the possibility of the symbol being a global function
937 that is stored on the misc function vector. Eventually, all
938 global symbols might be resolved in this way. */
940 if (namespace == VAR_NAMESPACE
)
942 int ind
= lookup_misc_func (name
);
944 /* Look for a mangled C++ name for NAME. */
947 int name_len
= strlen (name
);
949 for (ind
= misc_function_count
; --ind
>= 0; )
950 /* Assume orginal name is prefix of mangled name. */
951 if (!strncmp (misc_function_vector
[ind
].name
, name
, name_len
))
954 cplus_demangle(misc_function_vector
[ind
].name
, -1);
955 if (demangled
!= NULL
)
957 int cond
= strcmp (demangled
, name
);
963 /* Loop terminates on no match with ind == -1. */
968 s
= find_pc_symtab (misc_function_vector
[ind
].address
);
971 bv
= BLOCKVECTOR (s
);
972 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
973 sym
= lookup_block_symbol (block
, misc_function_vector
[ind
].name
,
975 /* sym == 0 if symbol was found in the misc_function_vector
976 but not in the symtab.
977 Return 0 to use the misc_function definition of "foo_".
979 This happens for Fortran "foo_" symbols,
980 which are "foo" in the symtab.
982 This can also happen if "asm" is used to make a
983 regular symbol but not a debugging symbol, e.g.
995 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
996 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 1, namespace))
998 s
= PSYMTAB_TO_SYMTAB(ps
);
999 bv
= BLOCKVECTOR (s
);
1000 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1001 sym
= lookup_block_symbol (block
, name
, namespace);
1003 fatal ("Internal: global symbol found in psymtab but not in symtab");
1009 /* Now search all per-file blocks.
1010 Not strictly correct, but more useful than an error.
1011 Do the symtabs first, then check the psymtabs */
1013 for (s
= symtab_list
; s
; s
= s
->next
)
1015 bv
= BLOCKVECTOR (s
);
1016 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1017 sym
= lookup_block_symbol (block
, name
, namespace);
1020 block_found
= block
;
1027 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
1028 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 0, namespace))
1030 s
= PSYMTAB_TO_SYMTAB(ps
);
1031 bv
= BLOCKVECTOR (s
);
1032 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1033 sym
= lookup_block_symbol (block
, name
, namespace);
1035 fatal ("Internal: static symbol found in psymtab but not in symtab");
1041 /* Now search all per-file blocks for static mangled symbols.
1042 Do the symtabs first, then check the psymtabs. */
1044 if (namespace == VAR_NAMESPACE
)
1046 for (s
= symtab_list
; s
; s
= s
->next
)
1048 bv
= BLOCKVECTOR (s
);
1049 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1050 sym
= lookup_demangled_block_symbol (block
, name
);
1053 block_found
= block
;
1060 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
1061 if (!ps
->readin
&& lookup_demangled_partial_symbol (ps
, name
))
1063 s
= PSYMTAB_TO_SYMTAB(ps
);
1064 bv
= BLOCKVECTOR (s
);
1065 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1066 sym
= lookup_demangled_block_symbol (block
, name
);
1068 fatal ("Internal: static symbol found in psymtab but not in symtab");
1080 /* Look for a static demangled symbol in block BLOCK. */
1082 static struct symbol
*
1083 lookup_demangled_block_symbol (block
, name
)
1084 register struct block
*block
;
1087 register int bot
, top
, inc
;
1088 register struct symbol
*sym
;
1091 top
= BLOCK_NSYMS (block
);
1096 sym
= BLOCK_SYM (block
, bot
);
1097 if (SYMBOL_NAME (sym
)[0] == inc
1098 && SYMBOL_NAMESPACE (sym
) == VAR_NAMESPACE
)
1100 char *demangled
= cplus_demangle(SYMBOL_NAME (sym
), -1);
1101 if (demangled
!= NULL
)
1103 int cond
= strcmp (demangled
, name
);
1115 /* Look, in partial_symtab PST, for static mangled symbol NAME. */
1117 static struct partial_symbol
*
1118 lookup_demangled_partial_symbol (pst
, name
)
1119 struct partial_symtab
*pst
;
1122 struct partial_symbol
*start
, *psym
;
1123 int length
= pst
->n_static_syms
;
1124 register int inc
= name
[0];
1127 return (struct partial_symbol
*) 0;
1129 start
= static_psymbols
.list
+ pst
->statics_offset
;
1130 for (psym
= start
; psym
< start
+ length
; psym
++)
1132 if (SYMBOL_NAME (psym
)[0] == inc
1133 && SYMBOL_NAMESPACE (psym
) == VAR_NAMESPACE
)
1135 char *demangled
= cplus_demangle(SYMBOL_NAME (psym
), -1);
1136 if (demangled
!= NULL
)
1138 int cond
= strcmp (demangled
, name
);
1146 return (struct partial_symbol
*) 0;
1149 /* Look, in partial_symtab PST, for symbol NAME. Check the global
1150 symbols if GLOBAL, the static symbols if not */
1152 static struct partial_symbol
*
1153 lookup_partial_symbol (pst
, name
, global
, namespace)
1154 struct partial_symtab
*pst
;
1157 enum namespace namespace;
1159 struct partial_symbol
*start
, *psym
;
1160 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
1163 return (struct partial_symbol
*) 0;
1166 global_psymbols
.list
+ pst
->globals_offset
:
1167 static_psymbols
.list
+ pst
->statics_offset
);
1169 if (global
) /* This means we can use a binary */
1172 struct partial_symbol
*top
, *bottom
, *center
;
1174 /* Binary search. This search is guaranteed to end with center
1175 pointing at the earliest partial symbol with the correct
1176 name. At that point *all* partial symbols with that name
1177 will be checked against the correct namespace. */
1179 top
= start
+ length
- 1;
1180 while (top
> bottom
)
1182 center
= bottom
+ (top
- bottom
) / 2;
1184 assert (center
< top
);
1186 if (strcmp (SYMBOL_NAME (center
), name
) >= 0)
1189 bottom
= center
+ 1;
1191 assert (top
== bottom
);
1193 while (!strcmp (SYMBOL_NAME (top
), name
))
1195 if (SYMBOL_NAMESPACE (top
) == namespace)
1202 /* Can't use a binary search */
1203 for (psym
= start
; psym
< start
+ length
; psym
++)
1204 if (namespace == SYMBOL_NAMESPACE (psym
)
1205 && !strcmp (name
, SYMBOL_NAME (psym
)))
1209 return (struct partial_symbol
*) 0;
1212 /* Look for a symbol in block BLOCK. */
1215 lookup_block_symbol (block
, name
, namespace)
1216 register struct block
*block
;
1218 enum namespace namespace;
1220 register int bot
, top
, inc
;
1221 register struct symbol
*sym
, *parameter_sym
;
1223 top
= BLOCK_NSYMS (block
);
1226 /* If the blocks's symbols were sorted, start with a binary search. */
1228 if (BLOCK_SHOULD_SORT (block
))
1230 /* First, advance BOT to not far before
1231 the first symbol whose name is NAME. */
1235 inc
= (top
- bot
+ 1);
1236 /* No need to keep binary searching for the last few bits worth. */
1239 inc
= (inc
>> 1) + bot
;
1240 sym
= BLOCK_SYM (block
, inc
);
1241 if (SYMBOL_NAME (sym
)[0] < name
[0])
1243 else if (SYMBOL_NAME (sym
)[0] > name
[0])
1245 else if (strcmp (SYMBOL_NAME (sym
), name
) < 0)
1251 /* Now scan forward until we run out of symbols,
1252 find one whose name is greater than NAME,
1253 or find one we want.
1254 If there is more than one symbol with the right name and namespace,
1255 we return the first one. dbxread.c is careful to make sure
1256 that if one is a register then it comes first. */
1258 top
= BLOCK_NSYMS (block
);
1261 sym
= BLOCK_SYM (block
, bot
);
1262 inc
= SYMBOL_NAME (sym
)[0] - name
[0];
1264 inc
= strcmp (SYMBOL_NAME (sym
), name
);
1265 if (inc
== 0 && SYMBOL_NAMESPACE (sym
) == namespace)
1274 /* Here if block isn't sorted.
1275 This loop is equivalent to the loop above,
1276 but hacked greatly for speed.
1278 Note that parameter symbols do not always show up last in the
1279 list; this loop makes sure to take anything else other than
1280 parameter symbols first; it only uses parameter symbols as a
1281 last resort. Note that this only takes up extra computation
1284 parameter_sym
= (struct symbol
*) 0;
1285 top
= BLOCK_NSYMS (block
);
1289 sym
= BLOCK_SYM (block
, bot
);
1290 if (SYMBOL_NAME (sym
)[0] == inc
1291 && !strcmp (SYMBOL_NAME (sym
), name
)
1292 && SYMBOL_NAMESPACE (sym
) == namespace)
1294 if (SYMBOL_CLASS (sym
) == LOC_ARG
1295 || SYMBOL_CLASS (sym
) == LOC_LOCAL_ARG
1296 || SYMBOL_CLASS (sym
) == LOC_REF_ARG
1297 || SYMBOL_CLASS (sym
) == LOC_REGPARM
)
1298 parameter_sym
= sym
;
1304 return parameter_sym
; /* Will be 0 if not found. */
1307 /* Return the symbol for the function which contains a specified
1308 lexical block, described by a struct block BL. */
1314 while (BLOCK_FUNCTION (bl
) == 0 && BLOCK_SUPERBLOCK (bl
) != 0)
1315 bl
= BLOCK_SUPERBLOCK (bl
);
1317 return BLOCK_FUNCTION (bl
);
1320 /* Subroutine of find_pc_line */
1324 register CORE_ADDR pc
;
1326 register struct block
*b
;
1327 struct blockvector
*bv
;
1328 register struct symtab
*s
;
1329 register struct partial_symtab
*ps
;
1331 /* Search all symtabs for one whose file contains our pc */
1333 for (s
= symtab_list
; s
; s
= s
->next
)
1335 bv
= BLOCKVECTOR (s
);
1336 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1337 if (BLOCK_START (b
) <= pc
1338 && BLOCK_END (b
) > pc
)
1344 ps
= find_pc_psymtab (pc
);
1345 if (ps
&& ps
->readin
)
1346 fatal ("Internal error: pc in read in psymtab, but not in symtab.");
1349 s
= PSYMTAB_TO_SYMTAB (ps
);
1355 /* Find the source file and line number for a given PC value.
1356 Return a structure containing a symtab pointer, a line number,
1357 and a pc range for the entire source line.
1358 The value's .pc field is NOT the specified pc.
1359 NOTCURRENT nonzero means, if specified pc is on a line boundary,
1360 use the line that ends there. Otherwise, in that case, the line
1361 that begins there is used. */
1363 struct symtab_and_line
1364 find_pc_line (pc
, notcurrent
)
1369 register struct linetable
*l
;
1372 register struct linetable_entry
*item
;
1373 struct symtab_and_line val
;
1374 struct blockvector
*bv
;
1376 /* Info on best line seen so far, and where it starts, and its file. */
1379 CORE_ADDR best_pc
= 0;
1380 CORE_ADDR best_end
= 0;
1381 struct symtab
*best_symtab
= 0;
1383 /* Store here the first line number
1384 of a file which contains the line at the smallest pc after PC.
1385 If we don't find a line whose range contains PC,
1386 we will use a line one less than this,
1387 with a range from the start of that file to the first line's pc. */
1389 CORE_ADDR alt_pc
= 0;
1390 struct symtab
*alt_symtab
= 0;
1392 /* Info on best line seen in this file. */
1397 /* Info on first line of this file. */
1402 /* If this pc is not from the current frame,
1403 it is the address of the end of a call instruction.
1404 Quite likely that is the start of the following statement.
1405 But what we want is the statement containing the instruction.
1406 Fudge the pc to make sure we get that. */
1408 if (notcurrent
) pc
-= 1;
1410 s
= find_pc_symtab (pc
);
1420 bv
= BLOCKVECTOR (s
);
1422 /* Look at all the symtabs that share this blockvector.
1423 They all have the same apriori range, that we found was right;
1424 but they have different line tables. */
1426 for (; s
&& BLOCKVECTOR (s
) == bv
; s
= s
->next
)
1428 /* Find the best line in this symtab. */
1433 for (i
= 0; i
< len
; i
++)
1435 item
= &(l
->item
[i
]);
1439 first_line
= item
->line
;
1440 first_pc
= item
->pc
;
1442 /* Return the last line that did not start after PC. */
1445 prev_line
= item
->line
;
1452 /* Is this file's best line closer than the best in the other files?
1453 If so, record this file, and its best line, as best so far. */
1454 if (prev_line
>= 0 && prev_pc
> best_pc
)
1457 best_line
= prev_line
;
1460 best_end
= item
->pc
;
1464 /* Is this file's first line closer than the first lines of other files?
1465 If so, record this file, and its first line, as best alternate. */
1466 if (first_line
>= 0 && first_pc
> pc
1467 && (alt_pc
== 0 || first_pc
< alt_pc
))
1470 alt_line
= first_line
;
1474 if (best_symtab
== 0)
1476 val
.symtab
= alt_symtab
;
1477 val
.line
= alt_line
- 1;
1478 val
.pc
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
1483 val
.symtab
= best_symtab
;
1484 val
.line
= best_line
;
1486 val
.end
= (best_end
? best_end
1488 : BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
))));
1493 /* Find the PC value for a given source file and line number.
1494 Returns zero for invalid line number.
1495 The source file is specified with a struct symtab. */
1498 find_line_pc (symtab
, line
)
1499 struct symtab
*symtab
;
1502 register struct linetable
*l
;
1508 l
= LINETABLE (symtab
);
1509 ind
= find_line_common(l
, line
, &dummy
);
1510 return (ind
>= 0) ? l
->item
[ind
].pc
: 0;
1513 /* Find the range of pc values in a line.
1514 Store the starting pc of the line into *STARTPTR
1515 and the ending pc (start of next line) into *ENDPTR.
1516 Returns 1 to indicate success.
1517 Returns 0 if could not find the specified line. */
1520 find_line_pc_range (symtab
, thisline
, startptr
, endptr
)
1521 struct symtab
*symtab
;
1523 CORE_ADDR
*startptr
, *endptr
;
1525 register struct linetable
*l
;
1527 int exact_match
; /* did we get an exact linenumber match */
1532 l
= LINETABLE (symtab
);
1533 ind
= find_line_common (l
, thisline
, &exact_match
);
1536 *startptr
= l
->item
[ind
].pc
;
1537 /* If we have not seen an entry for the specified line,
1538 assume that means the specified line has zero bytes. */
1539 if (!exact_match
|| ind
== l
->nitems
-1)
1540 *endptr
= *startptr
;
1542 /* Perhaps the following entry is for the following line.
1543 It's worth a try. */
1544 if (ind
+1 < l
->nitems
1545 && l
->item
[ind
+1].line
== thisline
+ 1)
1546 *endptr
= l
->item
[ind
+1].pc
;
1548 *endptr
= find_line_pc (symtab
, thisline
+1);
1555 /* Given a line table and a line number, return the index into the line
1556 table for the pc of the nearest line whose number is >= the specified one.
1557 Return -1 if none is found. The value is >= 0 if it is an index.
1559 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
1562 find_line_common (l
, lineno
, exact_match
)
1563 register struct linetable
*l
;
1564 register int lineno
;
1570 /* BEST is the smallest linenumber > LINENO so far seen,
1571 or 0 if none has been seen so far.
1572 BEST_INDEX identifies the item for it. */
1574 int best_index
= -1;
1581 for (i
= 0; i
< len
; i
++)
1583 register struct linetable_entry
*item
= &(l
->item
[i
]);
1585 if (item
->line
== lineno
)
1591 if (item
->line
> lineno
&& (best
== 0 || item
->line
< best
))
1598 /* If we got here, we didn't get an exact match. */
1605 find_pc_line_pc_range (pc
, startptr
, endptr
)
1607 CORE_ADDR
*startptr
, *endptr
;
1609 struct symtab_and_line sal
;
1610 sal
= find_pc_line (pc
, 0);
1613 return sal
.symtab
!= 0;
1616 /* Recursive helper function for decode_line_1.
1617 * Look for methods named NAME in type T.
1618 * Return number of matches.
1619 * Put matches in PHYSNAMES and SYM_ARR (which better be big enough!).
1620 * These allocations seem to define "big enough":
1621 * sym_arr = (struct symbol **) alloca(TYPE_NFN_FIELDS_TOTAL (t) * sizeof(struct symbol*));
1622 * physnames = (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t) * sizeof(char*));
1626 find_methods(t
, name
, physnames
, sym_arr
)
1630 struct symbol
**sym_arr
;
1634 struct symbol
*sym_class
;
1635 char *class_name
= type_name_no_tag (t
);
1636 /* Ignore this class if it doesn't have a name.
1637 This prevents core dumps, but is just a workaround
1638 because we might not find the function in
1639 certain cases, such as
1640 struct D {virtual int f();}
1641 struct C : D {virtual int g();}
1642 (in this case g++ 1.35.1- does not put out a name
1643 for D as such, it defines type 19 (for example) in
1644 the same stab as C, and then does a
1645 .stabs "D:T19" and a .stabs "D:t19".
1647 "break C::f" should not be looking for field f in
1649 but just for the field f in the baseclasses of C
1650 (no matter what their names).
1652 However, I don't know how to replace the code below
1653 that depends on knowing the name of D. */
1655 && (sym_class
= lookup_symbol (class_name
,
1656 (struct block
*)NULL
,
1659 (struct symtab
**)NULL
)))
1662 t
= SYMBOL_TYPE (sym_class
);
1663 for (method_counter
= TYPE_NFN_FIELDS (t
) - 1;
1664 method_counter
>= 0;
1668 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, method_counter
);
1670 char *method_name
= TYPE_FN_FIELDLIST_NAME (t
, method_counter
);
1671 if (!strcmp (name
, method_name
))
1672 /* Find all the fields with that name. */
1673 for (field_counter
= TYPE_FN_FIELDLIST_LENGTH (t
, method_counter
) - 1;
1678 if (TYPE_FLAGS (TYPE_FN_FIELD_TYPE (f
, field_counter
)) & TYPE_FLAG_STUB
)
1679 check_stub_method (t
, method_counter
, field_counter
);
1680 phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, field_counter
);
1681 physnames
[i1
] = (char*) alloca (strlen (phys_name
) + 1);
1682 strcpy (physnames
[i1
], phys_name
);
1683 sym_arr
[i1
] = lookup_symbol (phys_name
,
1684 SYMBOL_BLOCK_VALUE (sym_class
),
1687 (struct symtab
**) NULL
);
1688 if (sym_arr
[i1
]) i1
++;
1692 /* Only search baseclasses if there is no match yet,
1693 * since names in derived classes override those in baseclasses.
1697 for (ibase
= 0; ibase
< TYPE_N_BASECLASSES (t
); ibase
++)
1698 i1
+= find_methods(TYPE_BASECLASS(t
, ibase
), name
,
1699 physnames
+ i1
, sym_arr
+ i1
);
1703 /* Parse a string that specifies a line number.
1704 Pass the address of a char * variable; that variable will be
1705 advanced over the characters actually parsed.
1709 LINENUM -- that line number in current file. PC returned is 0.
1710 FILE:LINENUM -- that line in that file. PC returned is 0.
1711 FUNCTION -- line number of openbrace of that function.
1712 PC returned is the start of the function.
1713 VARIABLE -- line number of definition of that variable.
1715 FILE:FUNCTION -- likewise, but prefer functions in that file.
1716 *EXPR -- line in which address EXPR appears.
1718 FUNCTION may be an undebuggable function found in misc_function_vector.
1720 If the argument FUNFIRSTLINE is nonzero, we want the first line
1721 of real code inside a function when a function is specified.
1723 DEFAULT_SYMTAB specifies the file to use if none is specified.
1724 It defaults to current_source_symtab.
1725 DEFAULT_LINE specifies the line number to use for relative
1726 line numbers (that start with signs). Defaults to current_source_line.
1728 Note that it is possible to return zero for the symtab
1729 if no file is validly specified. Callers must check that.
1730 Also, the line number returned may be invalid. */
1732 struct symtabs_and_lines
1733 decode_line_1 (argptr
, funfirstline
, default_symtab
, default_line
)
1736 struct symtab
*default_symtab
;
1739 struct symtabs_and_lines
decode_line_2 ();
1740 struct symtabs_and_lines values
;
1741 struct symtab_and_line val
;
1742 register char *p
, *p1
;
1743 register struct symtab
*s
;
1745 register struct symbol
*sym
;
1746 /* The symtab that SYM was found in. */
1747 struct symtab
*sym_symtab
;
1749 register CORE_ADDR pc
;
1752 struct symbol
*sym_class
;
1754 struct symbol
**sym_arr
;
1758 /* Defaults have defaults. */
1760 if (default_symtab
== 0)
1762 default_symtab
= current_source_symtab
;
1763 default_line
= current_source_line
;
1766 /* See if arg is *PC */
1768 if (**argptr
== '*')
1771 pc
= parse_and_eval_address_1 (argptr
);
1772 values
.sals
= (struct symtab_and_line
*)
1773 xmalloc (sizeof (struct symtab_and_line
));
1775 values
.sals
[0] = find_pc_line (pc
, 0);
1776 values
.sals
[0].pc
= pc
;
1780 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
1784 for (p
= *argptr
; *p
; p
++)
1786 if (p
[0] == ':' || p
[0] == ' ' || p
[0] == '\t')
1789 while (p
[0] == ' ' || p
[0] == '\t') p
++;
1797 /* Extract the class name. */
1799 while (p
!= *argptr
&& p
[-1] == ' ') --p
;
1800 copy
= (char *) alloca (p
- *argptr
+ 1);
1801 bcopy (*argptr
, copy
, p
- *argptr
);
1802 copy
[p
- *argptr
] = 0;
1804 /* Discard the class name from the arg. */
1806 while (*p
== ' ' || *p
== '\t') p
++;
1809 sym_class
= lookup_symbol (copy
, 0, STRUCT_NAMESPACE
, 0,
1810 (struct symtab
**)NULL
);
1813 (TYPE_CODE (SYMBOL_TYPE (sym_class
)) == TYPE_CODE_STRUCT
1814 || TYPE_CODE (SYMBOL_TYPE (sym_class
)) == TYPE_CODE_UNION
))
1816 /* Arg token is not digits => try it as a function name
1817 Find the next token (everything up to end or next whitespace). */
1819 while (*p
&& *p
!= ' ' && *p
!= '\t' && *p
!= ',' && *p
!=':') p
++;
1820 copy
= (char *) alloca (p
- *argptr
+ 1);
1821 bcopy (*argptr
, copy
, p
- *argptr
);
1822 copy
[p
- *argptr
] = '\0';
1824 /* no line number may be specified */
1825 while (*p
== ' ' || *p
== '\t') p
++;
1829 i1
= 0; /* counter for the symbol array */
1830 t
= SYMBOL_TYPE (sym_class
);
1831 sym_arr
= (struct symbol
**) alloca(TYPE_NFN_FIELDS_TOTAL (t
) * sizeof(struct symbol
*));
1832 physnames
= (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t
) * sizeof(char*));
1834 if (destructor_name_p (copy
, t
))
1836 /* destructors are a special case. */
1837 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, 0);
1838 int len
= TYPE_FN_FIELDLIST_LENGTH (t
, 0) - 1;
1839 char *phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, len
);
1840 physnames
[i1
] = (char *)alloca (strlen (phys_name
) + 1);
1841 strcpy (physnames
[i1
], phys_name
);
1843 lookup_symbol (phys_name
, SYMBOL_BLOCK_VALUE (sym_class
),
1844 VAR_NAMESPACE
, 0, (struct symtab
**)NULL
);
1845 if (sym_arr
[i1
]) i1
++;
1848 i1
= find_methods (t
, copy
, physnames
, sym_arr
);
1851 /* There is exactly one field with that name. */
1854 if (sym
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1856 /* Arg is the name of a function */
1857 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) + FUNCTION_START_OFFSET
;
1860 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
1862 values
.sals
[0] = find_pc_line (pc
, 0);
1863 values
.sals
[0].pc
= (values
.sals
[0].end
&& values
.sals
[0].pc
!= pc
) ? values
.sals
[0].end
: pc
;
1873 /* There is more than one field with that name
1874 (overloaded). Ask the user which one to use. */
1875 return decode_line_2 (sym_arr
, i1
, funfirstline
);
1878 error ("that class does not have any method named %s",copy
);
1881 /* The quotes are important if copy is empty. */
1882 error("No class, struct, or union named \"%s\"", copy
);
1887 /* Extract the file name. */
1889 while (p
!= *argptr
&& p
[-1] == ' ') --p
;
1890 copy
= (char *) alloca (p
- *argptr
+ 1);
1891 bcopy (*argptr
, copy
, p
- *argptr
);
1892 copy
[p
- *argptr
] = 0;
1894 /* Find that file's data. */
1895 s
= lookup_symtab (copy
);
1898 if (symtab_list
== 0 && partial_symtab_list
== 0)
1899 error (no_symtab_msg
);
1900 error ("No source file named %s.", copy
);
1903 /* Discard the file name from the arg. */
1905 while (*p
== ' ' || *p
== '\t') p
++;
1909 /* S is specified file's symtab, or 0 if no file specified.
1910 arg no longer contains the file name. */
1912 /* Check whether arg is all digits (and sign) */
1915 if (*p
== '-' || *p
== '+') p
++;
1916 while (*p
>= '0' && *p
<= '9')
1919 if (p
!= *argptr
&& (*p
== 0 || *p
== ' ' || *p
== '\t' || *p
== ','))
1921 /* We found a token consisting of all digits -- at least one digit. */
1922 enum sign
{none
, plus
, minus
} sign
= none
;
1924 /* This is where we need to make sure that we have good defaults.
1925 We must guarantee that this section of code is never executed
1926 when we are called with just a function name, since
1927 select_source_symtab calls us with such an argument */
1929 if (s
== 0 && default_symtab
== 0)
1931 if (symtab_list
== 0 && partial_symtab_list
== 0)
1932 error (no_symtab_msg
);
1933 select_source_symtab (0);
1934 default_symtab
= current_source_symtab
;
1935 default_line
= current_source_line
;
1938 if (**argptr
== '+')
1939 sign
= plus
, (*argptr
)++;
1940 else if (**argptr
== '-')
1941 sign
= minus
, (*argptr
)++;
1942 val
.line
= atoi (*argptr
);
1949 val
.line
= default_line
+ val
.line
;
1955 val
.line
= default_line
- val
.line
;
1960 break; /* No need to adjust val.line. */
1963 while (*p
== ' ' || *p
== '\t') p
++;
1969 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
1970 values
.sals
[0] = val
;
1975 /* Arg token is not digits => try it as a variable name
1976 Find the next token (everything up to end or next whitespace). */
1978 while (*p
&& *p
!= ' ' && *p
!= '\t' && *p
!= ',') p
++;
1979 copy
= (char *) alloca (p
- *argptr
+ 1);
1980 bcopy (*argptr
, copy
, p
- *argptr
);
1981 copy
[p
- *argptr
] = 0;
1982 while (*p
== ' ' || *p
== '\t') p
++;
1985 /* Look up that token as a variable.
1986 If file specified, use that file's per-file block to start with. */
1988 sym
= lookup_symbol (copy
,
1989 (s
? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
)
1990 : get_selected_block ()),
1991 VAR_NAMESPACE
, 0, &sym_symtab
);
1995 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1997 /* Arg is the name of a function */
1998 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) + FUNCTION_START_OFFSET
;
2001 val
= find_pc_line (pc
, 0);
2002 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2003 /* Convex: no need to suppress code on first line, if any */
2006 val
.pc
= (val
.end
&& val
.pc
!= pc
) ? val
.end
: pc
;
2008 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
2009 values
.sals
[0] = val
;
2012 /* I think this is always the same as the line that
2013 we calculate above, but the general principle is
2014 "trust the symbols more than stuff like
2016 if (SYMBOL_LINE (sym
) != 0)
2017 values
.sals
[0].line
= SYMBOL_LINE (sym
);
2021 else if (SYMBOL_LINE (sym
) != 0)
2023 /* We know its line number. */
2024 values
.sals
= (struct symtab_and_line
*)
2025 xmalloc (sizeof (struct symtab_and_line
));
2027 bzero (&values
.sals
[0], sizeof (values
.sals
[0]));
2028 values
.sals
[0].symtab
= sym_symtab
;
2029 values
.sals
[0].line
= SYMBOL_LINE (sym
);
2033 /* This can happen if it is compiled with a compiler which doesn't
2034 put out line numbers for variables. */
2035 error ("Line number not known for symbol \"%s\"", copy
);
2038 if (symtab_list
== 0 && partial_symtab_list
== 0)
2039 error (no_symtab_msg
);
2041 if ((i
= lookup_misc_func (copy
)) >= 0)
2045 val
.pc
= misc_function_vector
[i
].address
+ FUNCTION_START_OFFSET
;
2047 SKIP_PROLOGUE (val
.pc
);
2048 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
2049 values
.sals
[0] = val
;
2054 error ("Function %s not defined.", copy
);
2055 return values
; /* for lint */
2058 struct symtabs_and_lines
2059 decode_line_spec (string
, funfirstline
)
2063 struct symtabs_and_lines sals
;
2065 error ("Empty line specification.");
2066 sals
= decode_line_1 (&string
, funfirstline
,
2067 current_source_symtab
, current_source_line
);
2069 error ("Junk at end of line specification: %s", string
);
2073 /* Given a list of NELTS symbols in sym_arr (with corresponding
2074 mangled names in physnames), return a list of lines to operate on
2075 (ask user if necessary). */
2076 struct symtabs_and_lines
2077 decode_line_2 (sym_arr
, nelts
, funfirstline
)
2078 struct symbol
*sym_arr
[];
2083 struct symtabs_and_lines values
, return_values
;
2084 register CORE_ADDR pc
;
2085 char *args
, *arg1
, *command_line_input ();
2089 values
.sals
= (struct symtab_and_line
*) alloca (nelts
* sizeof(struct symtab_and_line
));
2090 return_values
.sals
= (struct symtab_and_line
*) xmalloc (nelts
* sizeof(struct symtab_and_line
));
2093 printf("[0] cancel\n[1] all\n");
2096 if (sym_arr
[i
] && SYMBOL_CLASS (sym_arr
[i
]) == LOC_BLOCK
)
2098 /* Arg is the name of a function */
2099 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym_arr
[i
]))
2100 + FUNCTION_START_OFFSET
;
2103 values
.sals
[i
] = find_pc_line (pc
, 0);
2104 values
.sals
[i
].pc
= (values
.sals
[i
].end
&& values
.sals
[i
].pc
!= pc
) ?
2105 values
.sals
[i
].end
: pc
;
2106 printf("[%d] file:%s; line number:%d\n",
2107 (i
+2), values
.sals
[i
].symtab
->filename
, values
.sals
[i
].line
);
2109 else printf ("?HERE\n");
2113 if ((prompt
= getenv ("PS2")) == NULL
)
2117 printf("%s ",prompt
);
2120 args
= command_line_input (0, 0);
2123 error_no_arg ("one or more choice numbers");
2131 while (*arg1
>= '0' && *arg1
<= '9') arg1
++;
2132 if (*arg1
&& *arg1
!= ' ' && *arg1
!= '\t')
2133 error ("Arguments must be choice numbers.");
2138 error ("cancelled");
2141 bcopy (values
.sals
, return_values
.sals
, (nelts
* sizeof(struct symtab_and_line
)));
2142 return_values
.nelts
= nelts
;
2143 return return_values
;
2146 if (num
> nelts
+ 2)
2148 printf ("No choice number %d.\n", num
);
2153 if (values
.sals
[num
].pc
)
2155 return_values
.sals
[i
++] = values
.sals
[num
];
2156 values
.sals
[num
].pc
= 0;
2160 printf ("duplicate request for %d ignored.\n", num
);
2165 while (*args
== ' ' || *args
== '\t') args
++;
2167 return_values
.nelts
= i
;
2168 return return_values
;
2171 /* Return the index of misc function named NAME. */
2174 lookup_misc_func (name
)
2175 register char *name
;
2179 for (i
= 0; i
< misc_function_count
; i
++)
2180 if (!strcmp (misc_function_vector
[i
].name
, name
))
2182 return -1; /* not found */
2185 /* Slave routine for sources_info. Force line breaks at ,'s.
2186 NAME is the name to print and *FIRST is nonzero if this is the first
2187 name printed. Set *FIRST to zero. */
2189 output_source_filename (name
, first
)
2194 /* Table of files printed so far. Since a single source file can
2195 result in several partial symbol tables, we need to avoid printing
2196 it more than once. Note: if some of the psymtabs are read in and
2197 some are not, it gets printed both under "Source files for which
2198 symbols have been read" and "Source files for which symbols will
2199 be read in on demand". I consider this a reasonable way to deal
2200 with the situation. I'm not sure whether this can also happen for
2201 symtabs; it doesn't hurt to check. */
2202 static char **tab
= NULL
;
2203 /* Allocated size of tab in elements.
2204 Start with one 256-byte block (when using GNU malloc.c).
2205 24 is the malloc overhead when range checking is in effect. */
2206 static int tab_alloc_size
= (256 - 24) / sizeof (char *);
2207 /* Current size of tab in elements. */
2208 static int tab_cur_size
;
2215 tab
= (char **) xmalloc (tab_alloc_size
* sizeof (*tab
));
2219 /* Is NAME in tab? */
2220 for (p
= tab
; p
< tab
+ tab_cur_size
; p
++)
2221 if (strcmp (*p
, name
) == 0)
2222 /* Yes; don't print it again. */
2224 /* No; add it to tab. */
2225 if (tab_cur_size
== tab_alloc_size
)
2227 tab_alloc_size
*= 2;
2228 tab
= (char **) xrealloc (tab
, tab_alloc_size
* sizeof (*tab
));
2230 tab
[tab_cur_size
++] = name
;
2239 printf_filtered (",");
2243 if (column
!= 0 && column
+ strlen (name
) >= 70)
2245 printf_filtered ("\n");
2248 else if (column
!= 0)
2250 printf_filtered (" ");
2253 fputs_filtered (name
, stdout
);
2254 column
+= strlen (name
);
2260 register struct symtab
*s
;
2261 register struct partial_symtab
*ps
;
2264 if (symtab_list
== 0 && partial_symtab_list
== 0)
2266 printf (no_symtab_msg
);
2270 printf_filtered ("Source files for which symbols have been read in:\n\n");
2273 for (s
= symtab_list
; s
; s
= s
->next
)
2274 output_source_filename (s
->filename
, &first
);
2275 printf_filtered ("\n\n");
2277 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2280 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
2282 output_source_filename (ps
->filename
, &first
);
2283 printf_filtered ("\n");
2286 /* List all symbols (if REGEXP is 0) or all symbols matching REGEXP.
2287 If CLASS is zero, list all symbols except functions and type names.
2288 If CLASS is 1, list only functions.
2289 If CLASS is 2, list only type names.
2291 BPT is non-zero if we should set a breakpoint at the functions
2295 list_symbols (regexp
, class, bpt
)
2300 register struct symtab
*s
;
2301 register struct partial_symtab
*ps
;
2302 register struct blockvector
*bv
;
2303 struct blockvector
*prev_bv
= 0;
2304 register struct block
*b
;
2306 register struct symbol
*sym
;
2307 struct partial_symbol
*psym
;
2309 static char *classnames
[]
2310 = {"variable", "function", "type", "method"};
2311 int found_in_file
= 0;
2314 if (0 != (val
= (char *) re_comp (regexp
)))
2315 error ("Invalid regexp (%s): %s", val
, regexp
);
2317 /* Search through the partial_symtab_list *first* for all symbols
2318 matching the regexp. That way we don't have to reproduce all of
2319 the machinery below. */
2320 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
2322 struct partial_symbol
*bound
, *gbound
, *sbound
;
2325 if (ps
->readin
) continue;
2327 gbound
= global_psymbols
.list
+ ps
->globals_offset
+ ps
->n_global_syms
;
2328 sbound
= static_psymbols
.list
+ ps
->statics_offset
+ ps
->n_static_syms
;
2331 /* Go through all of the symbols stored in a partial
2332 symtab in one loop. */
2333 psym
= global_psymbols
.list
+ ps
->globals_offset
;
2338 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
2340 psym
= static_psymbols
.list
+ ps
->statics_offset
;
2351 /* If it would match (logic taken from loop below)
2352 load the file and go on to the next one */
2353 if ((regexp
== 0 || re_exec (SYMBOL_NAME (psym
)))
2354 && ((class == 0 && SYMBOL_CLASS (psym
) != LOC_TYPEDEF
2355 && SYMBOL_CLASS (psym
) != LOC_BLOCK
)
2356 || (class == 1 && SYMBOL_CLASS (psym
) == LOC_BLOCK
)
2357 || (class == 2 && SYMBOL_CLASS (psym
) == LOC_TYPEDEF
)
2358 || (class == 3 && SYMBOL_CLASS (psym
) == LOC_BLOCK
)))
2360 (void) PSYMTAB_TO_SYMTAB(ps
);
2368 /* Here, *if* the class is correct (function only, right now), we
2369 search through the misc function vector for symbols that
2370 match, and call find_pc_symtab on them to force their symbols to
2371 be read. The symbol will then be found during the scan of symtabs
2376 for (i
= 0; i
< misc_function_count
; i
++)
2377 if (regexp
== 0 || re_exec (misc_function_vector
[i
].name
))
2379 (void) find_pc_symtab (misc_function_vector
[i
].address
);
2383 /* Printout here so as to get after the "Reading in symbols"
2384 messages which will be generated above. */
2386 printf_filtered (regexp
2387 ? "All %ss matching regular expression \"%s\":\n"
2388 : "All defined %ss:\n",
2392 for (s
= symtab_list
; s
; s
= s
->next
)
2395 bv
= BLOCKVECTOR (s
);
2396 /* Often many files share a blockvector.
2397 Scan each blockvector only once so that
2398 we don't get every symbol many times.
2399 It happens that the first symtab in the list
2400 for any given blockvector is the main file. */
2402 for (i
= GLOBAL_BLOCK
; i
<= STATIC_BLOCK
; i
++)
2404 b
= BLOCKVECTOR_BLOCK (bv
, i
);
2405 /* Skip the sort if this block is always sorted. */
2406 if (!BLOCK_SHOULD_SORT (b
))
2407 sort_block_syms (b
);
2408 for (j
= 0; j
< BLOCK_NSYMS (b
); j
++)
2411 sym
= BLOCK_SYM (b
, j
);
2412 if ((regexp
== 0 || re_exec (SYMBOL_NAME (sym
)))
2413 && ((class == 0 && SYMBOL_CLASS (sym
) != LOC_TYPEDEF
2414 && SYMBOL_CLASS (sym
) != LOC_BLOCK
)
2415 || (class == 1 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
2416 || (class == 2 && SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
2417 || (class == 3 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)))
2421 /* Set a breakpoint here, if it's a function */
2423 break_command (SYMBOL_NAME(sym
), 0);
2425 else if (!found_in_file
)
2427 fputs_filtered ("\nFile ", stdout
);
2428 fputs_filtered (s
->filename
, stdout
);
2429 fputs_filtered (":\n", stdout
);
2433 if (class != 2 && i
== STATIC_BLOCK
)
2434 printf_filtered ("static ");
2436 && SYMBOL_NAMESPACE (sym
) != STRUCT_NAMESPACE
)
2437 printf_filtered ("typedef ");
2441 type_print (SYMBOL_TYPE (sym
),
2442 (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
2443 ? "" : SYMBOL_NAME (sym
)),
2447 && SYMBOL_NAMESPACE (sym
) != STRUCT_NAMESPACE
2448 && (TYPE_NAME ((SYMBOL_TYPE (sym
))) == 0
2449 || 0 != strcmp (TYPE_NAME ((SYMBOL_TYPE (sym
))),
2450 SYMBOL_NAME (sym
))))
2452 fputs_filtered (" ", stdout
);
2453 fprint_symbol (stdout
, SYMBOL_NAME (sym
));
2456 printf_filtered (";\n");
2462 type_print_base (TYPE_FN_FIELD_TYPE(t
, i
), stdout
, 0, 0);
2463 type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t
, i
), stdout
, 0);
2464 sprintf (buf
, " %s::", type_name_no_tag (t
));
2465 type_print_method_args (TYPE_FN_FIELD_ARGS (t
, i
), buf
, name
, stdout
);
2476 variables_info (regexp
)
2479 list_symbols (regexp
, 0, 0);
2483 functions_info (regexp
)
2486 list_symbols (regexp
, 1, 0);
2493 list_symbols (regexp
, 2, 0);
2497 /* Tiemann says: "info methods was never implemented." */
2499 methods_info (regexp
)
2502 list_symbols (regexp
, 3, 0);
2506 /* Breakpoint all functions matching regular expression. */
2508 rbreak_command (regexp
)
2511 list_symbols (regexp
, 1, 1);
2514 /* Initialize the standard C scalar types. */
2518 init_type (code
, length
, uns
, name
)
2519 enum type_code code
;
2523 register struct type
*type
;
2525 type
= (struct type
*) xmalloc (sizeof (struct type
));
2526 bzero (type
, sizeof *type
);
2527 TYPE_MAIN_VARIANT (type
) = type
;
2528 TYPE_CODE (type
) = code
;
2529 TYPE_LENGTH (type
) = length
;
2530 TYPE_FLAGS (type
) = uns
? TYPE_FLAG_UNSIGNED
: 0;
2531 TYPE_FLAGS (type
) |= TYPE_FLAG_PERM
;
2532 TYPE_NFIELDS (type
) = 0;
2533 TYPE_NAME (type
) = name
;
2536 TYPE_NFN_FIELDS (type
) = 0;
2537 TYPE_N_BASECLASSES (type
) = 0;
2541 /* Return Nonzero if block a is lexically nested within block b,
2542 or if a and b have the same pc range.
2543 Return zero otherwise. */
2546 struct block
*a
, *b
;
2550 return BLOCK_START (a
) >= BLOCK_START (b
)
2551 && BLOCK_END (a
) <= BLOCK_END (b
);
2555 /* Helper routine for make_symbol_completion_list. */
2557 int return_val_size
, return_val_index
;
2561 completion_list_add_symbol (symname
)
2564 if (return_val_index
+ 3 > return_val_size
)
2566 (char **)xrealloc (return_val
,
2567 (return_val_size
*= 2) * sizeof (char *));
2569 return_val
[return_val_index
] =
2570 (char *)xmalloc (1 + strlen (symname
));
2572 strcpy (return_val
[return_val_index
], symname
);
2574 return_val
[++return_val_index
] = (char *)NULL
;
2577 /* Return a NULL terminated array of all symbols (regardless of class) which
2578 begin by matching TEXT. If the answer is no symbols, then the return value
2579 is an array which contains only a NULL pointer.
2581 Problem: All of the symbols have to be copied because readline
2582 frees them. I'm not going to worry about this; hopefully there
2583 won't be that many. */
2586 make_symbol_completion_list (text
)
2589 register struct symtab
*s
;
2590 register struct partial_symtab
*ps
;
2591 register struct block
*b
, *surrounding_static_block
= 0;
2592 extern struct block
*get_selected_block ();
2594 struct partial_symbol
*psym
;
2596 int text_len
= strlen (text
);
2597 return_val_size
= 100;
2598 return_val_index
= 0;
2600 (char **)xmalloc ((1 + return_val_size
) *sizeof (char *));
2601 return_val
[0] = (char *)NULL
;
2603 /* Look through the partial symtabs for all symbols which begin
2604 by matching TEXT. Add each one that you find to the list. */
2606 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
2608 /* If the psymtab's been read in we'll get it when we search
2609 through the blockvector. */
2610 if (ps
->readin
) continue;
2612 for (psym
= global_psymbols
.list
+ ps
->globals_offset
;
2613 psym
< (global_psymbols
.list
+ ps
->globals_offset
2614 + ps
->n_global_syms
);
2617 QUIT
; /* If interrupted, then quit. */
2618 if ((strncmp (SYMBOL_NAME (psym
), text
, text_len
) == 0))
2619 completion_list_add_symbol (SYMBOL_NAME (psym
));
2622 for (psym
= static_psymbols
.list
+ ps
->statics_offset
;
2623 psym
< (static_psymbols
.list
+ ps
->statics_offset
2624 + ps
->n_static_syms
);
2628 if ((strncmp (SYMBOL_NAME (psym
), text
, text_len
) == 0))
2629 completion_list_add_symbol (SYMBOL_NAME (psym
));
2633 /* At this point scan through the misc function vector and add each
2634 symbol you find to the list. Eventually we want to ignore
2635 anything that isn't a text symbol (everything else will be
2636 handled by the psymtab code above). */
2638 for (i
= 0; i
< misc_function_count
; i
++)
2639 if (!strncmp (text
, misc_function_vector
[i
].name
, text_len
))
2640 completion_list_add_symbol (misc_function_vector
[i
].name
);
2642 /* Search upwards from currently selected frame (so that we can
2643 complete on local vars. */
2644 for (b
= get_selected_block (); b
; b
= BLOCK_SUPERBLOCK (b
))
2646 if (!BLOCK_SUPERBLOCK (b
))
2647 surrounding_static_block
= b
; /* For elmin of dups */
2649 /* Also catch fields of types defined in this places which
2650 match our text string. Only complete on types visible
2651 from current context. */
2652 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2654 register struct symbol
*sym
= BLOCK_SYM (b
, i
);
2656 if (!strncmp (SYMBOL_NAME (sym
), text
, text_len
))
2657 completion_list_add_symbol (SYMBOL_NAME (sym
));
2659 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
2661 struct type
*t
= SYMBOL_TYPE (sym
);
2662 enum type_code c
= TYPE_CODE (t
);
2664 if (c
== TYPE_CODE_UNION
|| c
== TYPE_CODE_STRUCT
)
2665 for (j
= TYPE_N_BASECLASSES (t
); j
< TYPE_NFIELDS (t
); j
++)
2666 if (TYPE_FIELD_NAME (t
, j
) &&
2667 !strncmp (TYPE_FIELD_NAME (t
, j
), text
, text_len
))
2668 completion_list_add_symbol (TYPE_FIELD_NAME (t
, j
));
2673 /* Go through the symtabs and check the externs and statics for
2674 symbols which match. */
2676 for (s
= symtab_list
; s
; s
= s
->next
)
2678 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
2680 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2681 if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b
, i
)), text
, text_len
))
2682 completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b
, i
)));
2685 for (s
= symtab_list
; s
; s
= s
->next
)
2687 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
2689 /* Don't do this block twice. */
2690 if (b
== surrounding_static_block
) continue;
2692 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2693 if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b
, i
)), text
, text_len
))
2694 completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b
, i
)));
2697 return (return_val
);
2701 _initialize_symtab ()
2703 add_info ("variables", variables_info
,
2704 "All global and static variable names, or those matching REGEXP.");
2705 add_info ("functions", functions_info
,
2706 "All function names, or those matching REGEXP.");
2708 /* FIXME: This command has at least the following problems:
2709 1. It prints builtin types (in a very strange and confusing fashion).
2710 2. It doesn't print right, e.g. with
2711 typedef struct foo *FOO
2712 type_print prints "FOO" when we want to make it (in this situation)
2713 print "struct foo *".
2714 I also think "ptype" or "whatis" is more likely to be useful (but if
2715 there is much disagreement "info types" can be fixed). */
2716 add_info ("types", types_info
,
2717 "All types names, or those matching REGEXP.");
2720 add_info ("methods", methods_info
,
2721 "All method names, or those matching REGEXP::REGEXP.\n\
2722 If the class qualifier is ommited, it is assumed to be the current scope.\n\
2723 If the first REGEXP is ommited, then all methods matching the second REGEXP\n\
2726 add_info ("sources", sources_info
,
2727 "Source files in the program.");
2729 add_com ("rbreak", no_class
, rbreak_command
,
2730 "Set a breakpoint for all functions matching REGEXP.");
2732 /* FIXME: The code below assumes that the sizes of the basic data
2733 types are the same on the host and target machines!!! */
2735 builtin_type_void
= init_type (TYPE_CODE_VOID
, 1, 0, "void");
2737 builtin_type_float
= init_type (TYPE_CODE_FLT
, sizeof (float), 0, "float");
2738 builtin_type_double
= init_type (TYPE_CODE_FLT
, sizeof (double), 0, "double");
2740 builtin_type_char
= init_type (TYPE_CODE_INT
, sizeof (char), 0, "char");
2741 builtin_type_short
= init_type (TYPE_CODE_INT
, sizeof (short), 0, "short");
2742 builtin_type_long
= init_type (TYPE_CODE_INT
, sizeof (long), 0, "long");
2743 builtin_type_int
= init_type (TYPE_CODE_INT
, sizeof (int), 0, "int");
2745 builtin_type_unsigned_char
= init_type (TYPE_CODE_INT
, sizeof (char), 1, "unsigned char");
2746 builtin_type_unsigned_short
= init_type (TYPE_CODE_INT
, sizeof (short), 1, "unsigned short");
2747 builtin_type_unsigned_long
= init_type (TYPE_CODE_INT
, sizeof (long), 1, "unsigned long");
2748 builtin_type_unsigned_int
= init_type (TYPE_CODE_INT
, sizeof (int), 1, "unsigned int");
2750 builtin_type_long_long
=
2751 init_type (TYPE_CODE_INT
, sizeof (long long), 0, "long long");
2752 builtin_type_unsigned_long_long
=
2753 init_type (TYPE_CODE_INT
, sizeof (long long), 1, "unsigned long long");
2755 builtin_type_error
= init_type (TYPE_CODE_ERROR
, 0, 0, "<unknown type>");