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 ();
53 /* These variables point to the objects
54 representing the predefined C data types. */
56 struct type
*builtin_type_void
;
57 struct type
*builtin_type_char
;
58 struct type
*builtin_type_short
;
59 struct type
*builtin_type_int
;
60 struct type
*builtin_type_long
;
62 struct type
*builtin_type_long_long
;
64 struct type
*builtin_type_unsigned_char
;
65 struct type
*builtin_type_unsigned_short
;
66 struct type
*builtin_type_unsigned_int
;
67 struct type
*builtin_type_unsigned_long
;
69 struct type
*builtin_type_unsigned_long_long
;
71 struct type
*builtin_type_float
;
72 struct type
*builtin_type_double
;
73 struct type
*builtin_type_error
;
75 /* Block in which the most recently searched-for symbol was found.
76 Might be better to make this a parameter to lookup_symbol and
78 struct block
*block_found
;
80 char no_symtab_msg
[] = "No symbol table is loaded. Use the \"file\" command.";
82 /* Check for a symtab of a specific name; first in symtabs, then in
83 psymtabs. *If* there is no '/' in the name, a match after a '/'
84 in the symtab filename will also work. */
86 static struct symtab
*
87 lookup_symtab_1 (name
)
90 register struct symtab
*s
;
91 register struct partial_symtab
*ps
;
92 register char *slash
= strchr (name
, '/');
93 register int len
= strlen (name
);
95 for (s
= symtab_list
; s
; s
= s
->next
)
96 if (!strcmp (name
, s
->filename
))
99 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
100 if (!strcmp (name
, ps
->filename
))
103 fatal ("Internal: readin pst found when no symtab found.");
104 return 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 return PSYMTAB_TO_SYMTAB (ps
);
134 /* Lookup the symbol table of a source file named NAME. Try a couple
135 of variations if the first lookup doesn't work. */
141 register struct symtab
*s
;
144 s
= lookup_symtab_1 (name
);
147 /* If name not found as specified, see if adding ".c" helps. */
149 copy
= (char *) alloca (strlen (name
) + 3);
152 s
= lookup_symtab_1 (copy
);
155 /* We didn't find anything; die. */
159 /* Lookup the partial symbol table of a source file named NAME. This
160 only returns true on an exact match (ie. this semantics are
161 different from lookup_symtab. */
163 struct partial_symtab
*
164 lookup_partial_symtab (name
)
167 register struct partial_symtab
*s
;
169 for (s
= partial_symtab_list
; s
; s
= s
->next
)
170 if (!strcmp (name
, s
->filename
))
176 /* Return a typename for a struct/union/enum type
177 without the tag qualifier. If the type has a NULL name,
180 type_name_no_tag (type
)
181 register struct type
*type
;
183 register char *name
= TYPE_NAME (type
);
189 switch (TYPE_CODE (type
))
191 case TYPE_CODE_STRUCT
:
193 case TYPE_CODE_UNION
:
200 name
= strchr (name
, ' ');
204 return TYPE_NAME (type
);
207 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
209 If this is a stubbed struct (i.e. declared as struct foo *), see if
210 we can find a full definition in some other file. If so, copy this
211 definition, so we can use it in future. If not, set a flag so we
212 don't waste too much time in future.
214 This used to be coded as a macro, but I don't think it is called
215 often enough to merit such treatment.
218 struct complaint stub_noname_complaint
=
219 {"stub type has NULL name", 0, 0};
222 check_stub_type(type
)
225 if (TYPE_FLAGS(type
) & TYPE_FLAG_STUB
)
227 char* name
= type_name_no_tag (type
);
231 complain (&stub_noname_complaint
, 0, 0);
234 if (sym
= lookup_symbol (name
, 0, STRUCT_NAMESPACE
, 0,
235 (struct symtab
**)NULL
) )
236 bcopy (SYMBOL_TYPE(sym
), type
, sizeof (struct type
));
240 /* Demangle a GDB method stub type. */
242 gdb_mangle_typename (type
)
245 static struct type
*last_type
;
246 static char *mangled_typename
;
248 if (type
!= last_type
)
250 /* Need a new type prefix. */
252 char *newname
= type_name_no_tag (type
);
256 if (mangled_typename
)
257 free (mangled_typename
);
259 len
= strlen (newname
);
260 sprintf (buf
, "__%d", len
);
261 mangled_typename
= (char *)xmalloc (strlen (buf
) + len
+ 1);
262 strcpy (mangled_typename
, buf
);
263 strcat (mangled_typename
, newname
);
264 /* Now we have built "__#newname". */
266 return mangled_typename
;
269 /* Lookup a primitive type named NAME.
270 Return zero if NAME is not a primitive type.*/
273 lookup_primitive_typename (name
)
276 if (!strcmp (name
, "int"))
277 return builtin_type_int
;
278 if (!strcmp (name
, "long"))
279 return builtin_type_long
;
280 if (!strcmp (name
, "short"))
281 return builtin_type_short
;
282 if (!strcmp (name
, "char"))
283 return builtin_type_char
;
284 if (!strcmp (name
, "float"))
285 return builtin_type_float
;
286 if (!strcmp (name
, "double"))
287 return builtin_type_double
;
288 if (!strcmp (name
, "void"))
289 return builtin_type_void
;
293 /* Lookup a typedef or primitive type named NAME,
294 visible in lexical block BLOCK.
295 If NOERR is nonzero, return zero if NAME is not suitably defined. */
298 lookup_typename (name
, block
, noerr
)
303 register struct symbol
*sym
=
304 lookup_symbol (name
, block
, VAR_NAMESPACE
, 0, (struct symtab
**)NULL
);
305 if (sym
== 0 || SYMBOL_CLASS (sym
) != LOC_TYPEDEF
)
308 tmp
= lookup_primitive_typename (name
);
311 error ("No type named %s.", name
);
313 return SYMBOL_TYPE (sym
);
317 lookup_unsigned_typename (name
)
320 if (!strcmp (name
, "int"))
321 return builtin_type_unsigned_int
;
322 if (!strcmp (name
, "long"))
323 return builtin_type_unsigned_long
;
324 if (!strcmp (name
, "short"))
325 return builtin_type_unsigned_short
;
326 if (!strcmp (name
, "char"))
327 return builtin_type_unsigned_char
;
328 error ("No type named unsigned %s.", name
);
329 return (struct type
*)-1; /* for lint */
332 /* Lookup a structure type named "struct NAME",
333 visible in lexical block BLOCK. */
336 lookup_struct (name
, block
)
340 register struct symbol
*sym
341 = lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0, (struct symtab
**)NULL
);
344 error ("No struct type named %s.", name
);
345 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
346 error ("This context has class, union or enum %s, not a struct.", name
);
347 return SYMBOL_TYPE (sym
);
350 /* Lookup a union type named "union NAME",
351 visible in lexical block BLOCK. */
354 lookup_union (name
, block
)
358 register struct symbol
*sym
359 = lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0, (struct symtab
**)NULL
);
362 error ("No union type named %s.", name
);
363 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_UNION
)
364 error ("This context has class, struct or enum %s, not a union.", name
);
365 return SYMBOL_TYPE (sym
);
368 /* Lookup an enum type named "enum NAME",
369 visible in lexical block BLOCK. */
372 lookup_enum (name
, block
)
376 register struct symbol
*sym
377 = lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0, (struct symtab
**)NULL
);
379 error ("No enum type named %s.", name
);
380 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_ENUM
)
381 error ("This context has class, struct or union %s, not an enum.", name
);
382 return SYMBOL_TYPE (sym
);
385 /* Given a type TYPE, lookup the type of the component of type named
389 lookup_struct_elt_type (type
, name
)
395 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
396 && TYPE_CODE (type
) != TYPE_CODE_UNION
)
398 target_terminal_ours ();
400 fprintf (stderr
, "Type ");
401 type_print (type
, "", stderr
, -1);
402 error (" is not a structure or union type.");
405 for (i
= TYPE_NFIELDS (type
) - 1; i
>= TYPE_N_BASECLASSES (type
); i
--)
406 if (!strcmp (TYPE_FIELD_NAME (type
, i
), name
))
407 return TYPE_FIELD_TYPE (type
, i
);
409 target_terminal_ours ();
411 fprintf (stderr
, "Type ");
412 type_print (type
, "", stderr
, -1);
413 fprintf (stderr
, " has no component named ");
414 fputs_filtered (name
, stderr
);
416 return (struct type
*)-1; /* For lint */
419 /* Given a type TYPE, return a type of pointers to that type.
420 May need to construct such a type if this is the first use.
422 C++: use TYPE_MAIN_VARIANT and TYPE_CHAIN to keep pointer
423 to member types under control. */
426 lookup_pointer_type (type
)
429 register struct type
*ptype
= TYPE_POINTER_TYPE (type
);
430 if (ptype
) return TYPE_MAIN_VARIANT (ptype
);
432 /* This is the first time anyone wanted a pointer to a TYPE. */
433 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
434 ptype
= (struct type
*) xmalloc (sizeof (struct type
));
436 ptype
= (struct type
*) obstack_alloc (symbol_obstack
,
437 sizeof (struct type
));
439 bzero (ptype
, sizeof (struct type
));
440 TYPE_MAIN_VARIANT (ptype
) = ptype
;
441 TYPE_TARGET_TYPE (ptype
) = type
;
442 TYPE_POINTER_TYPE (type
) = ptype
;
443 /* New type is permanent if type pointed to is permanent. */
444 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
445 TYPE_FLAGS (ptype
) |= TYPE_FLAG_PERM
;
446 /* We assume the machine has only one representation for pointers! */
447 TYPE_LENGTH (ptype
) = sizeof (char *);
448 TYPE_CODE (ptype
) = TYPE_CODE_PTR
;
453 lookup_reference_type (type
)
456 register struct type
*rtype
= TYPE_REFERENCE_TYPE (type
);
457 if (rtype
) return TYPE_MAIN_VARIANT (rtype
);
459 /* This is the first time anyone wanted a pointer to a TYPE. */
460 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
461 rtype
= (struct type
*) xmalloc (sizeof (struct type
));
463 rtype
= (struct type
*) obstack_alloc (symbol_obstack
,
464 sizeof (struct type
));
466 bzero (rtype
, sizeof (struct type
));
467 TYPE_MAIN_VARIANT (rtype
) = rtype
;
468 TYPE_TARGET_TYPE (rtype
) = type
;
469 TYPE_REFERENCE_TYPE (type
) = rtype
;
470 /* New type is permanent if type pointed to is permanent. */
471 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
472 TYPE_FLAGS (rtype
) |= TYPE_FLAG_PERM
;
473 /* We assume the machine has only one representation for pointers! */
474 TYPE_LENGTH (rtype
) = sizeof (char *);
475 TYPE_CODE (rtype
) = TYPE_CODE_REF
;
480 /* Implement direct support for MEMBER_TYPE in GNU C++.
481 May need to construct such a type if this is the first use.
482 The TYPE is the type of the member. The DOMAIN is the type
483 of the aggregate that the member belongs to. */
486 lookup_member_type (type
, domain
)
487 struct type
*type
, *domain
;
489 register struct type
*mtype
= TYPE_MAIN_VARIANT (type
);
490 struct type
*main_type
;
495 if (TYPE_DOMAIN_TYPE (mtype
) == domain
)
497 mtype
= TYPE_NEXT_VARIANT (mtype
);
500 /* This is the first time anyone wanted this member type. */
501 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
502 mtype
= (struct type
*) xmalloc (sizeof (struct type
));
504 mtype
= (struct type
*) obstack_alloc (symbol_obstack
,
505 sizeof (struct type
));
507 bzero (mtype
, sizeof (struct type
));
512 TYPE_NEXT_VARIANT (mtype
) = TYPE_NEXT_VARIANT (main_type
);
513 TYPE_NEXT_VARIANT (main_type
) = mtype
;
515 TYPE_MAIN_VARIANT (mtype
) = main_type
;
516 TYPE_TARGET_TYPE (mtype
) = type
;
517 TYPE_DOMAIN_TYPE (mtype
) = domain
;
518 /* New type is permanent if type pointed to is permanent. */
519 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
520 TYPE_FLAGS (mtype
) |= TYPE_FLAG_PERM
;
522 /* In practice, this is never used. */
523 TYPE_LENGTH (mtype
) = 1;
524 TYPE_CODE (mtype
) = TYPE_CODE_MEMBER
;
527 /* Now splice in the new member pointer type. */
530 /* This type was not "smashed". */
531 TYPE_CHAIN (mtype
) = TYPE_CHAIN (main_type
);
532 TYPE_CHAIN (main_type
) = mtype
;
540 lookup_method_type (type
, domain
, args
)
541 struct type
*type
, *domain
, **args
;
543 register struct type
*mtype
= TYPE_MAIN_VARIANT (type
);
544 struct type
*main_type
;
549 if (TYPE_DOMAIN_TYPE (mtype
) == domain
)
551 struct type
**t1
= args
;
552 struct type
**t2
= TYPE_ARG_TYPES (mtype
);
556 for (i
= 0; t1
[i
] != 0 && t1
[i
]->code
!= TYPE_CODE_VOID
; i
++)
563 mtype
= TYPE_NEXT_VARIANT (mtype
);
566 /* This is the first time anyone wanted this member type. */
567 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
568 mtype
= (struct type
*) xmalloc (sizeof (struct type
));
570 mtype
= (struct type
*) obstack_alloc (symbol_obstack
,
571 sizeof (struct type
));
573 bzero (mtype
, sizeof (struct type
));
578 TYPE_NEXT_VARIANT (mtype
) = TYPE_NEXT_VARIANT (main_type
);
579 TYPE_NEXT_VARIANT (main_type
) = mtype
;
581 TYPE_MAIN_VARIANT (mtype
) = main_type
;
582 TYPE_TARGET_TYPE (mtype
) = type
;
583 TYPE_DOMAIN_TYPE (mtype
) = domain
;
584 TYPE_ARG_TYPES (mtype
) = args
;
585 /* New type is permanent if type pointed to is permanent. */
586 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
587 TYPE_FLAGS (mtype
) |= TYPE_FLAG_PERM
;
589 /* In practice, this is never used. */
590 TYPE_LENGTH (mtype
) = 1;
591 TYPE_CODE (mtype
) = TYPE_CODE_METHOD
;
594 /* Now splice in the new member pointer type. */
597 /* This type was not "smashed". */
598 TYPE_CHAIN (mtype
) = TYPE_CHAIN (main_type
);
599 TYPE_CHAIN (main_type
) = mtype
;
607 /* Given a type TYPE, return a type which has offset OFFSET,
608 via_virtual VIA_VIRTUAL, and via_public VIA_PUBLIC.
609 May need to construct such a type if none exists. */
611 lookup_basetype_type (type
, offset
, via_virtual
, via_public
)
614 int via_virtual
, via_public
;
616 register struct type
*btype
= TYPE_MAIN_VARIANT (type
);
617 struct type
*main_type
;
621 printf ("Internal error: type offset non-zero in lookup_basetype_type");
628 if (/* TYPE_OFFSET (btype) == offset
629 && */ TYPE_VIA_PUBLIC (btype
) == via_public
630 && TYPE_VIA_VIRTUAL (btype
) == via_virtual
)
632 btype
= TYPE_NEXT_VARIANT (btype
);
635 /* This is the first time anyone wanted this member type. */
636 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
637 btype
= (struct type
*) xmalloc (sizeof (struct type
));
639 btype
= (struct type
*) obstack_alloc (symbol_obstack
,
640 sizeof (struct type
));
645 bzero (btype
, sizeof (struct type
));
646 TYPE_MAIN_VARIANT (btype
) = main_type
;
650 bcopy (main_type
, btype
, sizeof (struct type
));
651 TYPE_NEXT_VARIANT (main_type
) = btype
;
653 /* TYPE_OFFSET (btype) = offset; */
655 TYPE_FLAGS (btype
) |= TYPE_FLAG_VIA_PUBLIC
;
657 TYPE_FLAGS (btype
) |= TYPE_FLAG_VIA_VIRTUAL
;
658 /* New type is permanent if type pointed to is permanent. */
659 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
660 TYPE_FLAGS (btype
) |= TYPE_FLAG_PERM
;
662 /* In practice, this is never used. */
663 TYPE_LENGTH (btype
) = 1;
664 TYPE_CODE (btype
) = TYPE_CODE_STRUCT
;
670 /* Given a type TYPE, return a type of functions that return that type.
671 May need to construct such a type if this is the first use. */
674 lookup_function_type (type
)
677 register struct type
*ptype
= TYPE_FUNCTION_TYPE (type
);
678 if (ptype
) return ptype
;
680 /* This is the first time anyone wanted a function returning a TYPE. */
681 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
682 ptype
= (struct type
*) xmalloc (sizeof (struct type
));
684 ptype
= (struct type
*) obstack_alloc (symbol_obstack
,
685 sizeof (struct type
));
687 bzero (ptype
, sizeof (struct type
));
688 TYPE_TARGET_TYPE (ptype
) = type
;
689 TYPE_FUNCTION_TYPE (type
) = ptype
;
690 /* New type is permanent if type returned is permanent. */
691 if (TYPE_FLAGS (type
) & TYPE_FLAG_PERM
)
692 TYPE_FLAGS (ptype
) |= TYPE_FLAG_PERM
;
693 TYPE_LENGTH (ptype
) = 1;
694 TYPE_CODE (ptype
) = TYPE_CODE_FUNC
;
695 TYPE_NFIELDS (ptype
) = 0;
699 /* Create an array type. Elements will be of type TYPE, and there will
702 Eventually this should be extended to take two more arguments which
703 specify the bounds of the array and the type of the index.
704 It should also be changed to be a "lookup" function, with the
705 appropriate data structures added to the type field.
706 Then read array type should call here. */
709 create_array_type (element_type
, number
)
710 struct type
*element_type
;
713 struct type
*result_type
= (struct type
*)
714 obstack_alloc (symbol_obstack
, sizeof (struct type
));
716 bzero (result_type
, sizeof (struct type
));
718 TYPE_CODE (result_type
) = TYPE_CODE_ARRAY
;
719 TYPE_TARGET_TYPE (result_type
) = element_type
;
720 TYPE_LENGTH (result_type
) = number
* TYPE_LENGTH (element_type
);
721 TYPE_NFIELDS (result_type
) = 1;
722 TYPE_FIELDS (result_type
) =
723 (struct field
*) obstack_alloc (symbol_obstack
, sizeof (struct field
));
724 TYPE_FIELD_TYPE (result_type
, 0) = builtin_type_int
;
725 TYPE_VPTR_FIELDNO (result_type
) = -1;
731 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE. */
734 smash_to_member_type (type
, domain
, to_type
)
735 struct type
*type
, *domain
, *to_type
;
737 bzero (type
, sizeof (struct type
));
738 TYPE_TARGET_TYPE (type
) = to_type
;
739 TYPE_DOMAIN_TYPE (type
) = domain
;
741 /* In practice, this is never needed. */
742 TYPE_LENGTH (type
) = 1;
743 TYPE_CODE (type
) = TYPE_CODE_MEMBER
;
745 TYPE_MAIN_VARIANT (type
) = lookup_member_type (domain
, to_type
);
748 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE. */
751 smash_to_method_type (type
, domain
, to_type
, args
)
752 struct type
*type
, *domain
, *to_type
, **args
;
754 bzero (type
, sizeof (struct type
));
755 TYPE_TARGET_TYPE (type
) = to_type
;
756 TYPE_DOMAIN_TYPE (type
) = domain
;
757 TYPE_ARG_TYPES (type
) = args
;
759 /* In practice, this is never needed. */
760 TYPE_LENGTH (type
) = 1;
761 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
763 TYPE_MAIN_VARIANT (type
) = lookup_method_type (domain
, to_type
, args
);
766 /* Find which partial symtab on the partial_symtab_list contains
767 PC. Return 0 if none. */
769 struct partial_symtab
*
771 register CORE_ADDR pc
;
773 register struct partial_symtab
*ps
;
775 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
776 if (pc
>= ps
->textlow
&& pc
< ps
->texthigh
)
782 /* Find which partial symbol within a psymtab contains PC. Return 0
783 if none. Check all psymtabs if PSYMTAB is 0. */
784 struct partial_symbol
*
785 find_pc_psymbol (psymtab
, pc
)
786 struct partial_symtab
*psymtab
;
789 struct partial_symbol
*best
, *p
;
793 psymtab
= find_pc_psymtab (pc
);
797 best_pc
= psymtab
->textlow
- 1;
799 for (p
= static_psymbols
.list
+ psymtab
->statics_offset
;
800 (p
- (static_psymbols
.list
+ psymtab
->statics_offset
)
801 < psymtab
->n_static_syms
);
803 if (SYMBOL_NAMESPACE (p
) == VAR_NAMESPACE
804 && SYMBOL_CLASS (p
) == LOC_BLOCK
805 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
806 && SYMBOL_VALUE_ADDRESS (p
) > best_pc
)
808 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
811 if (best_pc
== psymtab
->textlow
- 1)
817 /* Find the definition for a specified symbol name NAME
818 in namespace NAMESPACE, visible from lexical block BLOCK.
819 Returns the struct symbol pointer, or zero if no symbol is found.
820 If SYMTAB is non-NULL, store the symbol table in which the
821 symbol was found there, or NULL if not found.
822 C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
823 NAME is a field of the current implied argument `this'. If so set
824 *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
825 BLOCK_FOUND is set to the block in which NAME is found (in the case of
826 a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
829 lookup_symbol (name
, block
, namespace, is_a_field_of_this
, symtab
)
831 register struct block
*block
;
832 enum namespace namespace;
833 int *is_a_field_of_this
;
834 struct symtab
**symtab
;
836 register struct symbol
*sym
;
837 register struct symtab
*s
;
838 register struct partial_symtab
*ps
;
839 struct blockvector
*bv
;
841 /* Search specified block and its superiors. */
845 sym
= lookup_block_symbol (block
, name
, namespace);
851 /* Search the list of symtabs for one which contains the
852 address of the start of this block. */
854 for (s
= symtab_list
; s
; s
= s
->next
)
856 bv
= BLOCKVECTOR (s
);
857 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
858 if (BLOCK_START (b
) <= BLOCK_START (block
)
859 && BLOCK_END (b
) > BLOCK_START (block
))
867 block
= BLOCK_SUPERBLOCK (block
);
870 /* C++: If requested to do so by the caller,
871 check to see if NAME is a field of `this'. */
872 if (is_a_field_of_this
)
874 struct value
*v
= value_of_this (0);
876 *is_a_field_of_this
= 0;
877 if (v
&& check_field (v
, name
))
879 *is_a_field_of_this
= 1;
886 /* Now search all global blocks. Do the symtab's first, then
887 check the psymtab's */
889 for (s
= symtab_list
; s
; s
= s
->next
)
891 bv
= BLOCKVECTOR (s
);
892 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
893 sym
= lookup_block_symbol (block
, name
, namespace);
903 /* Check for the possibility of the symbol being a global function
904 that is stored on the misc function vector. Eventually, all
905 global symbols might be resolved in this way. */
907 if (namespace == VAR_NAMESPACE
)
909 int ind
= lookup_misc_func (name
);
911 /* Look for a mangled C++ name for NAME. */
914 int name_len
= strlen (name
);
916 for (ind
= misc_function_count
; --ind
>= 0; )
917 /* Assume orginal name is prefix of mangled name. */
918 if (!strncmp (misc_function_vector
[ind
].name
, name
, name_len
))
921 cplus_demangle(misc_function_vector
[ind
].name
, -1);
922 if (demangled
!= NULL
)
924 int cond
= strcmp (demangled
, name
);
930 /* Loop terminates on no match with ind == -1. */
935 s
= find_pc_symtab (misc_function_vector
[ind
].address
);
938 bv
= BLOCKVECTOR (s
);
939 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
940 sym
= lookup_block_symbol (block
, misc_function_vector
[ind
].name
,
942 /* sym == 0 if symbol was found in the misc_function_vector
943 but not in the symtab.
944 Return 0 to use the misc_function definition of "foo_".
946 This happens for Fortran "foo_" symbols,
947 which are "foo" in the symtab.
949 This can also happen if "asm" is used to make a
950 regular symbol but not a debugging symbol, e.g.
962 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
963 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 1, namespace))
965 s
= PSYMTAB_TO_SYMTAB(ps
);
966 bv
= BLOCKVECTOR (s
);
967 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
968 sym
= lookup_block_symbol (block
, name
, namespace);
970 fatal ("Internal: global symbol found in psymtab but not in symtab");
976 /* Now search all per-file blocks.
977 Not strictly correct, but more useful than an error.
978 Do the symtabs first, then check the psymtabs */
980 for (s
= symtab_list
; s
; s
= s
->next
)
982 bv
= BLOCKVECTOR (s
);
983 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
984 sym
= lookup_block_symbol (block
, name
, namespace);
994 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
995 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 0, namespace))
997 s
= PSYMTAB_TO_SYMTAB(ps
);
998 bv
= BLOCKVECTOR (s
);
999 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1000 sym
= lookup_block_symbol (block
, name
, namespace);
1002 fatal ("Internal: static symbol found in psymtab but not in symtab");
1013 /* Look, in partial_symtab PST, for symbol NAME. Check the global
1014 symbols if GLOBAL, the static symbols if not */
1016 static struct partial_symbol
*
1017 lookup_partial_symbol (pst
, name
, global
, namespace)
1018 struct partial_symtab
*pst
;
1021 enum namespace namespace;
1023 struct partial_symbol
*start
, *psym
;
1024 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
1027 return (struct partial_symbol
*) 0;
1030 global_psymbols
.list
+ pst
->globals_offset
:
1031 static_psymbols
.list
+ pst
->statics_offset
);
1033 if (global
) /* This means we can use a binary */
1036 struct partial_symbol
*top
, *bottom
, *center
;
1038 /* Binary search. This search is guaranteed to end with center
1039 pointing at the earliest partial symbol with the correct
1040 name. At that point *all* partial symbols with that name
1041 will be checked against the correct namespace. */
1043 top
= start
+ length
- 1;
1044 while (top
> bottom
)
1046 center
= bottom
+ (top
- bottom
) / 2;
1048 assert (center
< top
);
1050 if (strcmp (SYMBOL_NAME (center
), name
) >= 0)
1053 bottom
= center
+ 1;
1055 assert (top
== bottom
);
1057 while (!strcmp (SYMBOL_NAME (top
), name
))
1059 if (SYMBOL_NAMESPACE (top
) == namespace)
1066 /* Can't use a binary search */
1067 for (psym
= start
; psym
< start
+ length
; psym
++)
1068 if (namespace == SYMBOL_NAMESPACE (psym
)
1069 && !strcmp (name
, SYMBOL_NAME (psym
)))
1073 return (struct partial_symbol
*) 0;
1076 /* Look for a symbol in block BLOCK. */
1079 lookup_block_symbol (block
, name
, namespace)
1080 register struct block
*block
;
1082 enum namespace namespace;
1084 register int bot
, top
, inc
;
1085 register struct symbol
*sym
, *parameter_sym
;
1087 top
= BLOCK_NSYMS (block
);
1090 /* If the blocks's symbols were sorted, start with a binary search. */
1092 if (BLOCK_SHOULD_SORT (block
))
1094 /* First, advance BOT to not far before
1095 the first symbol whose name is NAME. */
1099 inc
= (top
- bot
+ 1);
1100 /* No need to keep binary searching for the last few bits worth. */
1103 inc
= (inc
>> 1) + bot
;
1104 sym
= BLOCK_SYM (block
, inc
);
1105 if (SYMBOL_NAME (sym
)[0] < name
[0])
1107 else if (SYMBOL_NAME (sym
)[0] > name
[0])
1109 else if (strcmp (SYMBOL_NAME (sym
), name
) < 0)
1115 /* Now scan forward until we run out of symbols,
1116 find one whose name is greater than NAME,
1117 or find one we want.
1118 If there is more than one symbol with the right name and namespace,
1119 we return the first one. dbxread.c is careful to make sure
1120 that if one is a register then it comes first. */
1122 top
= BLOCK_NSYMS (block
);
1125 sym
= BLOCK_SYM (block
, bot
);
1126 inc
= SYMBOL_NAME (sym
)[0] - name
[0];
1128 inc
= strcmp (SYMBOL_NAME (sym
), name
);
1129 if (inc
== 0 && SYMBOL_NAMESPACE (sym
) == namespace)
1138 /* Here if block isn't sorted.
1139 This loop is equivalent to the loop above,
1140 but hacked greatly for speed.
1142 Note that parameter symbols do not always show up last in the
1143 list; this loop makes sure to take anything else other than
1144 parameter symbols first; it only uses parameter symbols as a
1145 last resort. Note that this only takes up extra computation
1148 parameter_sym
= (struct symbol
*) 0;
1149 top
= BLOCK_NSYMS (block
);
1153 sym
= BLOCK_SYM (block
, bot
);
1154 if (SYMBOL_NAME (sym
)[0] == inc
1155 && !strcmp (SYMBOL_NAME (sym
), name
)
1156 && SYMBOL_NAMESPACE (sym
) == namespace)
1158 if (SYMBOL_CLASS (sym
) == LOC_ARG
1159 || SYMBOL_CLASS (sym
) == LOC_LOCAL_ARG
1160 || SYMBOL_CLASS (sym
) == LOC_REF_ARG
1161 || SYMBOL_CLASS (sym
) == LOC_REGPARM
)
1162 parameter_sym
= sym
;
1168 return parameter_sym
; /* Will be 0 if not found. */
1171 /* Return the symbol for the function which contains a specified
1172 lexical block, described by a struct block BL. */
1178 while (BLOCK_FUNCTION (bl
) == 0 && BLOCK_SUPERBLOCK (bl
) != 0)
1179 bl
= BLOCK_SUPERBLOCK (bl
);
1181 return BLOCK_FUNCTION (bl
);
1184 /* Subroutine of find_pc_line */
1188 register CORE_ADDR pc
;
1190 register struct block
*b
;
1191 struct blockvector
*bv
;
1192 register struct symtab
*s
;
1193 register struct partial_symtab
*ps
;
1195 /* Search all symtabs for one whose file contains our pc */
1197 for (s
= symtab_list
; s
; s
= s
->next
)
1199 bv
= BLOCKVECTOR (s
);
1200 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1201 if (BLOCK_START (b
) <= pc
1202 && BLOCK_END (b
) > pc
)
1208 ps
= find_pc_psymtab (pc
);
1209 if (ps
&& ps
->readin
)
1210 fatal ("Internal error: pc in read in psymtab, but not in symtab.");
1213 s
= PSYMTAB_TO_SYMTAB (ps
);
1219 /* Find the source file and line number for a given PC value.
1220 Return a structure containing a symtab pointer, a line number,
1221 and a pc range for the entire source line.
1222 The value's .pc field is NOT the specified pc.
1223 NOTCURRENT nonzero means, if specified pc is on a line boundary,
1224 use the line that ends there. Otherwise, in that case, the line
1225 that begins there is used. */
1227 struct symtab_and_line
1228 find_pc_line (pc
, notcurrent
)
1233 register struct linetable
*l
;
1236 register struct linetable_entry
*item
;
1237 struct symtab_and_line val
;
1238 struct blockvector
*bv
;
1240 /* Info on best line seen so far, and where it starts, and its file. */
1243 CORE_ADDR best_pc
= 0;
1244 CORE_ADDR best_end
= 0;
1245 struct symtab
*best_symtab
= 0;
1247 /* Store here the first line number
1248 of a file which contains the line at the smallest pc after PC.
1249 If we don't find a line whose range contains PC,
1250 we will use a line one less than this,
1251 with a range from the start of that file to the first line's pc. */
1253 CORE_ADDR alt_pc
= 0;
1254 struct symtab
*alt_symtab
= 0;
1256 /* Info on best line seen in this file. */
1261 /* Info on first line of this file. */
1266 /* If this pc is not from the current frame,
1267 it is the address of the end of a call instruction.
1268 Quite likely that is the start of the following statement.
1269 But what we want is the statement containing the instruction.
1270 Fudge the pc to make sure we get that. */
1272 if (notcurrent
) pc
-= 1;
1274 s
= find_pc_symtab (pc
);
1284 bv
= BLOCKVECTOR (s
);
1286 /* Look at all the symtabs that share this blockvector.
1287 They all have the same apriori range, that we found was right;
1288 but they have different line tables. */
1290 for (; s
&& BLOCKVECTOR (s
) == bv
; s
= s
->next
)
1292 /* Find the best line in this symtab. */
1297 for (i
= 0; i
< len
; i
++)
1299 item
= &(l
->item
[i
]);
1303 first_line
= item
->line
;
1304 first_pc
= item
->pc
;
1306 /* Return the last line that did not start after PC. */
1309 prev_line
= item
->line
;
1316 /* Is this file's best line closer than the best in the other files?
1317 If so, record this file, and its best line, as best so far. */
1318 if (prev_line
>= 0 && prev_pc
> best_pc
)
1321 best_line
= prev_line
;
1324 best_end
= item
->pc
;
1328 /* Is this file's first line closer than the first lines of other files?
1329 If so, record this file, and its first line, as best alternate. */
1330 if (first_line
>= 0 && first_pc
> pc
1331 && (alt_pc
== 0 || first_pc
< alt_pc
))
1334 alt_line
= first_line
;
1338 if (best_symtab
== 0)
1340 val
.symtab
= alt_symtab
;
1341 val
.line
= alt_line
- 1;
1342 val
.pc
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
1347 val
.symtab
= best_symtab
;
1348 val
.line
= best_line
;
1350 val
.end
= (best_end
? best_end
1352 : BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
))));
1357 /* Find the PC value for a given source file and line number.
1358 Returns zero for invalid line number.
1359 The source file is specified with a struct symtab. */
1362 find_line_pc (symtab
, line
)
1363 struct symtab
*symtab
;
1366 register struct linetable
*l
;
1372 l
= LINETABLE (symtab
);
1373 ind
= find_line_common(l
, line
, &dummy
);
1374 return (ind
>= 0) ? l
->item
[ind
].pc
: 0;
1377 /* Find the range of pc values in a line.
1378 Store the starting pc of the line into *STARTPTR
1379 and the ending pc (start of next line) into *ENDPTR.
1380 Returns 1 to indicate success.
1381 Returns 0 if could not find the specified line. */
1384 find_line_pc_range (symtab
, thisline
, startptr
, endptr
)
1385 struct symtab
*symtab
;
1387 CORE_ADDR
*startptr
, *endptr
;
1389 register struct linetable
*l
;
1391 int exact_match
; /* did we get an exact linenumber match */
1396 l
= LINETABLE (symtab
);
1397 ind
= find_line_common (l
, thisline
, &exact_match
);
1400 *startptr
= l
->item
[ind
].pc
;
1401 /* If we have not seen an entry for the specified line,
1402 assume that means the specified line has zero bytes. */
1403 if (!exact_match
|| ind
== l
->nitems
-1)
1404 *endptr
= *startptr
;
1406 /* Perhaps the following entry is for the following line.
1407 It's worth a try. */
1408 if (ind
+1 < l
->nitems
1409 && l
->item
[ind
+1].line
== thisline
+ 1)
1410 *endptr
= l
->item
[ind
+1].pc
;
1412 *endptr
= find_line_pc (symtab
, thisline
+1);
1419 /* Given a line table and a line number, return the index into the line
1420 table for the pc of the nearest line whose number is >= the specified one.
1421 Return -1 if none is found. The value is >= 0 if it is an index.
1423 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
1426 find_line_common (l
, lineno
, exact_match
)
1427 register struct linetable
*l
;
1428 register int lineno
;
1434 /* BEST is the smallest linenumber > LINENO so far seen,
1435 or 0 if none has been seen so far.
1436 BEST_INDEX identifies the item for it. */
1438 int best_index
= -1;
1445 for (i
= 0; i
< len
; i
++)
1447 register struct linetable_entry
*item
= &(l
->item
[i
]);
1449 if (item
->line
== lineno
)
1455 if (item
->line
> lineno
&& (best
== 0 || item
->line
< best
))
1462 /* If we got here, we didn't get an exact match. */
1469 find_pc_line_pc_range (pc
, startptr
, endptr
)
1471 CORE_ADDR
*startptr
, *endptr
;
1473 struct symtab_and_line sal
;
1474 sal
= find_pc_line (pc
, 0);
1477 return sal
.symtab
!= 0;
1480 /* Recursive helper function for decode_line_1.
1481 * Look for methods named NAME in type T.
1482 * Return number of matches.
1483 * Put matches in PHYSNAMES and SYM_ARR (which better be big enough!).
1484 * These allocations seem to define "big enough":
1485 * sym_arr = (struct symbol **) alloca(TYPE_NFN_FIELDS_TOTAL (t) * sizeof(struct symbol*));
1486 * physnames = (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t) * sizeof(char*));
1490 find_methods(t
, name
, physnames
, sym_arr
)
1494 struct symbol
**sym_arr
;
1498 struct symbol
*sym_class
;
1499 char *class_name
= type_name_no_tag (t
);
1500 /* Ignore this class if it doesn't have a name.
1501 This prevents core dumps, but is just a workaround
1502 because we might not find the function in
1503 certain cases, such as
1504 struct D {virtual int f();}
1505 struct C : D {virtual int g();}
1506 (in this case g++ 1.35.1- does not put out a name
1507 for D as such, it defines type 19 (for example) in
1508 the same stab as C, and then does a
1509 .stabs "D:T19" and a .stabs "D:t19".
1511 "break C::f" should not be looking for field f in
1513 but just for the field f in the baseclasses of C
1514 (no matter what their names).
1516 However, I don't know how to replace the code below
1517 that depends on knowing the name of D. */
1519 && (sym_class
= lookup_symbol (class_name
,
1520 (struct block
*)NULL
,
1523 (struct symtab
**)NULL
)))
1526 t
= SYMBOL_TYPE (sym_class
);
1527 for (method_counter
= TYPE_NFN_FIELDS (t
) - 1;
1528 method_counter
>= 0;
1532 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, method_counter
);
1534 char *method_name
= TYPE_FN_FIELDLIST_NAME (t
, method_counter
);
1535 if (!strcmp (name
, method_name
))
1536 /* Find all the fields with that name. */
1537 for (field_counter
= TYPE_FN_FIELDLIST_LENGTH (t
, method_counter
) - 1;
1542 if (TYPE_FLAGS (TYPE_FN_FIELD_TYPE (f
, field_counter
)) & TYPE_FLAG_STUB
)
1543 check_stub_method (t
, method_counter
, field_counter
);
1544 phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, field_counter
);
1545 physnames
[i1
] = (char*) alloca (strlen (phys_name
) + 1);
1546 strcpy (physnames
[i1
], phys_name
);
1547 sym_arr
[i1
] = lookup_symbol (phys_name
,
1548 SYMBOL_BLOCK_VALUE (sym_class
),
1551 (struct symtab
**) NULL
);
1552 if (sym_arr
[i1
]) i1
++;
1556 /* Only search baseclasses if there is no match yet,
1557 * since names in derived classes override those in baseclasses.
1561 for (ibase
= 0; ibase
< TYPE_N_BASECLASSES (t
); ibase
++)
1562 i1
+= find_methods(TYPE_BASECLASS(t
, ibase
), name
,
1563 physnames
+ i1
, sym_arr
+ i1
);
1567 /* Parse a string that specifies a line number.
1568 Pass the address of a char * variable; that variable will be
1569 advanced over the characters actually parsed.
1573 LINENUM -- that line number in current file. PC returned is 0.
1574 FILE:LINENUM -- that line in that file. PC returned is 0.
1575 FUNCTION -- line number of openbrace of that function.
1576 PC returned is the start of the function.
1577 VARIABLE -- line number of definition of that variable.
1579 FILE:FUNCTION -- likewise, but prefer functions in that file.
1580 *EXPR -- line in which address EXPR appears.
1582 FUNCTION may be an undebuggable function found in misc_function_vector.
1584 If the argument FUNFIRSTLINE is nonzero, we want the first line
1585 of real code inside a function when a function is specified.
1587 DEFAULT_SYMTAB specifies the file to use if none is specified.
1588 It defaults to current_source_symtab.
1589 DEFAULT_LINE specifies the line number to use for relative
1590 line numbers (that start with signs). Defaults to current_source_line.
1592 Note that it is possible to return zero for the symtab
1593 if no file is validly specified. Callers must check that.
1594 Also, the line number returned may be invalid. */
1596 struct symtabs_and_lines
1597 decode_line_1 (argptr
, funfirstline
, default_symtab
, default_line
)
1600 struct symtab
*default_symtab
;
1603 struct symtabs_and_lines
decode_line_2 ();
1604 struct symtabs_and_lines values
;
1605 struct symtab_and_line val
;
1606 register char *p
, *p1
;
1607 register struct symtab
*s
;
1609 register struct symbol
*sym
;
1610 /* The symtab that SYM was found in. */
1611 struct symtab
*sym_symtab
;
1613 register CORE_ADDR pc
;
1616 struct symbol
*sym_class
;
1618 struct symbol
**sym_arr
;
1622 /* Defaults have defaults. */
1624 if (default_symtab
== 0)
1626 default_symtab
= current_source_symtab
;
1627 default_line
= current_source_line
;
1630 /* See if arg is *PC */
1632 if (**argptr
== '*')
1635 pc
= parse_and_eval_address_1 (argptr
);
1636 values
.sals
= (struct symtab_and_line
*)
1637 xmalloc (sizeof (struct symtab_and_line
));
1639 values
.sals
[0] = find_pc_line (pc
, 0);
1640 values
.sals
[0].pc
= pc
;
1644 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
1648 for (p
= *argptr
; *p
; p
++)
1650 if (p
[0] == ':' || p
[0] == ' ' || p
[0] == '\t')
1653 while (p
[0] == ' ' || p
[0] == '\t') p
++;
1661 /* Extract the class name. */
1663 while (p
!= *argptr
&& p
[-1] == ' ') --p
;
1664 copy
= (char *) alloca (p
- *argptr
+ 1);
1665 bcopy (*argptr
, copy
, p
- *argptr
);
1666 copy
[p
- *argptr
] = 0;
1668 /* Discard the class name from the arg. */
1670 while (*p
== ' ' || *p
== '\t') p
++;
1673 sym_class
= lookup_symbol (copy
, 0, STRUCT_NAMESPACE
, 0,
1674 (struct symtab
**)NULL
);
1677 (TYPE_CODE (SYMBOL_TYPE (sym_class
)) == TYPE_CODE_STRUCT
1678 || TYPE_CODE (SYMBOL_TYPE (sym_class
)) == TYPE_CODE_UNION
))
1680 /* Arg token is not digits => try it as a function name
1681 Find the next token (everything up to end or next whitespace). */
1683 while (*p
&& *p
!= ' ' && *p
!= '\t' && *p
!= ',' && *p
!=':') p
++;
1684 copy
= (char *) alloca (p
- *argptr
+ 1);
1685 bcopy (*argptr
, copy
, p
- *argptr
);
1686 copy
[p
- *argptr
] = '\0';
1688 /* no line number may be specified */
1689 while (*p
== ' ' || *p
== '\t') p
++;
1693 i1
= 0; /* counter for the symbol array */
1694 t
= SYMBOL_TYPE (sym_class
);
1695 sym_arr
= (struct symbol
**) alloca(TYPE_NFN_FIELDS_TOTAL (t
) * sizeof(struct symbol
*));
1696 physnames
= (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t
) * sizeof(char*));
1698 if (destructor_name_p (copy
, t
))
1700 /* destructors are a special case. */
1701 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, 0);
1702 int len
= TYPE_FN_FIELDLIST_LENGTH (t
, 0) - 1;
1703 char *phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, len
);
1704 physnames
[i1
] = (char *)alloca (strlen (phys_name
) + 1);
1705 strcpy (physnames
[i1
], phys_name
);
1707 lookup_symbol (phys_name
, SYMBOL_BLOCK_VALUE (sym_class
),
1708 VAR_NAMESPACE
, 0, (struct symtab
**)NULL
);
1709 if (sym_arr
[i1
]) i1
++;
1712 i1
= find_methods (t
, copy
, physnames
, sym_arr
);
1715 /* There is exactly one field with that name. */
1718 if (sym
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1720 /* Arg is the name of a function */
1721 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) + FUNCTION_START_OFFSET
;
1724 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
1726 values
.sals
[0] = find_pc_line (pc
, 0);
1727 values
.sals
[0].pc
= (values
.sals
[0].end
&& values
.sals
[0].pc
!= pc
) ? values
.sals
[0].end
: pc
;
1737 /* There is more than one field with that name
1738 (overloaded). Ask the user which one to use. */
1739 return decode_line_2 (sym_arr
, i1
, funfirstline
);
1742 error ("that class does not have any method named %s",copy
);
1745 /* The quotes are important if copy is empty. */
1746 error("No class, struct, or union named \"%s\"", copy
);
1751 /* Extract the file name. */
1753 while (p
!= *argptr
&& p
[-1] == ' ') --p
;
1754 copy
= (char *) alloca (p
- *argptr
+ 1);
1755 bcopy (*argptr
, copy
, p
- *argptr
);
1756 copy
[p
- *argptr
] = 0;
1758 /* Find that file's data. */
1759 s
= lookup_symtab (copy
);
1762 if (symtab_list
== 0 && partial_symtab_list
== 0)
1763 error (no_symtab_msg
);
1764 error ("No source file named %s.", copy
);
1767 /* Discard the file name from the arg. */
1769 while (*p
== ' ' || *p
== '\t') p
++;
1773 /* S is specified file's symtab, or 0 if no file specified.
1774 arg no longer contains the file name. */
1776 /* Check whether arg is all digits (and sign) */
1779 if (*p
== '-' || *p
== '+') p
++;
1780 while (*p
>= '0' && *p
<= '9')
1783 if (p
!= *argptr
&& (*p
== 0 || *p
== ' ' || *p
== '\t' || *p
== ','))
1785 /* We found a token consisting of all digits -- at least one digit. */
1786 enum sign
{none
, plus
, minus
} sign
= none
;
1788 /* This is where we need to make sure that we have good defaults.
1789 We must guarantee that this section of code is never executed
1790 when we are called with just a function name, since
1791 select_source_symtab calls us with such an argument */
1793 if (s
== 0 && default_symtab
== 0)
1795 if (symtab_list
== 0 && partial_symtab_list
== 0)
1796 error (no_symtab_msg
);
1797 select_source_symtab (0);
1798 default_symtab
= current_source_symtab
;
1799 default_line
= current_source_line
;
1802 if (**argptr
== '+')
1803 sign
= plus
, (*argptr
)++;
1804 else if (**argptr
== '-')
1805 sign
= minus
, (*argptr
)++;
1806 val
.line
= atoi (*argptr
);
1813 val
.line
= default_line
+ val
.line
;
1819 val
.line
= default_line
- val
.line
;
1824 break; /* No need to adjust val.line. */
1827 while (*p
== ' ' || *p
== '\t') p
++;
1833 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
1834 values
.sals
[0] = val
;
1839 /* Arg token is not digits => try it as a variable name
1840 Find the next token (everything up to end or next whitespace). */
1842 while (*p
&& *p
!= ' ' && *p
!= '\t' && *p
!= ',') p
++;
1843 copy
= (char *) alloca (p
- *argptr
+ 1);
1844 bcopy (*argptr
, copy
, p
- *argptr
);
1845 copy
[p
- *argptr
] = 0;
1846 while (*p
== ' ' || *p
== '\t') p
++;
1849 /* Look up that token as a variable.
1850 If file specified, use that file's per-file block to start with. */
1852 sym
= lookup_symbol (copy
,
1853 (s
? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
)
1854 : get_selected_block ()),
1855 VAR_NAMESPACE
, 0, &sym_symtab
);
1859 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1861 /* Arg is the name of a function */
1862 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) + FUNCTION_START_OFFSET
;
1865 val
= find_pc_line (pc
, 0);
1866 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
1867 /* Convex: no need to suppress code on first line, if any */
1870 val
.pc
= (val
.end
&& val
.pc
!= pc
) ? val
.end
: pc
;
1872 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
1873 values
.sals
[0] = val
;
1876 /* I think this is always the same as the line that
1877 we calculate above, but the general principle is
1878 "trust the symbols more than stuff like
1880 if (SYMBOL_LINE (sym
) != 0)
1881 values
.sals
[0].line
= SYMBOL_LINE (sym
);
1885 else if (SYMBOL_LINE (sym
) != 0)
1887 /* We know its line number. */
1888 values
.sals
= (struct symtab_and_line
*)
1889 xmalloc (sizeof (struct symtab_and_line
));
1891 bzero (&values
.sals
[0], sizeof (values
.sals
[0]));
1892 values
.sals
[0].symtab
= sym_symtab
;
1893 values
.sals
[0].line
= SYMBOL_LINE (sym
);
1897 /* This can happen if it is compiled with a compiler which doesn't
1898 put out line numbers for variables. */
1899 error ("Line number not known for symbol \"%s\"", copy
);
1902 if (symtab_list
== 0 && partial_symtab_list
== 0)
1903 error (no_symtab_msg
);
1905 if ((i
= lookup_misc_func (copy
)) >= 0)
1909 val
.pc
= misc_function_vector
[i
].address
+ FUNCTION_START_OFFSET
;
1911 SKIP_PROLOGUE (val
.pc
);
1912 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
1913 values
.sals
[0] = val
;
1918 error ("Function %s not defined.", copy
);
1919 return values
; /* for lint */
1922 struct symtabs_and_lines
1923 decode_line_spec (string
, funfirstline
)
1927 struct symtabs_and_lines sals
;
1929 error ("Empty line specification.");
1930 sals
= decode_line_1 (&string
, funfirstline
,
1931 current_source_symtab
, current_source_line
);
1933 error ("Junk at end of line specification: %s", string
);
1937 /* Given a list of NELTS symbols in sym_arr (with corresponding
1938 mangled names in physnames), return a list of lines to operate on
1939 (ask user if necessary). */
1940 struct symtabs_and_lines
1941 decode_line_2 (sym_arr
, nelts
, funfirstline
)
1942 struct symbol
*sym_arr
[];
1947 struct symtabs_and_lines values
, return_values
;
1948 register CORE_ADDR pc
;
1949 char *args
, *arg1
, *command_line_input ();
1953 values
.sals
= (struct symtab_and_line
*) alloca (nelts
* sizeof(struct symtab_and_line
));
1954 return_values
.sals
= (struct symtab_and_line
*) xmalloc (nelts
* sizeof(struct symtab_and_line
));
1957 printf("[0] cancel\n[1] all\n");
1960 if (sym_arr
[i
] && SYMBOL_CLASS (sym_arr
[i
]) == LOC_BLOCK
)
1962 /* Arg is the name of a function */
1963 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym_arr
[i
]))
1964 + FUNCTION_START_OFFSET
;
1967 values
.sals
[i
] = find_pc_line (pc
, 0);
1968 values
.sals
[i
].pc
= (values
.sals
[i
].end
&& values
.sals
[i
].pc
!= pc
) ?
1969 values
.sals
[i
].end
: pc
;
1970 printf("[%d] file:%s; line number:%d\n",
1971 (i
+2), values
.sals
[i
].symtab
->filename
, values
.sals
[i
].line
);
1973 else printf ("?HERE\n");
1977 if ((prompt
= getenv ("PS2")) == NULL
)
1981 printf("%s ",prompt
);
1984 args
= command_line_input (0, 0);
1987 error_no_arg ("one or more choice numbers");
1995 while (*arg1
>= '0' && *arg1
<= '9') arg1
++;
1996 if (*arg1
&& *arg1
!= ' ' && *arg1
!= '\t')
1997 error ("Arguments must be choice numbers.");
2002 error ("cancelled");
2005 bcopy (values
.sals
, return_values
.sals
, (nelts
* sizeof(struct symtab_and_line
)));
2006 return_values
.nelts
= nelts
;
2007 return return_values
;
2010 if (num
> nelts
+ 2)
2012 printf ("No choice number %d.\n", num
);
2017 if (values
.sals
[num
].pc
)
2019 return_values
.sals
[i
++] = values
.sals
[num
];
2020 values
.sals
[num
].pc
= 0;
2024 printf ("duplicate request for %d ignored.\n", num
);
2029 while (*args
== ' ' || *args
== '\t') args
++;
2031 return_values
.nelts
= i
;
2032 return return_values
;
2035 /* Return the index of misc function named NAME. */
2038 lookup_misc_func (name
)
2039 register char *name
;
2043 for (i
= 0; i
< misc_function_count
; i
++)
2044 if (!strcmp (misc_function_vector
[i
].name
, name
))
2046 return -1; /* not found */
2049 /* Slave routine for sources_info. Force line breaks at ,'s.
2050 NAME is the name to print and *FIRST is nonzero if this is the first
2051 name printed. Set *FIRST to zero. */
2053 output_source_filename (name
, first
)
2058 /* Table of files printed so far. Since a single source file can
2059 result in several partial symbol tables, we need to avoid printing
2060 it more than once. Note: if some of the psymtabs are read in and
2061 some are not, it gets printed both under "Source files for which
2062 symbols have been read" and "Source files for which symbols will
2063 be read in on demand". I consider this a reasonable way to deal
2064 with the situation. I'm not sure whether this can also happen for
2065 symtabs; it doesn't hurt to check. */
2066 static char **tab
= NULL
;
2067 /* Allocated size of tab in elements.
2068 Start with one 256-byte block (when using GNU malloc.c).
2069 24 is the malloc overhead when range checking is in effect. */
2070 static int tab_alloc_size
= (256 - 24) / sizeof (char *);
2071 /* Current size of tab in elements. */
2072 static int tab_cur_size
;
2079 tab
= (char **) xmalloc (tab_alloc_size
* sizeof (*tab
));
2083 /* Is NAME in tab? */
2084 for (p
= tab
; p
< tab
+ tab_cur_size
; p
++)
2085 if (strcmp (*p
, name
) == 0)
2086 /* Yes; don't print it again. */
2088 /* No; add it to tab. */
2089 if (tab_cur_size
== tab_alloc_size
)
2091 tab_alloc_size
*= 2;
2092 tab
= (char **) xrealloc (tab
, tab_alloc_size
* sizeof (*tab
));
2094 tab
[tab_cur_size
++] = name
;
2103 printf_filtered (",");
2107 if (column
!= 0 && column
+ strlen (name
) >= 70)
2109 printf_filtered ("\n");
2112 else if (column
!= 0)
2114 printf_filtered (" ");
2117 fputs_filtered (name
, stdout
);
2118 column
+= strlen (name
);
2124 register struct symtab
*s
;
2125 register struct partial_symtab
*ps
;
2128 if (symtab_list
== 0 && partial_symtab_list
== 0)
2130 printf (no_symtab_msg
);
2134 printf_filtered ("Source files for which symbols have been read in:\n\n");
2137 for (s
= symtab_list
; s
; s
= s
->next
)
2138 output_source_filename (s
->filename
, &first
);
2139 printf_filtered ("\n\n");
2141 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2144 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
2146 output_source_filename (ps
->filename
, &first
);
2147 printf_filtered ("\n");
2150 /* List all symbols (if REGEXP is 0) or all symbols matching REGEXP.
2151 If CLASS is zero, list all symbols except functions and type names.
2152 If CLASS is 1, list only functions.
2153 If CLASS is 2, list only type names.
2155 BPT is non-zero if we should set a breakpoint at the functions
2159 list_symbols (regexp
, class, bpt
)
2164 register struct symtab
*s
;
2165 register struct partial_symtab
*ps
;
2166 register struct blockvector
*bv
;
2167 struct blockvector
*prev_bv
= 0;
2168 register struct block
*b
;
2170 register struct symbol
*sym
;
2171 struct partial_symbol
*psym
;
2173 static char *classnames
[]
2174 = {"variable", "function", "type", "method"};
2175 int found_in_file
= 0;
2178 if (0 != (val
= (char *) re_comp (regexp
)))
2179 error ("Invalid regexp (%s): %s", val
, regexp
);
2181 /* Search through the partial_symtab_list *first* for all symbols
2182 matching the regexp. That way we don't have to reproduce all of
2183 the machinery below. */
2184 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
2186 struct partial_symbol
*bound
, *gbound
, *sbound
;
2189 if (ps
->readin
) continue;
2191 gbound
= global_psymbols
.list
+ ps
->globals_offset
+ ps
->n_global_syms
;
2192 sbound
= static_psymbols
.list
+ ps
->statics_offset
+ ps
->n_static_syms
;
2195 /* Go through all of the symbols stored in a partial
2196 symtab in one loop. */
2197 psym
= global_psymbols
.list
+ ps
->globals_offset
;
2202 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
2204 psym
= static_psymbols
.list
+ ps
->statics_offset
;
2215 /* If it would match (logic taken from loop below)
2216 load the file and go on to the next one */
2217 if ((regexp
== 0 || re_exec (SYMBOL_NAME (psym
)))
2218 && ((class == 0 && SYMBOL_CLASS (psym
) != LOC_TYPEDEF
2219 && SYMBOL_CLASS (psym
) != LOC_BLOCK
)
2220 || (class == 1 && SYMBOL_CLASS (psym
) == LOC_BLOCK
)
2221 || (class == 2 && SYMBOL_CLASS (psym
) == LOC_TYPEDEF
)
2222 || (class == 3 && SYMBOL_CLASS (psym
) == LOC_BLOCK
)))
2224 (void) PSYMTAB_TO_SYMTAB(ps
);
2232 /* Here, *if* the class is correct (function only, right now), we
2233 search through the misc function vector for symbols that
2234 match, and call find_pc_symtab on them to force their symbols to
2235 be read. The symbol will then be found during the scan of symtabs
2240 for (i
= 0; i
< misc_function_count
; i
++)
2241 if (regexp
== 0 || re_exec (misc_function_vector
[i
].name
))
2243 (void) find_pc_symtab (misc_function_vector
[i
].address
);
2247 /* Printout here so as to get after the "Reading in symbols"
2248 messages which will be generated above. */
2250 printf_filtered (regexp
2251 ? "All %ss matching regular expression \"%s\":\n"
2252 : "All defined %ss:\n",
2256 for (s
= symtab_list
; s
; s
= s
->next
)
2259 bv
= BLOCKVECTOR (s
);
2260 /* Often many files share a blockvector.
2261 Scan each blockvector only once so that
2262 we don't get every symbol many times.
2263 It happens that the first symtab in the list
2264 for any given blockvector is the main file. */
2266 for (i
= GLOBAL_BLOCK
; i
<= STATIC_BLOCK
; i
++)
2268 b
= BLOCKVECTOR_BLOCK (bv
, i
);
2269 /* Skip the sort if this block is always sorted. */
2270 if (!BLOCK_SHOULD_SORT (b
))
2271 sort_block_syms (b
);
2272 for (j
= 0; j
< BLOCK_NSYMS (b
); j
++)
2275 sym
= BLOCK_SYM (b
, j
);
2276 if ((regexp
== 0 || re_exec (SYMBOL_NAME (sym
)))
2277 && ((class == 0 && SYMBOL_CLASS (sym
) != LOC_TYPEDEF
2278 && SYMBOL_CLASS (sym
) != LOC_BLOCK
)
2279 || (class == 1 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
2280 || (class == 2 && SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
2281 || (class == 3 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)))
2285 /* Set a breakpoint here, if it's a function */
2287 break_command (SYMBOL_NAME(sym
), 0);
2289 else if (!found_in_file
)
2291 fputs_filtered ("\nFile ", stdout
);
2292 fputs_filtered (s
->filename
, stdout
);
2293 fputs_filtered (":\n", stdout
);
2297 if (class != 2 && i
== STATIC_BLOCK
)
2298 printf_filtered ("static ");
2300 && SYMBOL_NAMESPACE (sym
) != STRUCT_NAMESPACE
)
2301 printf_filtered ("typedef ");
2305 type_print (SYMBOL_TYPE (sym
),
2306 (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
2307 ? "" : SYMBOL_NAME (sym
)),
2311 && SYMBOL_NAMESPACE (sym
) != STRUCT_NAMESPACE
2312 && (TYPE_NAME ((SYMBOL_TYPE (sym
))) == 0
2313 || 0 != strcmp (TYPE_NAME ((SYMBOL_TYPE (sym
))),
2314 SYMBOL_NAME (sym
))))
2316 fputs_filtered (" ", stdout
);
2317 fprint_symbol (stdout
, SYMBOL_NAME (sym
));
2320 printf_filtered (";\n");
2326 type_print_base (TYPE_FN_FIELD_TYPE(t
, i
), stdout
, 0, 0);
2327 type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t
, i
), stdout
, 0);
2328 sprintf (buf
, " %s::", type_name_no_tag (t
));
2329 type_print_method_args (TYPE_FN_FIELD_ARGS (t
, i
), buf
, name
, stdout
);
2340 variables_info (regexp
)
2343 list_symbols (regexp
, 0, 0);
2347 functions_info (regexp
)
2350 list_symbols (regexp
, 1, 0);
2357 list_symbols (regexp
, 2, 0);
2361 /* Tiemann says: "info methods was never implemented." */
2363 methods_info (regexp
)
2366 list_symbols (regexp
, 3, 0);
2370 /* Breakpoint all functions matching regular expression. */
2372 rbreak_command (regexp
)
2375 list_symbols (regexp
, 1, 1);
2378 /* Initialize the standard C scalar types. */
2382 init_type (code
, length
, uns
, name
)
2383 enum type_code code
;
2387 register struct type
*type
;
2389 type
= (struct type
*) xmalloc (sizeof (struct type
));
2390 bzero (type
, sizeof *type
);
2391 TYPE_MAIN_VARIANT (type
) = type
;
2392 TYPE_CODE (type
) = code
;
2393 TYPE_LENGTH (type
) = length
;
2394 TYPE_FLAGS (type
) = uns
? TYPE_FLAG_UNSIGNED
: 0;
2395 TYPE_FLAGS (type
) |= TYPE_FLAG_PERM
;
2396 TYPE_NFIELDS (type
) = 0;
2397 TYPE_NAME (type
) = name
;
2400 TYPE_NFN_FIELDS (type
) = 0;
2401 TYPE_N_BASECLASSES (type
) = 0;
2405 /* Return Nonzero if block a is lexically nested within block b,
2406 or if a and b have the same pc range.
2407 Return zero otherwise. */
2410 struct block
*a
, *b
;
2414 return BLOCK_START (a
) >= BLOCK_START (b
)
2415 && BLOCK_END (a
) <= BLOCK_END (b
);
2419 /* Helper routine for make_symbol_completion_list. */
2421 int return_val_size
, return_val_index
;
2425 completion_list_add_symbol (symname
)
2428 if (return_val_index
+ 3 > return_val_size
)
2430 (char **)xrealloc (return_val
,
2431 (return_val_size
*= 2) * sizeof (char *));
2433 return_val
[return_val_index
] =
2434 (char *)xmalloc (1 + strlen (symname
));
2436 strcpy (return_val
[return_val_index
], symname
);
2438 return_val
[++return_val_index
] = (char *)NULL
;
2441 /* Return a NULL terminated array of all symbols (regardless of class) which
2442 begin by matching TEXT. If the answer is no symbols, then the return value
2443 is an array which contains only a NULL pointer.
2445 Problem: All of the symbols have to be copied because readline
2446 frees them. I'm not going to worry about this; hopefully there
2447 won't be that many. */
2450 make_symbol_completion_list (text
)
2453 register struct symtab
*s
;
2454 register struct partial_symtab
*ps
;
2455 register struct block
*b
, *surrounding_static_block
= 0;
2456 extern struct block
*get_selected_block ();
2458 struct partial_symbol
*psym
;
2460 int text_len
= strlen (text
);
2461 return_val_size
= 100;
2462 return_val_index
= 0;
2464 (char **)xmalloc ((1 + return_val_size
) *sizeof (char *));
2465 return_val
[0] = (char *)NULL
;
2467 /* Look through the partial symtabs for all symbols which begin
2468 by matching TEXT. Add each one that you find to the list. */
2470 for (ps
= partial_symtab_list
; ps
; ps
= ps
->next
)
2472 /* If the psymtab's been read in we'll get it when we search
2473 through the blockvector. */
2474 if (ps
->readin
) continue;
2476 for (psym
= global_psymbols
.list
+ ps
->globals_offset
;
2477 psym
< (global_psymbols
.list
+ ps
->globals_offset
2478 + ps
->n_global_syms
);
2481 QUIT
; /* If interrupted, then quit. */
2482 if ((strncmp (SYMBOL_NAME (psym
), text
, text_len
) == 0))
2483 completion_list_add_symbol (SYMBOL_NAME (psym
));
2486 for (psym
= static_psymbols
.list
+ ps
->statics_offset
;
2487 psym
< (static_psymbols
.list
+ ps
->statics_offset
2488 + ps
->n_static_syms
);
2492 if ((strncmp (SYMBOL_NAME (psym
), text
, text_len
) == 0))
2493 completion_list_add_symbol (SYMBOL_NAME (psym
));
2497 /* At this point scan through the misc function vector and add each
2498 symbol you find to the list. Eventually we want to ignore
2499 anything that isn't a text symbol (everything else will be
2500 handled by the psymtab code above). */
2502 for (i
= 0; i
< misc_function_count
; i
++)
2503 if (!strncmp (text
, misc_function_vector
[i
].name
, text_len
))
2504 completion_list_add_symbol (misc_function_vector
[i
].name
);
2506 /* Search upwards from currently selected frame (so that we can
2507 complete on local vars. */
2508 for (b
= get_selected_block (); b
; b
= BLOCK_SUPERBLOCK (b
))
2510 if (!BLOCK_SUPERBLOCK (b
))
2511 surrounding_static_block
= b
; /* For elmin of dups */
2513 /* Also catch fields of types defined in this places which
2514 match our text string. Only complete on types visible
2515 from current context. */
2516 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2518 register struct symbol
*sym
= BLOCK_SYM (b
, i
);
2520 if (!strncmp (SYMBOL_NAME (sym
), text
, text_len
))
2521 completion_list_add_symbol (SYMBOL_NAME (sym
));
2523 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
2525 struct type
*t
= SYMBOL_TYPE (sym
);
2526 enum type_code c
= TYPE_CODE (t
);
2528 if (c
== TYPE_CODE_UNION
|| c
== TYPE_CODE_STRUCT
)
2529 for (j
= TYPE_N_BASECLASSES (t
); j
< TYPE_NFIELDS (t
); j
++)
2530 if (TYPE_FIELD_NAME (t
, j
) &&
2531 !strncmp (TYPE_FIELD_NAME (t
, j
), text
, text_len
))
2532 completion_list_add_symbol (TYPE_FIELD_NAME (t
, j
));
2537 /* Go through the symtabs and check the externs and statics for
2538 symbols which match. */
2540 for (s
= symtab_list
; s
; s
= s
->next
)
2542 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
2544 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2545 if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b
, i
)), text
, text_len
))
2546 completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b
, i
)));
2549 for (s
= symtab_list
; s
; s
= s
->next
)
2551 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
2553 /* Don't do this block twice. */
2554 if (b
== surrounding_static_block
) continue;
2556 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2557 if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b
, i
)), text
, text_len
))
2558 completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b
, i
)));
2561 return (return_val
);
2565 _initialize_symtab ()
2567 add_info ("variables", variables_info
,
2568 "All global and static variable names, or those matching REGEXP.");
2569 add_info ("functions", functions_info
,
2570 "All function names, or those matching REGEXP.");
2572 /* FIXME: This command has at least the following problems:
2573 1. It prints builtin types (in a very strange and confusing fashion).
2574 2. It doesn't print right, e.g. with
2575 typedef struct foo *FOO
2576 type_print prints "FOO" when we want to make it (in this situation)
2577 print "struct foo *".
2578 I also think "ptype" or "whatis" is more likely to be useful (but if
2579 there is much disagreement "info types" can be fixed). */
2580 add_info ("types", types_info
,
2581 "All types names, or those matching REGEXP.");
2584 add_info ("methods", methods_info
,
2585 "All method names, or those matching REGEXP::REGEXP.\n\
2586 If the class qualifier is ommited, it is assumed to be the current scope.\n\
2587 If the first REGEXP is ommited, then all methods matching the second REGEXP\n\
2590 add_info ("sources", sources_info
,
2591 "Source files in the program.");
2593 add_com ("rbreak", no_class
, rbreak_command
,
2594 "Set a breakpoint for all functions matching REGEXP.");
2596 /* FIXME: The code below assumes that the sizes of the basic data
2597 types are the same on the host and target machines!!! */
2599 builtin_type_void
= init_type (TYPE_CODE_VOID
, 1, 0, "void");
2601 builtin_type_float
= init_type (TYPE_CODE_FLT
, sizeof (float), 0, "float");
2602 builtin_type_double
= init_type (TYPE_CODE_FLT
, sizeof (double), 0, "double");
2604 builtin_type_char
= init_type (TYPE_CODE_INT
, sizeof (char), 0, "char");
2605 builtin_type_short
= init_type (TYPE_CODE_INT
, sizeof (short), 0, "short");
2606 builtin_type_long
= init_type (TYPE_CODE_INT
, sizeof (long), 0, "long");
2607 builtin_type_int
= init_type (TYPE_CODE_INT
, sizeof (int), 0, "int");
2609 builtin_type_unsigned_char
= init_type (TYPE_CODE_INT
, sizeof (char), 1, "unsigned char");
2610 builtin_type_unsigned_short
= init_type (TYPE_CODE_INT
, sizeof (short), 1, "unsigned short");
2611 builtin_type_unsigned_long
= init_type (TYPE_CODE_INT
, sizeof (long), 1, "unsigned long");
2612 builtin_type_unsigned_int
= init_type (TYPE_CODE_INT
, sizeof (int), 1, "unsigned int");
2614 builtin_type_long_long
=
2615 init_type (TYPE_CODE_INT
, sizeof (long long), 0, "long long");
2616 builtin_type_unsigned_long_long
=
2617 init_type (TYPE_CODE_INT
, sizeof (long long), 1, "unsigned long long");
2619 builtin_type_error
= init_type (TYPE_CODE_ERROR
, 0, 0, "<unknown type>");