Delete a superfluous space.
[binutils-gdb.git] / gdb / symtab.c
1 /* Symbol table lookup for the GNU debugger, GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 #include <stdio.h>
21 #include "defs.h"
22 #include "symtab.h"
23 #include "gdbcore.h"
24 #include "frame.h"
25 #include "target.h"
26 #include "value.h"
27 #include "symfile.h"
28 #include "gdbcmd.h"
29 #include "regex.h"
30 #include "language.h"
31
32 #include <obstack.h>
33 #include <assert.h>
34
35 #include <sys/types.h>
36 #include <fcntl.h>
37 #include <string.h>
38 #include <sys/stat.h>
39
40 extern char *getenv ();
41
42 extern char *cplus_demangle ();
43 extern char *cplus_mangle_opname ();
44 extern struct value *value_of_this ();
45 extern void break_command ();
46 extern void select_source_symtab ();
47
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 ();
54
55 /* The single non-language-specific builtin type */
56 struct type *builtin_type_error;
57
58 /* Block in which the most recently searched-for symbol was found.
59 Might be better to make this a parameter to lookup_symbol and
60 value_of_this. */
61 struct block *block_found;
62
63 char no_symtab_msg[] = "No symbol table is loaded. Use the \"file\" command.";
64
65 /* Check for a symtab of a specific name; first in symtabs, then in
66 psymtabs. *If* there is no '/' in the name, a match after a '/'
67 in the symtab filename will also work. */
68
69 static struct symtab *
70 lookup_symtab_1 (name)
71 char *name;
72 {
73 register struct symtab *s;
74 register struct partial_symtab *ps;
75 register char *slash = strchr (name, '/');
76 register int len = strlen (name);
77
78 for (s = symtab_list; s; s = s->next)
79 if (!strcmp (name, s->filename))
80 return s;
81
82 for (ps = partial_symtab_list; ps; ps = ps->next)
83 if (!strcmp (name, ps->filename))
84 {
85 if (ps->readin)
86 error ("Internal: readin pst for `%s' found when no symtab found.", name);
87 return PSYMTAB_TO_SYMTAB (ps);
88 }
89
90 if (!slash)
91 {
92 for (s = symtab_list; s; s = s->next)
93 {
94 int l = strlen (s->filename);
95
96 if (s->filename[l - len -1] == '/'
97 && !strcmp (s->filename + l - len, name))
98 return s;
99 }
100
101 for (ps = partial_symtab_list; ps; ps = ps->next)
102 {
103 int l = strlen (ps->filename);
104
105 if (ps->filename[l - len - 1] == '/'
106 && !strcmp (ps->filename + l - len, name))
107 {
108 if (ps->readin)
109 error ("Internal: readin pst for `%s' found when no symtab found.", name);
110 return PSYMTAB_TO_SYMTAB (ps);
111 }
112 }
113 }
114 return 0;
115 }
116
117 /* Lookup the symbol table of a source file named NAME. Try a couple
118 of variations if the first lookup doesn't work. */
119
120 struct symtab *
121 lookup_symtab (name)
122 char *name;
123 {
124 register struct symtab *s;
125 register char *copy;
126
127 s = lookup_symtab_1 (name);
128 if (s) return s;
129
130 /* If name not found as specified, see if adding ".c" helps. */
131
132 copy = (char *) alloca (strlen (name) + 3);
133 strcpy (copy, name);
134 strcat (copy, ".c");
135 s = lookup_symtab_1 (copy);
136 if (s) return s;
137
138 /* We didn't find anything; die. */
139 return 0;
140 }
141
142 /* Lookup the partial symbol table of a source file named NAME. This
143 only returns true on an exact match (ie. this semantics are
144 different from lookup_symtab. */
145
146 struct partial_symtab *
147 lookup_partial_symtab (name)
148 char *name;
149 {
150 register struct partial_symtab *s;
151
152 for (s = partial_symtab_list; s; s = s->next)
153 if (!strcmp (name, s->filename))
154 return s;
155
156 return 0;
157 }
158 \f
159 /* Return a typename for a struct/union/enum type
160 without the tag qualifier. If the type has a NULL name,
161 NULL is returned. */
162 char *
163 type_name_no_tag (type)
164 register struct type *type;
165 {
166 register char *name = TYPE_NAME (type);
167
168 if (name == 0)
169 return 0;
170
171 switch (TYPE_CODE (type))
172 {
173 case TYPE_CODE_STRUCT:
174 if(!strncmp(name,"struct ",7))
175 return name + 7;
176 else return name;
177 case TYPE_CODE_UNION:
178 if(!strncmp(name,"union ",6))
179 return name + 6;
180 else return name;
181 case TYPE_CODE_ENUM:
182 if(!strncmp(name,"enum ",5))
183 return name + 5;
184 else return name;
185 default:
186 return name;
187 }
188 }
189
190 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
191
192 If this is a stubbed struct (i.e. declared as struct foo *), see if
193 we can find a full definition in some other file. If so, copy this
194 definition, so we can use it in future. If not, set a flag so we
195 don't waste too much time in future. (FIXME, this doesn't seem
196 to be happening...)
197
198 This used to be coded as a macro, but I don't think it is called
199 often enough to merit such treatment.
200 */
201
202 struct complaint stub_noname_complaint =
203 {"stub type has NULL name", 0, 0};
204
205 void
206 check_stub_type(type)
207 struct type *type;
208 {
209 if (TYPE_FLAGS(type) & TYPE_FLAG_STUB)
210 {
211 char* name= type_name_no_tag (type);
212 struct symbol *sym;
213 if (name == 0)
214 {
215 complain (&stub_noname_complaint, 0);
216 return;
217 }
218 sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0,
219 (struct symtab **)NULL);
220 if (sym)
221 memcpy (type, SYMBOL_TYPE(sym), sizeof (struct type));
222 }
223 }
224
225 /* Demangle a GDB method stub type. */
226 char *
227 gdb_mangle_name (type, i, j)
228 struct type *type;
229 int i, j;
230 {
231 int mangled_name_len;
232 char *mangled_name;
233 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
234 struct fn_field *method = &f[j];
235 char *field_name = TYPE_FN_FIELDLIST_NAME (type, i);
236 int is_constructor = strcmp(field_name, TYPE_NAME (type)) == 0;
237
238 /* Need a new type prefix. */
239 char *strchr ();
240 char *const_prefix = method->is_const ? "C" : "";
241 char *volatile_prefix = method->is_volatile ? "V" : "";
242 char *newname = type_name_no_tag (type);
243 char buf[20];
244 int len = strlen (newname);
245
246 sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len);
247 mangled_name_len = ((is_constructor ? 0 : strlen (field_name))
248 + strlen (buf) + len
249 + strlen (TYPE_FN_FIELD_PHYSNAME (f, j))
250 + 1);
251
252 /* Only needed for GNU-mangled names. ANSI-mangled names
253 work with the normal mechanisms. */
254 if (OPNAME_PREFIX_P (field_name))
255 {
256 char *opname = cplus_mangle_opname (field_name + 3, 0);
257 if (opname == NULL)
258 error ("No mangling for \"%s\"", field_name);
259 mangled_name_len += strlen (opname);
260 mangled_name = (char *)xmalloc (mangled_name_len);
261
262 strncpy (mangled_name, field_name, 3);
263 mangled_name[3] = '\0';
264 strcat (mangled_name, opname);
265 }
266 else
267 {
268 mangled_name = (char *)xmalloc (mangled_name_len);
269 if (is_constructor)
270 mangled_name[0] = '\0';
271 else
272 strcpy (mangled_name, field_name);
273 }
274 strcat (mangled_name, buf);
275 strcat (mangled_name, newname);
276 strcat (mangled_name, TYPE_FN_FIELD_PHYSNAME (f, j));
277
278 return mangled_name;
279 }
280
281 /* Lookup a primitive type named NAME.
282 Return zero if NAME is not a primitive type.*/
283
284 struct type *
285 lookup_primitive_typename (name)
286 char *name;
287 {
288 struct type ** const *p;
289
290 for (p = current_language->la_builtin_type_vector; *p; p++)
291 if(!strcmp((**p)->name, name))
292 return **p;
293 return 0;
294 }
295
296 /* Lookup a typedef or primitive type named NAME,
297 visible in lexical block BLOCK.
298 If NOERR is nonzero, return zero if NAME is not suitably defined. */
299
300 struct type *
301 lookup_typename (name, block, noerr)
302 char *name;
303 struct block *block;
304 int noerr;
305 {
306 register struct symbol *sym =
307 lookup_symbol (name, block, VAR_NAMESPACE, 0, (struct symtab **)NULL);
308 if (sym == 0 || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
309 {
310 struct type *tmp;
311 tmp = lookup_primitive_typename (name);
312 if(tmp)
313 return tmp;
314 else if (!tmp && noerr)
315 return 0;
316 else
317 error ("No type named %s.", name);
318 }
319 return SYMBOL_TYPE (sym);
320 }
321
322 struct type *
323 lookup_unsigned_typename (name)
324 char *name;
325 {
326 char *uns = alloca (strlen(name) + 10);
327
328 strcpy (uns, "unsigned ");
329 strcpy (uns+9, name);
330 return lookup_typename (uns, (struct block *)0, 0);
331 }
332
333 /* Lookup a structure type named "struct NAME",
334 visible in lexical block BLOCK. */
335
336 struct type *
337 lookup_struct (name, block)
338 char *name;
339 struct block *block;
340 {
341 register struct symbol *sym
342 = lookup_symbol (name, block, STRUCT_NAMESPACE, 0, (struct symtab **)NULL);
343
344 if (sym == 0)
345 error ("No struct type named %s.", name);
346 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
347 error ("This context has class, union or enum %s, not a struct.", name);
348 return SYMBOL_TYPE (sym);
349 }
350
351 /* Lookup a union type named "union NAME",
352 visible in lexical block BLOCK. */
353
354 struct type *
355 lookup_union (name, block)
356 char *name;
357 struct block *block;
358 {
359 register struct symbol *sym
360 = lookup_symbol (name, block, STRUCT_NAMESPACE, 0, (struct symtab **)NULL);
361
362 if (sym == 0)
363 error ("No union type named %s.", name);
364 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_UNION)
365 error ("This context has class, struct or enum %s, not a union.", name);
366 return SYMBOL_TYPE (sym);
367 }
368
369 /* Lookup an enum type named "enum NAME",
370 visible in lexical block BLOCK. */
371
372 struct type *
373 lookup_enum (name, block)
374 char *name;
375 struct block *block;
376 {
377 register struct symbol *sym
378 = lookup_symbol (name, block, STRUCT_NAMESPACE, 0, (struct symtab **)NULL);
379 if (sym == 0)
380 error ("No enum type named %s.", name);
381 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
382 error ("This context has class, struct or union %s, not an enum.", name);
383 return SYMBOL_TYPE (sym);
384 }
385
386 /* Lookup a template type named "template NAME<TYPE>",
387 visible in lexical block BLOCK. */
388
389 struct type *
390 lookup_template_type (name, type, block)
391 char *name;
392 struct type *type;
393 struct block *block;
394 {
395 struct symbol *sym ;
396 char *nam = (char*) alloca(strlen(name) + strlen(type->name) + 4);
397 strcpy(nam, name);
398 strcat(nam, "<");
399 strcat(nam, type->name);
400 strcat(nam, " >"); /* FIXME, extra space still introduced in gcc? */
401
402 sym = lookup_symbol (nam, block, VAR_NAMESPACE, 0, (struct symtab **)NULL);
403
404 if (sym == 0)
405 error ("No template type named %s.", name);
406 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
407 error ("This context has class, union or enum %s, not a struct.", name);
408 return SYMBOL_TYPE (sym);
409 }
410
411 /* Given a type TYPE, lookup the type of the component of type named
412 NAME.
413 If NOERR is nonzero, return zero if NAME is not suitably defined. */
414
415 struct type *
416 lookup_struct_elt_type (type, name, noerr)
417 struct type *type;
418 char *name;
419 int noerr;
420 {
421 int i;
422
423 if ( TYPE_CODE (type) != TYPE_CODE_STRUCT
424 && TYPE_CODE (type) != TYPE_CODE_UNION)
425 {
426 target_terminal_ours ();
427 fflush (stdout);
428 fprintf (stderr, "Type ");
429 type_print (type, "", stderr, -1);
430 error (" is not a structure or union type.");
431 }
432
433 check_stub_type (type);
434
435 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
436 {
437 char *t_field_name = TYPE_FIELD_NAME (type, i);
438
439 if (t_field_name && !strcmp (t_field_name, name))
440 return TYPE_FIELD_TYPE (type, i);
441 }
442 /* OK, it's not in this class. Recursively check the baseclasses. */
443 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
444 {
445 struct type *t = lookup_struct_elt_type (TYPE_BASECLASS (type, i),
446 name, 0);
447 if (t != NULL)
448 return t;
449 }
450
451 if (noerr)
452 return NULL;
453
454 target_terminal_ours ();
455 fflush (stdout);
456 fprintf (stderr, "Type ");
457 type_print (type, "", stderr, -1);
458 fprintf (stderr, " has no component named ");
459 fputs_filtered (name, stderr);
460 error (".");
461 return (struct type *)-1; /* For lint */
462 }
463
464 /* Given a type TYPE, return a type of pointers to that type.
465 May need to construct such a type if this is the first use. */
466
467 struct type *
468 lookup_pointer_type (type)
469 struct type *type;
470 {
471 register struct type *ptype = TYPE_POINTER_TYPE (type);
472 if (ptype) return ptype;
473
474 /* This is the first time anyone wanted a pointer to a TYPE. */
475 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
476 ptype = (struct type *) xmalloc (sizeof (struct type));
477 else
478 ptype = (struct type *) obstack_alloc (symbol_obstack,
479 sizeof (struct type));
480
481 bzero (ptype, sizeof (struct type));
482 TYPE_TARGET_TYPE (ptype) = type;
483 TYPE_POINTER_TYPE (type) = ptype;
484 /* New type is permanent if type pointed to is permanent. */
485 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
486 TYPE_FLAGS (ptype) |= TYPE_FLAG_PERM;
487 /* We assume the machine has only one representation for pointers! */
488 /* FIXME: This confuses host<->target data representations, and is a
489 poor assumption besides. */
490 TYPE_LENGTH (ptype) = sizeof (char *);
491 TYPE_CODE (ptype) = TYPE_CODE_PTR;
492 return ptype;
493 }
494
495 struct type *
496 lookup_reference_type (type)
497 struct type *type;
498 {
499 register struct type *rtype = TYPE_REFERENCE_TYPE (type);
500 if (rtype) return rtype;
501
502 /* This is the first time anyone wanted a pointer to a TYPE. */
503 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
504 rtype = (struct type *) xmalloc (sizeof (struct type));
505 else
506 rtype = (struct type *) obstack_alloc (symbol_obstack,
507 sizeof (struct type));
508
509 bzero (rtype, sizeof (struct type));
510 TYPE_TARGET_TYPE (rtype) = type;
511 TYPE_REFERENCE_TYPE (type) = rtype;
512 /* New type is permanent if type pointed to is permanent. */
513 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
514 TYPE_FLAGS (rtype) |= TYPE_FLAG_PERM;
515 /* We assume the machine has only one representation for pointers! */
516 TYPE_LENGTH (rtype) = sizeof (char *);
517 TYPE_CODE (rtype) = TYPE_CODE_REF;
518 return rtype;
519 }
520
521
522 /* Implement direct support for MEMBER_TYPE in GNU C++.
523 May need to construct such a type if this is the first use.
524 The TYPE is the type of the member. The DOMAIN is the type
525 of the aggregate that the member belongs to. */
526
527 struct type *
528 lookup_member_type (type, domain)
529 struct type *type, *domain;
530 {
531 register struct type *mtype;
532
533 mtype = (struct type *) obstack_alloc (symbol_obstack,
534 sizeof (struct type));
535 smash_to_member_type (mtype, domain, type);
536 return mtype;
537 }
538
539 /* Allocate a stub method whose return type is TYPE.
540 This apparently happens for speed of symbol reading, since parsing
541 out the arguments to the method is cpu-intensive, the way we are doing
542 it. So, we will fill in arguments later.
543 This always returns a fresh type. */
544
545 struct type *
546 allocate_stub_method (type)
547 struct type *type;
548 {
549 struct type *mtype = (struct type *) obstack_alloc (symbol_obstack,
550 sizeof (struct type));
551 bzero (mtype, sizeof (struct type));
552 TYPE_TARGET_TYPE (mtype) = type;
553 /* _DOMAIN_TYPE (mtype) = unknown yet */
554 /* _ARG_TYPES (mtype) = unknown yet */
555 TYPE_FLAGS (mtype) = TYPE_FLAG_STUB;
556 TYPE_CODE (mtype) = TYPE_CODE_METHOD;
557 TYPE_LENGTH (mtype) = 1;
558 return mtype;
559 }
560
561 /* Ugly hack to convert method stubs into method types.
562
563 He ain't kiddin'. This demangles the name of the method into a string
564 including argument types, parses out each argument type, generates
565 a string casting a zero to that type, evaluates the string, and stuffs
566 the resulting type into an argtype vector!!! Then it knows the type
567 of the whole function (including argument types for overloading),
568 which info used to be in the stab's but was removed to hack back
569 the space required for them. */
570 void
571 check_stub_method (type, i, j)
572 struct type *type;
573 int i, j;
574 {
575 extern char *gdb_mangle_name (), *strchr ();
576 struct fn_field *f;
577 char *mangled_name = gdb_mangle_name (type, i, j);
578 char *demangled_name = cplus_demangle (mangled_name, 0);
579 char *argtypetext, *p;
580 int depth = 0, argcount = 1;
581 struct type **argtypes;
582 struct type *mtype;
583
584 if (demangled_name == NULL)
585 error ("Internal: Cannot demangle mangled name `%s'.", mangled_name);
586
587 /* Now, read in the parameters that define this type. */
588 argtypetext = strchr (demangled_name, '(') + 1;
589 p = argtypetext;
590 while (*p)
591 {
592 if (*p == '(')
593 depth += 1;
594 else if (*p == ')')
595 depth -= 1;
596 else if (*p == ',' && depth == 0)
597 argcount += 1;
598
599 p += 1;
600 }
601 /* We need two more slots: one for the THIS pointer, and one for the
602 NULL [...] or void [end of arglist]. */
603 argtypes = (struct type **) obstack_alloc (symbol_obstack,
604 (argcount+2) * sizeof (struct type *));
605 p = argtypetext;
606 argtypes[0] = lookup_pointer_type (type);
607 argcount = 1;
608
609 if (*p != ')') /* () means no args, skip while */
610 {
611 depth = 0;
612 while (*p)
613 {
614 if (depth <= 0 && (*p == ',' || *p == ')'))
615 {
616 argtypes[argcount] =
617 parse_and_eval_type (argtypetext, p - argtypetext);
618 argcount += 1;
619 argtypetext = p + 1;
620 }
621
622 if (*p == '(')
623 depth += 1;
624 else if (*p == ')')
625 depth -= 1;
626
627 p += 1;
628 }
629 }
630
631 if (p[-2] != '.') /* ... */
632 argtypes[argcount] = builtin_type_void; /* Ellist terminator */
633 else
634 argtypes[argcount] = NULL; /* List terminator */
635
636 free (demangled_name);
637
638 f = TYPE_FN_FIELDLIST1 (type, i);
639 TYPE_FN_FIELD_PHYSNAME (f, j) = mangled_name;
640
641 /* Now update the old "stub" type into a real type. */
642 mtype = TYPE_FN_FIELD_TYPE (f, j);
643 TYPE_DOMAIN_TYPE (mtype) = type;
644 TYPE_ARG_TYPES (mtype) = argtypes;
645 TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB;
646 TYPE_FN_FIELD_STUB (f, j) = 0;
647 }
648
649 /* Given a type TYPE, return a type of functions that return that type.
650 May need to construct such a type if this is the first use. */
651
652 struct type *
653 lookup_function_type (type)
654 struct type *type;
655 {
656 register struct type *ptype = TYPE_FUNCTION_TYPE (type);
657 if (ptype) return ptype;
658
659 /* This is the first time anyone wanted a function returning a TYPE. */
660 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
661 ptype = (struct type *) xmalloc (sizeof (struct type));
662 else
663 ptype = (struct type *) obstack_alloc (symbol_obstack,
664 sizeof (struct type));
665
666 bzero (ptype, sizeof (struct type));
667 TYPE_TARGET_TYPE (ptype) = type;
668 TYPE_FUNCTION_TYPE (type) = ptype;
669 /* New type is permanent if type returned is permanent. */
670 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
671 TYPE_FLAGS (ptype) |= TYPE_FLAG_PERM;
672 TYPE_LENGTH (ptype) = 1;
673 TYPE_CODE (ptype) = TYPE_CODE_FUNC;
674 TYPE_NFIELDS (ptype) = 0;
675 return ptype;
676 }
677 \f
678 /* Create an array type. Elements will be of type TYPE, and there will
679 be NUM of them.
680
681 Eventually this should be extended to take two more arguments which
682 specify the bounds of the array and the type of the index.
683 It should also be changed to be a "lookup" function, with the
684 appropriate data structures added to the type field.
685 Then read array type should call here. */
686
687 struct type *
688 create_array_type (element_type, number)
689 struct type *element_type;
690 int number;
691 {
692 struct type *result_type = (struct type *)
693 obstack_alloc (symbol_obstack, sizeof (struct type));
694 struct type *range_type;
695
696 bzero (result_type, sizeof (struct type));
697
698 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
699 TYPE_TARGET_TYPE (result_type) = element_type;
700 TYPE_LENGTH (result_type) = number * TYPE_LENGTH (element_type);
701 TYPE_NFIELDS (result_type) = 1;
702 TYPE_FIELDS (result_type) =
703 (struct field *) obstack_alloc (symbol_obstack, sizeof (struct field));
704
705 {
706 /* Create range type. */
707 range_type = (struct type *) obstack_alloc (symbol_obstack,
708 sizeof (struct type));
709 TYPE_CODE (range_type) = TYPE_CODE_RANGE;
710 TYPE_TARGET_TYPE (range_type) = builtin_type_int; /* FIXME */
711
712 /* This should never be needed. */
713 TYPE_LENGTH (range_type) = sizeof (int);
714
715 TYPE_NFIELDS (range_type) = 2;
716 TYPE_FIELDS (range_type) =
717 (struct field *) obstack_alloc (symbol_obstack,
718 2 * sizeof (struct field));
719 TYPE_FIELD_BITPOS (range_type, 0) = 0; /* FIXME */
720 TYPE_FIELD_BITPOS (range_type, 1) = number-1; /* FIXME */
721 TYPE_FIELD_TYPE (range_type, 0) = builtin_type_int; /* FIXME */
722 TYPE_FIELD_TYPE (range_type, 1) = builtin_type_int; /* FIXME */
723 }
724 TYPE_FIELD_TYPE(result_type,0)=range_type;
725 TYPE_VPTR_FIELDNO (result_type) = -1;
726
727 return result_type;
728 }
729
730 \f
731 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
732 A MEMBER is a wierd thing -- it amounts to a typed offset into
733 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
734 include the offset (that's the value of the MEMBER itself), but does
735 include the structure type into which it points (for some reason). */
736
737 void
738 smash_to_member_type (type, domain, to_type)
739 struct type *type, *domain, *to_type;
740 {
741 bzero (type, sizeof (struct type));
742 TYPE_TARGET_TYPE (type) = to_type;
743 TYPE_DOMAIN_TYPE (type) = domain;
744 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
745 TYPE_CODE (type) = TYPE_CODE_MEMBER;
746 }
747
748 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
749 METHOD just means `function that gets an extra "this" argument'. */
750
751 void
752 smash_to_method_type (type, domain, to_type, args)
753 struct type *type, *domain, *to_type, **args;
754 {
755 bzero (type, sizeof (struct type));
756 TYPE_TARGET_TYPE (type) = to_type;
757 TYPE_DOMAIN_TYPE (type) = domain;
758 TYPE_ARG_TYPES (type) = args;
759 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
760 TYPE_CODE (type) = TYPE_CODE_METHOD;
761 }
762 \f
763 /* Find which partial symtab on the partial_symtab_list contains
764 PC. Return 0 if none. */
765
766 struct partial_symtab *
767 find_pc_psymtab (pc)
768 register CORE_ADDR pc;
769 {
770 register struct partial_symtab *ps;
771
772 for (ps = partial_symtab_list; ps; ps = ps->next)
773 if (pc >= ps->textlow && pc < ps->texthigh)
774 return ps;
775
776 return 0;
777 }
778
779 /* Find which partial symbol within a psymtab contains PC. Return 0
780 if none. Check all psymtabs if PSYMTAB is 0. */
781 struct partial_symbol *
782 find_pc_psymbol (psymtab, pc)
783 struct partial_symtab *psymtab;
784 CORE_ADDR pc;
785 {
786 struct partial_symbol *best, *p;
787 CORE_ADDR best_pc;
788
789 if (!psymtab)
790 psymtab = find_pc_psymtab (pc);
791 if (!psymtab)
792 return 0;
793
794 best_pc = psymtab->textlow - 1;
795
796 for (p = static_psymbols.list + psymtab->statics_offset;
797 (p - (static_psymbols.list + psymtab->statics_offset)
798 < psymtab->n_static_syms);
799 p++)
800 if (SYMBOL_NAMESPACE (p) == VAR_NAMESPACE
801 && SYMBOL_CLASS (p) == LOC_BLOCK
802 && pc >= SYMBOL_VALUE_ADDRESS (p)
803 && SYMBOL_VALUE_ADDRESS (p) > best_pc)
804 {
805 best_pc = SYMBOL_VALUE_ADDRESS (p);
806 best = p;
807 }
808 if (best_pc == psymtab->textlow - 1)
809 return 0;
810 return best;
811 }
812
813 \f
814 /* Find the definition for a specified symbol name NAME
815 in namespace NAMESPACE, visible from lexical block BLOCK.
816 Returns the struct symbol pointer, or zero if no symbol is found.
817 If SYMTAB is non-NULL, store the symbol table in which the
818 symbol was found there, or NULL if not found.
819 C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
820 NAME is a field of the current implied argument `this'. If so set
821 *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
822 BLOCK_FOUND is set to the block in which NAME is found (in the case of
823 a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
824
825 struct symbol *
826 lookup_symbol (name, block, namespace, is_a_field_of_this, symtab)
827 char *name;
828 register struct block *block;
829 enum namespace namespace;
830 int *is_a_field_of_this;
831 struct symtab **symtab;
832 {
833 register struct symbol *sym;
834 register struct symtab *s;
835 register struct partial_symtab *ps;
836 struct blockvector *bv;
837
838 /* Search specified block and its superiors. */
839
840 while (block != 0)
841 {
842 sym = lookup_block_symbol (block, name, namespace);
843 if (sym)
844 {
845 block_found = block;
846 if (symtab != NULL)
847 {
848 /* Search the list of symtabs for one which contains the
849 address of the start of this block. */
850 struct block *b;
851 for (s = symtab_list; s; s = s->next)
852 {
853 bv = BLOCKVECTOR (s);
854 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
855 if (BLOCK_START (b) <= BLOCK_START (block)
856 && BLOCK_END (b) > BLOCK_START (block))
857 break;
858 }
859 *symtab = s;
860 }
861
862 return sym;
863 }
864 block = BLOCK_SUPERBLOCK (block);
865 }
866
867 /* But that doesn't do any demangling for the STATIC_BLOCK.
868 I'm not sure whether demangling is needed in the case of
869 nested function in inner blocks; if so this needs to be changed.
870
871 Don't need to mess with the psymtabs; if we have a block,
872 that file is read in. If we don't, then we deal later with
873 all the psymtab stuff that needs checking. */
874 if (namespace == VAR_NAMESPACE && block != NULL)
875 {
876 struct block *b;
877 /* Find the right symtab. */
878 for (s = symtab_list; s; s = s->next)
879 {
880 bv = BLOCKVECTOR (s);
881 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
882 if (BLOCK_START (b) <= BLOCK_START (block)
883 && BLOCK_END (b) > BLOCK_START (block))
884 {
885 sym = lookup_demangled_block_symbol (b, name);
886 if (sym)
887 {
888 block_found = b;
889 if (symtab != NULL)
890 *symtab = s;
891 return sym;
892 }
893 }
894 }
895 }
896
897
898 /* C++: If requested to do so by the caller,
899 check to see if NAME is a field of `this'. */
900 if (is_a_field_of_this)
901 {
902 struct value *v = value_of_this (0);
903
904 *is_a_field_of_this = 0;
905 if (v && check_field (v, name))
906 {
907 *is_a_field_of_this = 1;
908 if (symtab != NULL)
909 *symtab = NULL;
910 return 0;
911 }
912 }
913
914 /* Now search all global blocks. Do the symtab's first, then
915 check the psymtab's */
916
917 for (s = symtab_list; s; s = s->next)
918 {
919 bv = BLOCKVECTOR (s);
920 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
921 sym = lookup_block_symbol (block, name, namespace);
922 if (sym)
923 {
924 block_found = block;
925 if (symtab != NULL)
926 *symtab = s;
927 return sym;
928 }
929 }
930
931 /* Check for the possibility of the symbol being a global function
932 that is stored on the misc function vector. Eventually, all
933 global symbols might be resolved in this way. */
934
935 if (namespace == VAR_NAMESPACE)
936 {
937 int ind = lookup_misc_func (name);
938
939 /* Look for a mangled C++ name for NAME. */
940 if (ind == -1)
941 {
942 int name_len = strlen (name);
943
944 for (ind = misc_function_count; --ind >= 0; )
945 /* Assume orginal name is prefix of mangled name. */
946 if (!strncmp (misc_function_vector[ind].name, name, name_len))
947 {
948 char *demangled =
949 cplus_demangle(misc_function_vector[ind].name, -1);
950 if (demangled != NULL)
951 {
952 int cond = strcmp (demangled, name);
953 free (demangled);
954 if (!cond)
955 break;
956 }
957 }
958 /* Loop terminates on no match with ind == -1. */
959 }
960
961 if (ind != -1)
962 {
963 s = find_pc_symtab (misc_function_vector[ind].address);
964 /* If S is zero, there are no debug symbols for this file.
965 Skip this stuff and check for matching static symbols below. */
966 if (s)
967 {
968 bv = BLOCKVECTOR (s);
969 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
970 sym = lookup_block_symbol (block, misc_function_vector[ind].name,
971 namespace);
972 /* sym == 0 if symbol was found in the misc_function_vector
973 but not in the symtab.
974 Return 0 to use the misc_function definition of "foo_".
975
976 This happens for Fortran "foo_" symbols,
977 which are "foo" in the symtab.
978
979 This can also happen if "asm" is used to make a
980 regular symbol but not a debugging symbol, e.g.
981 asm(".globl _main");
982 asm("_main:");
983 */
984
985 if (symtab != NULL)
986 *symtab = s;
987 return sym;
988 }
989 }
990 }
991
992 for (ps = partial_symtab_list; ps; ps = ps->next)
993 if (!ps->readin && lookup_partial_symbol (ps, name, 1, namespace))
994 {
995 s = PSYMTAB_TO_SYMTAB(ps);
996 bv = BLOCKVECTOR (s);
997 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
998 sym = lookup_block_symbol (block, name, namespace);
999 if (!sym)
1000 error ("Internal: global symbol `%s' found in psymtab but not in symtab", name);
1001 if (symtab != NULL)
1002 *symtab = s;
1003 return sym;
1004 }
1005
1006 /* Now search all per-file blocks.
1007 Not strictly correct, but more useful than an error.
1008 Do the symtabs first, then check the psymtabs */
1009
1010 for (s = symtab_list; s; s = s->next)
1011 {
1012 bv = BLOCKVECTOR (s);
1013 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1014 sym = lookup_block_symbol (block, name, namespace);
1015 if (sym)
1016 {
1017 block_found = block;
1018 if (symtab != NULL)
1019 *symtab = s;
1020 return sym;
1021 }
1022 }
1023
1024 for (ps = partial_symtab_list; ps; ps = ps->next)
1025 if (!ps->readin && lookup_partial_symbol (ps, name, 0, namespace))
1026 {
1027 s = PSYMTAB_TO_SYMTAB(ps);
1028 bv = BLOCKVECTOR (s);
1029 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1030 sym = lookup_block_symbol (block, name, namespace);
1031 if (!sym)
1032 error ("Internal: static symbol `%s' found in psymtab but not in symtab", name);
1033 if (symtab != NULL)
1034 *symtab = s;
1035 return sym;
1036 }
1037
1038 /* Now search all per-file blocks for static mangled symbols.
1039 Do the symtabs first, then check the psymtabs. */
1040
1041 if (namespace == VAR_NAMESPACE)
1042 {
1043 for (s = symtab_list; s; s = s->next)
1044 {
1045 bv = BLOCKVECTOR (s);
1046 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1047 sym = lookup_demangled_block_symbol (block, name);
1048 if (sym)
1049 {
1050 block_found = block;
1051 if (symtab != NULL)
1052 *symtab = s;
1053 return sym;
1054 }
1055 }
1056
1057 for (ps = partial_symtab_list; ps; ps = ps->next)
1058 if (!ps->readin && lookup_demangled_partial_symbol (ps, name))
1059 {
1060 s = PSYMTAB_TO_SYMTAB(ps);
1061 bv = BLOCKVECTOR (s);
1062 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1063 sym = lookup_demangled_block_symbol (block, name);
1064 if (!sym)
1065 error ("Internal: mangled static symbol `%s' found in psymtab but not in symtab", name);
1066 if (symtab != NULL)
1067 *symtab = s;
1068 return sym;
1069 }
1070 }
1071
1072 if (symtab != NULL)
1073 *symtab = NULL;
1074 return 0;
1075 }
1076
1077 /* Look for a static demangled symbol in block BLOCK. */
1078
1079 static struct symbol *
1080 lookup_demangled_block_symbol (block, name)
1081 register struct block *block;
1082 char *name;
1083 {
1084 register int bot, top, inc;
1085 register struct symbol *sym;
1086
1087 bot = 0;
1088 top = BLOCK_NSYMS (block);
1089 inc = name[0];
1090
1091 while (bot < top)
1092 {
1093 sym = BLOCK_SYM (block, bot);
1094 if (SYMBOL_NAME (sym)[0] == inc
1095 && SYMBOL_NAMESPACE (sym) == VAR_NAMESPACE)
1096 {
1097 char *demangled = cplus_demangle(SYMBOL_NAME (sym), -1);
1098 if (demangled != NULL)
1099 {
1100 int cond = strcmp (demangled, name);
1101 free (demangled);
1102 if (!cond)
1103 return sym;
1104 }
1105 }
1106 bot++;
1107 }
1108
1109 return 0;
1110 }
1111
1112 /* Look, in partial_symtab PST, for static mangled symbol NAME. */
1113
1114 static struct partial_symbol *
1115 lookup_demangled_partial_symbol (pst, name)
1116 struct partial_symtab *pst;
1117 char *name;
1118 {
1119 struct partial_symbol *start, *psym;
1120 int length = pst->n_static_syms;
1121 register int inc = name[0];
1122
1123 if (!length)
1124 return (struct partial_symbol *) 0;
1125
1126 start = static_psymbols.list + pst->statics_offset;
1127 for (psym = start; psym < start + length; psym++)
1128 {
1129 if (SYMBOL_NAME (psym)[0] == inc
1130 && SYMBOL_NAMESPACE (psym) == VAR_NAMESPACE)
1131 {
1132 char *demangled = cplus_demangle(SYMBOL_NAME (psym), -1);
1133 if (demangled != NULL)
1134 {
1135 int cond = strcmp (demangled, name);
1136 free (demangled);
1137 if (!cond)
1138 return psym;
1139 }
1140 }
1141 }
1142
1143 return (struct partial_symbol *) 0;
1144 }
1145
1146 /* Look, in partial_symtab PST, for symbol NAME. Check the global
1147 symbols if GLOBAL, the static symbols if not */
1148
1149 static struct partial_symbol *
1150 lookup_partial_symbol (pst, name, global, namespace)
1151 struct partial_symtab *pst;
1152 char *name;
1153 int global;
1154 enum namespace namespace;
1155 {
1156 struct partial_symbol *start, *psym;
1157 int length = (global ? pst->n_global_syms : pst->n_static_syms);
1158
1159 if (!length)
1160 return (struct partial_symbol *) 0;
1161
1162 start = (global ?
1163 global_psymbols.list + pst->globals_offset :
1164 static_psymbols.list + pst->statics_offset );
1165
1166 if (global) /* This means we can use a binary */
1167 /* search. */
1168 {
1169 struct partial_symbol *top, *bottom, *center;
1170
1171 /* Binary search. This search is guaranteed to end with center
1172 pointing at the earliest partial symbol with the correct
1173 name. At that point *all* partial symbols with that name
1174 will be checked against the correct namespace. */
1175 bottom = start;
1176 top = start + length - 1;
1177 while (top > bottom)
1178 {
1179 center = bottom + (top - bottom) / 2;
1180
1181 assert (center < top);
1182
1183 if (strcmp (SYMBOL_NAME (center), name) >= 0)
1184 top = center;
1185 else
1186 bottom = center + 1;
1187 }
1188 assert (top == bottom);
1189
1190 while (!strcmp (SYMBOL_NAME (top), name))
1191 {
1192 if (SYMBOL_NAMESPACE (top) == namespace)
1193 return top;
1194 top ++;
1195 }
1196 }
1197 else
1198 {
1199 /* Can't use a binary search */
1200 for (psym = start; psym < start + length; psym++)
1201 if (namespace == SYMBOL_NAMESPACE (psym)
1202 && !strcmp (name, SYMBOL_NAME (psym)))
1203 return psym;
1204 }
1205
1206 return (struct partial_symbol *) 0;
1207 }
1208
1209 /* Find the psymtab containing main(). */
1210
1211 struct partial_symtab *
1212 find_main_psymtab ()
1213 {
1214 register struct partial_symtab *pst;
1215 for (pst = partial_symtab_list; pst; pst = pst->next)
1216 if (lookup_partial_symbol (pst, "main", 1, VAR_NAMESPACE))
1217 return pst;
1218 return NULL;
1219 }
1220
1221 /* Look for a symbol in block BLOCK. */
1222
1223 struct symbol *
1224 lookup_block_symbol (block, name, namespace)
1225 register struct block *block;
1226 char *name;
1227 enum namespace namespace;
1228 {
1229 register int bot, top, inc;
1230 register struct symbol *sym, *parameter_sym;
1231
1232 top = BLOCK_NSYMS (block);
1233 bot = 0;
1234
1235 /* If the blocks's symbols were sorted, start with a binary search. */
1236
1237 if (BLOCK_SHOULD_SORT (block))
1238 {
1239 /* First, advance BOT to not far before
1240 the first symbol whose name is NAME. */
1241
1242 while (1)
1243 {
1244 inc = (top - bot + 1);
1245 /* No need to keep binary searching for the last few bits worth. */
1246 if (inc < 4)
1247 break;
1248 inc = (inc >> 1) + bot;
1249 sym = BLOCK_SYM (block, inc);
1250 if (SYMBOL_NAME (sym)[0] < name[0])
1251 bot = inc;
1252 else if (SYMBOL_NAME (sym)[0] > name[0])
1253 top = inc;
1254 else if (strcmp (SYMBOL_NAME (sym), name) < 0)
1255 bot = inc;
1256 else
1257 top = inc;
1258 }
1259
1260 /* Now scan forward until we run out of symbols,
1261 find one whose name is greater than NAME,
1262 or find one we want.
1263 If there is more than one symbol with the right name and namespace,
1264 we return the first one. dbxread.c is careful to make sure
1265 that if one is a register then it comes first. */
1266
1267 top = BLOCK_NSYMS (block);
1268 while (bot < top)
1269 {
1270 sym = BLOCK_SYM (block, bot);
1271 inc = SYMBOL_NAME (sym)[0] - name[0];
1272 if (inc == 0)
1273 inc = strcmp (SYMBOL_NAME (sym), name);
1274 if (inc == 0 && SYMBOL_NAMESPACE (sym) == namespace)
1275 return sym;
1276 if (inc > 0)
1277 return 0;
1278 bot++;
1279 }
1280 return 0;
1281 }
1282
1283 /* Here if block isn't sorted.
1284 This loop is equivalent to the loop above,
1285 but hacked greatly for speed.
1286
1287 Note that parameter symbols do not always show up last in the
1288 list; this loop makes sure to take anything else other than
1289 parameter symbols first; it only uses parameter symbols as a
1290 last resort. Note that this only takes up extra computation
1291 time on a match. */
1292
1293 parameter_sym = (struct symbol *) 0;
1294 top = BLOCK_NSYMS (block);
1295 inc = name[0];
1296 while (bot < top)
1297 {
1298 sym = BLOCK_SYM (block, bot);
1299 if (SYMBOL_NAME (sym)[0] == inc
1300 && !strcmp (SYMBOL_NAME (sym), name)
1301 && SYMBOL_NAMESPACE (sym) == namespace)
1302 {
1303 if (SYMBOL_CLASS (sym) == LOC_ARG
1304 || SYMBOL_CLASS (sym) == LOC_LOCAL_ARG
1305 || SYMBOL_CLASS (sym) == LOC_REF_ARG
1306 || SYMBOL_CLASS (sym) == LOC_REGPARM)
1307 parameter_sym = sym;
1308 else
1309 return sym;
1310 }
1311 bot++;
1312 }
1313 return parameter_sym; /* Will be 0 if not found. */
1314 }
1315 \f
1316 /* Return the symbol for the function which contains a specified
1317 lexical block, described by a struct block BL. */
1318
1319 struct symbol *
1320 block_function (bl)
1321 struct block *bl;
1322 {
1323 while (BLOCK_FUNCTION (bl) == 0 && BLOCK_SUPERBLOCK (bl) != 0)
1324 bl = BLOCK_SUPERBLOCK (bl);
1325
1326 return BLOCK_FUNCTION (bl);
1327 }
1328
1329 /* Subroutine of find_pc_line */
1330
1331 struct symtab *
1332 find_pc_symtab (pc)
1333 register CORE_ADDR pc;
1334 {
1335 register struct block *b;
1336 struct blockvector *bv;
1337 register struct symtab *s;
1338 register struct partial_symtab *ps;
1339
1340 /* Search all symtabs for one whose file contains our pc */
1341
1342 for (s = symtab_list; s; s = s->next)
1343 {
1344 bv = BLOCKVECTOR (s);
1345 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1346 if (BLOCK_START (b) <= pc
1347 && BLOCK_END (b) > pc)
1348 break;
1349 }
1350
1351 if (!s)
1352 {
1353 ps = find_pc_psymtab (pc);
1354 if (ps && ps->readin)
1355 printf_filtered (
1356 "(Internal error: pc 0x%x in read in psymtab, but not in symtab.)\n", pc);
1357
1358 if (ps)
1359 s = PSYMTAB_TO_SYMTAB (ps);
1360 }
1361
1362 return s;
1363 }
1364
1365 /* Find the source file and line number for a given PC value.
1366 Return a structure containing a symtab pointer, a line number,
1367 and a pc range for the entire source line.
1368 The value's .pc field is NOT the specified pc.
1369 NOTCURRENT nonzero means, if specified pc is on a line boundary,
1370 use the line that ends there. Otherwise, in that case, the line
1371 that begins there is used. */
1372
1373 struct symtab_and_line
1374 find_pc_line (pc, notcurrent)
1375 CORE_ADDR pc;
1376 int notcurrent;
1377 {
1378 struct symtab *s;
1379 register struct linetable *l;
1380 register int len;
1381 register int i;
1382 register struct linetable_entry *item;
1383 struct symtab_and_line val;
1384 struct blockvector *bv;
1385
1386 /* Info on best line seen so far, and where it starts, and its file. */
1387
1388 int best_line = 0;
1389 CORE_ADDR best_pc = 0;
1390 CORE_ADDR best_end = 0;
1391 struct symtab *best_symtab = 0;
1392
1393 /* Store here the first line number
1394 of a file which contains the line at the smallest pc after PC.
1395 If we don't find a line whose range contains PC,
1396 we will use a line one less than this,
1397 with a range from the start of that file to the first line's pc. */
1398 int alt_line = 0;
1399 CORE_ADDR alt_pc = 0;
1400 struct symtab *alt_symtab = 0;
1401
1402 /* Info on best line seen in this file. */
1403
1404 int prev_line;
1405 CORE_ADDR prev_pc;
1406
1407 /* Info on first line of this file. */
1408
1409 int first_line;
1410 CORE_ADDR first_pc;
1411
1412 /* If this pc is not from the current frame,
1413 it is the address of the end of a call instruction.
1414 Quite likely that is the start of the following statement.
1415 But what we want is the statement containing the instruction.
1416 Fudge the pc to make sure we get that. */
1417
1418 if (notcurrent) pc -= 1;
1419
1420 s = find_pc_symtab (pc);
1421 if (s == 0)
1422 {
1423 val.symtab = 0;
1424 val.line = 0;
1425 val.pc = pc;
1426 val.end = 0;
1427 return val;
1428 }
1429
1430 bv = BLOCKVECTOR (s);
1431
1432 /* Look at all the symtabs that share this blockvector.
1433 They all have the same apriori range, that we found was right;
1434 but they have different line tables. */
1435
1436 for (; s && BLOCKVECTOR (s) == bv; s = s->next)
1437 {
1438 /* Find the best line in this symtab. */
1439 l = LINETABLE (s);
1440 if (!l)
1441 continue;
1442 len = l->nitems;
1443 prev_line = -1;
1444 first_line = -1;
1445 for (i = 0; i < len; i++)
1446 {
1447 item = &(l->item[i]);
1448
1449 if (first_line < 0)
1450 {
1451 first_line = item->line;
1452 first_pc = item->pc;
1453 }
1454 /* Return the last line that did not start after PC. */
1455 if (pc >= item->pc)
1456 {
1457 prev_line = item->line;
1458 prev_pc = item->pc;
1459 }
1460 else
1461 break;
1462 }
1463
1464 /* Is this file's best line closer than the best in the other files?
1465 If so, record this file, and its best line, as best so far. */
1466 if (prev_line >= 0 && prev_pc > best_pc)
1467 {
1468 best_pc = prev_pc;
1469 best_line = prev_line;
1470 best_symtab = s;
1471 if (i < len)
1472 best_end = item->pc;
1473 else
1474 best_end = 0;
1475 }
1476 /* Is this file's first line closer than the first lines of other files?
1477 If so, record this file, and its first line, as best alternate. */
1478 if (first_line >= 0 && first_pc > pc
1479 && (alt_pc == 0 || first_pc < alt_pc))
1480 {
1481 alt_pc = first_pc;
1482 alt_line = first_line;
1483 alt_symtab = s;
1484 }
1485 }
1486 if (best_symtab == 0)
1487 {
1488 val.symtab = alt_symtab;
1489 val.line = alt_line - 1;
1490 val.pc = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
1491 val.end = alt_pc;
1492 }
1493 else
1494 {
1495 val.symtab = best_symtab;
1496 val.line = best_line;
1497 val.pc = best_pc;
1498 val.end = (best_end ? best_end
1499 : (alt_pc ? alt_pc
1500 : BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK))));
1501 }
1502 return val;
1503 }
1504 \f
1505 /* Find the PC value for a given source file and line number.
1506 Returns zero for invalid line number.
1507 The source file is specified with a struct symtab. */
1508
1509 CORE_ADDR
1510 find_line_pc (symtab, line)
1511 struct symtab *symtab;
1512 int line;
1513 {
1514 register struct linetable *l;
1515 register int ind;
1516 int dummy;
1517
1518 if (symtab == 0)
1519 return 0;
1520 l = LINETABLE (symtab);
1521 ind = find_line_common(l, line, &dummy);
1522 return (ind >= 0) ? l->item[ind].pc : 0;
1523 }
1524
1525 /* Find the range of pc values in a line.
1526 Store the starting pc of the line into *STARTPTR
1527 and the ending pc (start of next line) into *ENDPTR.
1528 Returns 1 to indicate success.
1529 Returns 0 if could not find the specified line. */
1530
1531 int
1532 find_line_pc_range (symtab, thisline, startptr, endptr)
1533 struct symtab *symtab;
1534 int thisline;
1535 CORE_ADDR *startptr, *endptr;
1536 {
1537 register struct linetable *l;
1538 register int ind;
1539 int exact_match; /* did we get an exact linenumber match */
1540
1541 if (symtab == 0)
1542 return 0;
1543
1544 l = LINETABLE (symtab);
1545 ind = find_line_common (l, thisline, &exact_match);
1546 if (ind >= 0)
1547 {
1548 *startptr = l->item[ind].pc;
1549 /* If we have not seen an entry for the specified line,
1550 assume that means the specified line has zero bytes. */
1551 if (!exact_match || ind == l->nitems-1)
1552 *endptr = *startptr;
1553 else
1554 /* Perhaps the following entry is for the following line.
1555 It's worth a try. */
1556 if (ind+1 < l->nitems
1557 && l->item[ind+1].line == thisline + 1)
1558 *endptr = l->item[ind+1].pc;
1559 else
1560 *endptr = find_line_pc (symtab, thisline+1);
1561 return 1;
1562 }
1563
1564 return 0;
1565 }
1566
1567 /* Given a line table and a line number, return the index into the line
1568 table for the pc of the nearest line whose number is >= the specified one.
1569 Return -1 if none is found. The value is >= 0 if it is an index.
1570
1571 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
1572
1573 static int
1574 find_line_common (l, lineno, exact_match)
1575 register struct linetable *l;
1576 register int lineno;
1577 int *exact_match;
1578 {
1579 register int i;
1580 register int len;
1581
1582 /* BEST is the smallest linenumber > LINENO so far seen,
1583 or 0 if none has been seen so far.
1584 BEST_INDEX identifies the item for it. */
1585
1586 int best_index = -1;
1587 int best = 0;
1588
1589 if (lineno <= 0)
1590 return -1;
1591 if (l == 0)
1592 return -1;
1593
1594 len = l->nitems;
1595 for (i = 0; i < len; i++)
1596 {
1597 register struct linetable_entry *item = &(l->item[i]);
1598
1599 if (item->line == lineno)
1600 {
1601 *exact_match = 1;
1602 return i;
1603 }
1604
1605 if (item->line > lineno && (best == 0 || item->line < best))
1606 {
1607 best = item->line;
1608 best_index = i;
1609 }
1610 }
1611
1612 /* If we got here, we didn't get an exact match. */
1613
1614 *exact_match = 0;
1615 return best_index;
1616 }
1617
1618 int
1619 find_pc_line_pc_range (pc, startptr, endptr)
1620 CORE_ADDR pc;
1621 CORE_ADDR *startptr, *endptr;
1622 {
1623 struct symtab_and_line sal;
1624 sal = find_pc_line (pc, 0);
1625 *startptr = sal.pc;
1626 *endptr = sal.end;
1627 return sal.symtab != 0;
1628 }
1629 \f
1630 /* If P is of the form "operator[ \t]+..." where `...' is
1631 some legitimate operator text, return a pointer to the
1632 beginning of the substring of the operator text.
1633 Otherwise, return "". */
1634 static char *
1635 operator_chars (p, end)
1636 char *p;
1637 char **end;
1638 {
1639 *end = "";
1640 if (strncmp (p, "operator", 8))
1641 return *end;
1642 p += 8;
1643
1644 /* Don't get faked out by `operator' being part of a longer
1645 identifier. */
1646 if ((*p >= 'A' && *p <= 'Z') || (*p >= 'a' && *p <= 'z')
1647 || *p == '_' || *p == '$' || *p == '\0')
1648 return *end;
1649
1650 /* Allow some whitespace between `operator' and the operator symbol. */
1651 while (*p == ' ' || *p == '\t')
1652 p++;
1653
1654 switch (*p)
1655 {
1656 case '!':
1657 case '=':
1658 case '*':
1659 case '/':
1660 case '%':
1661 case '^':
1662 if (p[1] == '=')
1663 *end = p+2;
1664 else
1665 *end = p+1;
1666 return p;
1667 case '<':
1668 case '>':
1669 case '+':
1670 case '-':
1671 case '&':
1672 case '|':
1673 if (p[1] == '=' || p[1] == p[0])
1674 *end = p+2;
1675 else
1676 *end = p+1;
1677 return p;
1678 case '~':
1679 case ',':
1680 *end = p+1;
1681 return p;
1682 case '(':
1683 if (p[1] != ')')
1684 error ("`operator ()' must be specified without whitespace in `()'");
1685 *end = p+2;
1686 return p;
1687 case '?':
1688 if (p[1] != ':')
1689 error ("`operator ?:' must be specified without whitespace in `?:'");
1690 *end = p+2;
1691 return p;
1692 case '[':
1693 if (p[1] != ']')
1694 error ("`operator []' must be specified without whitespace in `[]'");
1695 *end = p+2;
1696 return p;
1697 default:
1698 error ("`operator %s' not supported", p);
1699 break;
1700 }
1701 *end = "";
1702 return *end;
1703 }
1704
1705 /* Recursive helper function for decode_line_1.
1706 * Look for methods named NAME in type T.
1707 * Return number of matches.
1708 * Put matches in PHYSNAMES and SYM_ARR (which better be big enough!).
1709 * These allocations seem to define "big enough":
1710 * sym_arr = (struct symbol **) alloca(TYPE_NFN_FIELDS_TOTAL (t) * sizeof(struct symbol*));
1711 * physnames = (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t) * sizeof(char*));
1712 */
1713
1714 int
1715 find_methods (t, name, physnames, sym_arr)
1716 struct type *t;
1717 char *name;
1718 char **physnames;
1719 struct symbol **sym_arr;
1720 {
1721 int i1 = 0;
1722 int ibase;
1723 struct symbol *sym_class;
1724 char *class_name = type_name_no_tag (t);
1725 /* Ignore this class if it doesn't have a name.
1726 This prevents core dumps, but is just a workaround
1727 because we might not find the function in
1728 certain cases, such as
1729 struct D {virtual int f();}
1730 struct C : D {virtual int g();}
1731 (in this case g++ 1.35.1- does not put out a name
1732 for D as such, it defines type 19 (for example) in
1733 the same stab as C, and then does a
1734 .stabs "D:T19" and a .stabs "D:t19".
1735 Thus
1736 "break C::f" should not be looking for field f in
1737 the class named D,
1738 but just for the field f in the baseclasses of C
1739 (no matter what their names).
1740
1741 However, I don't know how to replace the code below
1742 that depends on knowing the name of D. */
1743 if (class_name
1744 && (sym_class = lookup_symbol (class_name,
1745 (struct block *)NULL,
1746 STRUCT_NAMESPACE,
1747 (int *)NULL,
1748 (struct symtab **)NULL)))
1749 {
1750 int method_counter;
1751 t = SYMBOL_TYPE (sym_class);
1752 for (method_counter = TYPE_NFN_FIELDS (t) - 1;
1753 method_counter >= 0;
1754 --method_counter)
1755 {
1756 int field_counter;
1757 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, method_counter);
1758
1759 char *method_name = TYPE_FN_FIELDLIST_NAME (t, method_counter);
1760 if (!strcmp (name, method_name))
1761 /* Find all the fields with that name. */
1762 for (field_counter = TYPE_FN_FIELDLIST_LENGTH (t, method_counter) - 1;
1763 field_counter >= 0;
1764 --field_counter)
1765 {
1766 char *phys_name;
1767 if (TYPE_FN_FIELD_STUB (f, field_counter))
1768 check_stub_method (t, method_counter, field_counter);
1769 phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter);
1770 physnames[i1] = (char*) alloca (strlen (phys_name) + 1);
1771 strcpy (physnames[i1], phys_name);
1772 sym_arr[i1] = lookup_symbol (phys_name,
1773 SYMBOL_BLOCK_VALUE (sym_class),
1774 VAR_NAMESPACE,
1775 (int *) NULL,
1776 (struct symtab **) NULL);
1777 if (sym_arr[i1]) i1++;
1778 }
1779 }
1780 }
1781 /* Only search baseclasses if there is no match yet,
1782 * since names in derived classes override those in baseclasses.
1783 */
1784 if (i1)
1785 return i1;
1786 for (ibase = 0; ibase < TYPE_N_BASECLASSES (t); ibase++)
1787 i1 += find_methods(TYPE_BASECLASS(t, ibase), name,
1788 physnames + i1, sym_arr + i1);
1789 return i1;
1790 }
1791
1792 /* Parse a string that specifies a line number.
1793 Pass the address of a char * variable; that variable will be
1794 advanced over the characters actually parsed.
1795
1796 The string can be:
1797
1798 LINENUM -- that line number in current file. PC returned is 0.
1799 FILE:LINENUM -- that line in that file. PC returned is 0.
1800 FUNCTION -- line number of openbrace of that function.
1801 PC returned is the start of the function.
1802 VARIABLE -- line number of definition of that variable.
1803 PC returned is 0.
1804 FILE:FUNCTION -- likewise, but prefer functions in that file.
1805 *EXPR -- line in which address EXPR appears.
1806
1807 FUNCTION may be an undebuggable function found in misc_function_vector.
1808
1809 If the argument FUNFIRSTLINE is nonzero, we want the first line
1810 of real code inside a function when a function is specified.
1811
1812 DEFAULT_SYMTAB specifies the file to use if none is specified.
1813 It defaults to current_source_symtab.
1814 DEFAULT_LINE specifies the line number to use for relative
1815 line numbers (that start with signs). Defaults to current_source_line.
1816
1817 Note that it is possible to return zero for the symtab
1818 if no file is validly specified. Callers must check that.
1819 Also, the line number returned may be invalid. */
1820
1821 struct symtabs_and_lines
1822 decode_line_1 (argptr, funfirstline, default_symtab, default_line)
1823 char **argptr;
1824 int funfirstline;
1825 struct symtab *default_symtab;
1826 int default_line;
1827 {
1828 struct symtabs_and_lines decode_line_2 ();
1829 struct symtabs_and_lines values;
1830 struct symtab_and_line val;
1831 register char *p, *p1;
1832 char *q, *q1;
1833 register struct symtab *s;
1834
1835 register struct symbol *sym;
1836 /* The symtab that SYM was found in. */
1837 struct symtab *sym_symtab;
1838
1839 register CORE_ADDR pc;
1840 register int i;
1841 char *copy;
1842 struct symbol *sym_class;
1843 int i1;
1844 struct symbol **sym_arr;
1845 struct type *t;
1846 char **physnames;
1847
1848 /* Defaults have defaults. */
1849
1850 if (default_symtab == 0)
1851 {
1852 default_symtab = current_source_symtab;
1853 default_line = current_source_line;
1854 }
1855
1856 /* See if arg is *PC */
1857
1858 if (**argptr == '*')
1859 {
1860 (*argptr)++;
1861 pc = parse_and_eval_address_1 (argptr);
1862 values.sals = (struct symtab_and_line *)
1863 xmalloc (sizeof (struct symtab_and_line));
1864 values.nelts = 1;
1865 values.sals[0] = find_pc_line (pc, 0);
1866 values.sals[0].pc = pc;
1867 return values;
1868 }
1869
1870 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
1871
1872 s = 0;
1873
1874 for (p = *argptr; *p; p++)
1875 {
1876 if (p[0] == ':' || p[0] == ' ' || p[0] == '\t')
1877 break;
1878 }
1879 while (p[0] == ' ' || p[0] == '\t') p++;
1880
1881 if (p[0] == ':')
1882 {
1883
1884 /* C++ */
1885 if (p[1] ==':')
1886 {
1887 /* Extract the class name. */
1888 p1 = p;
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;
1893
1894 /* Discard the class name from the arg. */
1895 p = p1 + 2;
1896 while (*p == ' ' || *p == '\t') p++;
1897 *argptr = p;
1898
1899 sym_class = lookup_symbol (copy, 0, STRUCT_NAMESPACE, 0,
1900 (struct symtab **)NULL);
1901
1902 if (sym_class &&
1903 ( TYPE_CODE (SYMBOL_TYPE (sym_class)) == TYPE_CODE_STRUCT
1904 || TYPE_CODE (SYMBOL_TYPE (sym_class)) == TYPE_CODE_UNION))
1905 {
1906 /* Arg token is not digits => try it as a function name
1907 Find the next token (everything up to end or next whitespace). */
1908 p = *argptr;
1909 while (*p && *p != ' ' && *p != '\t' && *p != ',' && *p !=':') p++;
1910 q = operator_chars (*argptr, &q1);
1911
1912 copy = (char *) alloca (p - *argptr + 1 + (q1 - q));
1913 if (q1 - q)
1914 {
1915 copy[0] = 'o';
1916 copy[1] = 'p';
1917 copy[2] = CPLUS_MARKER;
1918 bcopy (q, copy + 3, q1 - q);
1919 copy[3 + (q1 - q)] = '\0';
1920 p = q1;
1921 }
1922 else
1923 {
1924 bcopy (*argptr, copy, p - *argptr);
1925 copy[p - *argptr] = '\0';
1926 }
1927
1928 /* no line number may be specified */
1929 while (*p == ' ' || *p == '\t') p++;
1930 *argptr = p;
1931
1932 sym = 0;
1933 i1 = 0; /* counter for the symbol array */
1934 t = SYMBOL_TYPE (sym_class);
1935 sym_arr = (struct symbol **) alloca(TYPE_NFN_FIELDS_TOTAL (t) * sizeof(struct symbol*));
1936 physnames = (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t) * sizeof(char*));
1937
1938 if (destructor_name_p (copy, t))
1939 {
1940 /* destructors are a special case. */
1941 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, 0);
1942 int len = TYPE_FN_FIELDLIST_LENGTH (t, 0) - 1;
1943 char *phys_name = TYPE_FN_FIELD_PHYSNAME (f, len);
1944 physnames[i1] = (char *)alloca (strlen (phys_name) + 1);
1945 strcpy (physnames[i1], phys_name);
1946 sym_arr[i1] =
1947 lookup_symbol (phys_name, SYMBOL_BLOCK_VALUE (sym_class),
1948 VAR_NAMESPACE, 0, (struct symtab **)NULL);
1949 if (sym_arr[i1]) i1++;
1950 }
1951 else
1952 i1 = find_methods (t, copy, physnames, sym_arr);
1953 if (i1 == 1)
1954 {
1955 /* There is exactly one field with that name. */
1956 sym = sym_arr[0];
1957
1958 if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
1959 {
1960 /* Arg is the name of a function */
1961 pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) + FUNCTION_START_OFFSET;
1962 if (funfirstline)
1963 SKIP_PROLOGUE (pc);
1964 values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line));
1965 values.nelts = 1;
1966 values.sals[0] = find_pc_line (pc, 0);
1967 values.sals[0].pc = (values.sals[0].end && values.sals[0].pc != pc) ? values.sals[0].end : pc;
1968 }
1969 else
1970 {
1971 values.nelts = 0;
1972 }
1973 return values;
1974 }
1975 if (i1 > 0)
1976 {
1977 /* There is more than one field with that name
1978 (overloaded). Ask the user which one to use. */
1979 return decode_line_2 (sym_arr, i1, funfirstline);
1980 }
1981 else
1982 {
1983 char *tmp;
1984
1985 if (OPNAME_PREFIX_P (copy))
1986 {
1987 tmp = (char *)alloca (strlen (copy+3) + 9);
1988 strcpy (tmp, "operator ");
1989 strcat (tmp, copy+3);
1990 }
1991 else
1992 tmp = copy;
1993 if (tmp[0] == '~')
1994 error ("The class `%s' does not have destructor defined",
1995 sym_class->name);
1996 else
1997 error ("The class %s does not have any method named %s",
1998 sym_class->name, tmp);
1999 }
2000 }
2001 else
2002 /* The quotes are important if copy is empty. */
2003 error("No class, struct, or union named \"%s\"", copy );
2004 }
2005 /* end of C++ */
2006
2007
2008 /* Extract the file name. */
2009 p1 = p;
2010 while (p != *argptr && p[-1] == ' ') --p;
2011 copy = (char *) alloca (p - *argptr + 1);
2012 bcopy (*argptr, copy, p - *argptr);
2013 copy[p - *argptr] = 0;
2014
2015 /* Find that file's data. */
2016 s = lookup_symtab (copy);
2017 if (s == 0)
2018 {
2019 if (symtab_list == 0 && partial_symtab_list == 0)
2020 error (no_symtab_msg);
2021 error ("No source file named %s.", copy);
2022 }
2023
2024 /* Discard the file name from the arg. */
2025 p = p1 + 1;
2026 while (*p == ' ' || *p == '\t') p++;
2027 *argptr = p;
2028 }
2029
2030 /* S is specified file's symtab, or 0 if no file specified.
2031 arg no longer contains the file name. */
2032
2033 /* Check whether arg is all digits (and sign) */
2034
2035 p = *argptr;
2036 if (*p == '-' || *p == '+') p++;
2037 while (*p >= '0' && *p <= '9')
2038 p++;
2039
2040 if (p != *argptr && (*p == 0 || *p == ' ' || *p == '\t' || *p == ','))
2041 {
2042 /* We found a token consisting of all digits -- at least one digit. */
2043 enum sign {none, plus, minus} sign = none;
2044
2045 /* This is where we need to make sure that we have good defaults.
2046 We must guarantee that this section of code is never executed
2047 when we are called with just a function name, since
2048 select_source_symtab calls us with such an argument */
2049
2050 if (s == 0 && default_symtab == 0)
2051 {
2052 select_source_symtab (0);
2053 default_symtab = current_source_symtab;
2054 default_line = current_source_line;
2055 }
2056
2057 if (**argptr == '+')
2058 sign = plus, (*argptr)++;
2059 else if (**argptr == '-')
2060 sign = minus, (*argptr)++;
2061 val.line = atoi (*argptr);
2062 switch (sign)
2063 {
2064 case plus:
2065 if (p == *argptr)
2066 val.line = 5;
2067 if (s == 0)
2068 val.line = default_line + val.line;
2069 break;
2070 case minus:
2071 if (p == *argptr)
2072 val.line = 15;
2073 if (s == 0)
2074 val.line = default_line - val.line;
2075 else
2076 val.line = 1;
2077 break;
2078 case none:
2079 break; /* No need to adjust val.line. */
2080 }
2081
2082 while (*p == ' ' || *p == '\t') p++;
2083 *argptr = p;
2084 if (s == 0)
2085 s = default_symtab;
2086 val.symtab = s;
2087 val.pc = 0;
2088 values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line));
2089 values.sals[0] = val;
2090 values.nelts = 1;
2091 return values;
2092 }
2093
2094 /* Arg token is not digits => try it as a variable name
2095 Find the next token (everything up to end or next whitespace). */
2096 p = *argptr;
2097 while (*p && *p != ' ' && *p != '\t' && *p != ',') p++;
2098 copy = (char *) alloca (p - *argptr + 1);
2099 bcopy (*argptr, copy, p - *argptr);
2100 copy[p - *argptr] = 0;
2101 while (*p == ' ' || *p == '\t') p++;
2102 *argptr = p;
2103
2104 /* Look up that token as a variable.
2105 If file specified, use that file's per-file block to start with. */
2106
2107 sym = lookup_symbol (copy,
2108 (s ? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)
2109 : get_selected_block ()),
2110 VAR_NAMESPACE, 0, &sym_symtab);
2111
2112 if (sym != NULL)
2113 {
2114 if (SYMBOL_CLASS (sym) == LOC_BLOCK)
2115 {
2116 /* Arg is the name of a function */
2117 pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) + FUNCTION_START_OFFSET;
2118 if (funfirstline)
2119 SKIP_PROLOGUE (pc);
2120 val = find_pc_line (pc, 0);
2121 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2122 /* Convex: no need to suppress code on first line, if any */
2123 val.pc = pc;
2124 #else
2125 /* If SKIP_PROLOGUE left us in mid-line, and the next line is still
2126 part of the same function:
2127 advance to next line,
2128 recalculate its line number (might not be N+1). */
2129 if (val.pc != pc && val.end &&
2130 find_pc_misc_function (pc) == find_pc_misc_function (val.end)) {
2131 pc = val.end; /* First pc of next line */
2132 val = find_pc_line (pc, 0);
2133 }
2134 val.pc = pc;
2135 #endif
2136 values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line));
2137 values.sals[0] = val;
2138 values.nelts = 1;
2139
2140 /* I think this is always the same as the line that
2141 we calculate above, but the general principle is
2142 "trust the symbols more than stuff like
2143 SKIP_PROLOGUE". */
2144 if (SYMBOL_LINE (sym) != 0)
2145 values.sals[0].line = SYMBOL_LINE (sym);
2146
2147 return values;
2148 }
2149 else if (SYMBOL_LINE (sym) != 0)
2150 {
2151 /* We know its line number. */
2152 values.sals = (struct symtab_and_line *)
2153 xmalloc (sizeof (struct symtab_and_line));
2154 values.nelts = 1;
2155 bzero (&values.sals[0], sizeof (values.sals[0]));
2156 values.sals[0].symtab = sym_symtab;
2157 values.sals[0].line = SYMBOL_LINE (sym);
2158 return values;
2159 }
2160 else
2161 /* This can happen if it is compiled with a compiler which doesn't
2162 put out line numbers for variables. */
2163 error ("Line number not known for symbol \"%s\"", copy);
2164 }
2165
2166 if ((i = lookup_misc_func (copy)) >= 0)
2167 {
2168 val.symtab = 0;
2169 val.line = 0;
2170 val.pc = misc_function_vector[i].address + FUNCTION_START_OFFSET;
2171 if (funfirstline)
2172 SKIP_PROLOGUE (val.pc);
2173 values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line));
2174 values.sals[0] = val;
2175 values.nelts = 1;
2176 return values;
2177 }
2178
2179 if (symtab_list == 0 && partial_symtab_list == 0 && misc_function_count == 0)
2180 error (no_symtab_msg);
2181
2182 error ("Function %s not defined.", copy);
2183 return values; /* for lint */
2184 }
2185
2186 struct symtabs_and_lines
2187 decode_line_spec (string, funfirstline)
2188 char *string;
2189 int funfirstline;
2190 {
2191 struct symtabs_and_lines sals;
2192 if (string == 0)
2193 error ("Empty line specification.");
2194 sals = decode_line_1 (&string, funfirstline,
2195 current_source_symtab, current_source_line);
2196 if (*string)
2197 error ("Junk at end of line specification: %s", string);
2198 return sals;
2199 }
2200
2201 /* Given a list of NELTS symbols in sym_arr (with corresponding
2202 mangled names in physnames), return a list of lines to operate on
2203 (ask user if necessary). */
2204 struct symtabs_and_lines
2205 decode_line_2 (sym_arr, nelts, funfirstline)
2206 struct symbol *sym_arr[];
2207 int nelts;
2208 int funfirstline;
2209 {
2210 struct symtabs_and_lines values, return_values;
2211 register CORE_ADDR pc;
2212 char *args, *arg1, *command_line_input ();
2213 int i;
2214 char *prompt;
2215
2216 values.sals = (struct symtab_and_line *) alloca (nelts * sizeof(struct symtab_and_line));
2217 return_values.sals = (struct symtab_and_line *) xmalloc (nelts * sizeof(struct symtab_and_line));
2218
2219 i = 0;
2220 printf("[0] cancel\n[1] all\n");
2221 while (i < nelts)
2222 {
2223 if (sym_arr[i] && SYMBOL_CLASS (sym_arr[i]) == LOC_BLOCK)
2224 {
2225 /* Arg is the name of a function */
2226 pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym_arr[i]))
2227 + FUNCTION_START_OFFSET;
2228 if (funfirstline)
2229 SKIP_PROLOGUE (pc);
2230 values.sals[i] = find_pc_line (pc, 0);
2231 values.sals[i].pc = (values.sals[i].end && values.sals[i].pc != pc) ?
2232 values.sals[i].end : pc;
2233 printf("[%d] file:%s; line number:%d\n",
2234 (i+2), values.sals[i].symtab->filename, values.sals[i].line);
2235 }
2236 else printf ("?HERE\n");
2237 i++;
2238 }
2239
2240 if ((prompt = getenv ("PS2")) == NULL)
2241 {
2242 prompt = ">";
2243 }
2244 printf("%s ",prompt);
2245 fflush(stdout);
2246
2247 args = command_line_input (0, 0);
2248
2249 if (args == 0)
2250 error_no_arg ("one or more choice numbers");
2251
2252 i = 0;
2253 while (*args)
2254 {
2255 int num;
2256
2257 arg1 = args;
2258 while (*arg1 >= '0' && *arg1 <= '9') arg1++;
2259 if (*arg1 && *arg1 != ' ' && *arg1 != '\t')
2260 error ("Arguments must be choice numbers.");
2261
2262 num = atoi (args);
2263
2264 if (num == 0)
2265 error ("cancelled");
2266 else if (num == 1)
2267 {
2268 bcopy (values.sals, return_values.sals, (nelts * sizeof(struct symtab_and_line)));
2269 return_values.nelts = nelts;
2270 return return_values;
2271 }
2272
2273 if (num > nelts + 2)
2274 {
2275 printf ("No choice number %d.\n", num);
2276 }
2277 else
2278 {
2279 num -= 2;
2280 if (values.sals[num].pc)
2281 {
2282 return_values.sals[i++] = values.sals[num];
2283 values.sals[num].pc = 0;
2284 }
2285 else
2286 {
2287 printf ("duplicate request for %d ignored.\n", num);
2288 }
2289 }
2290
2291 args = arg1;
2292 while (*args == ' ' || *args == '\t') args++;
2293 }
2294 return_values.nelts = i;
2295 return return_values;
2296 }
2297
2298 /* Return the index of misc function named NAME. */
2299
2300 int
2301 lookup_misc_func (name)
2302 register char *name;
2303 {
2304 register int i;
2305
2306 for (i = 0; i < misc_function_count; i++)
2307 if (!strcmp (misc_function_vector[i].name, name))
2308 return i;
2309 return -1; /* not found */
2310 }
2311 \f
2312 /* Slave routine for sources_info. Force line breaks at ,'s.
2313 NAME is the name to print and *FIRST is nonzero if this is the first
2314 name printed. Set *FIRST to zero. */
2315 static void
2316 output_source_filename (name, first)
2317 char *name;
2318 int *first;
2319 {
2320 static int column;
2321 /* Table of files printed so far. Since a single source file can
2322 result in several partial symbol tables, we need to avoid printing
2323 it more than once. Note: if some of the psymtabs are read in and
2324 some are not, it gets printed both under "Source files for which
2325 symbols have been read" and "Source files for which symbols will
2326 be read in on demand". I consider this a reasonable way to deal
2327 with the situation. I'm not sure whether this can also happen for
2328 symtabs; it doesn't hurt to check. */
2329 static char **tab = NULL;
2330 /* Allocated size of tab in elements.
2331 Start with one 256-byte block (when using GNU malloc.c).
2332 24 is the malloc overhead when range checking is in effect. */
2333 static int tab_alloc_size = (256 - 24) / sizeof (char *);
2334 /* Current size of tab in elements. */
2335 static int tab_cur_size;
2336
2337 char **p;
2338
2339 if (*first)
2340 {
2341 if (tab == NULL)
2342 tab = (char **) xmalloc (tab_alloc_size * sizeof (*tab));
2343 tab_cur_size = 0;
2344 }
2345
2346 /* Is NAME in tab? */
2347 for (p = tab; p < tab + tab_cur_size; p++)
2348 if (strcmp (*p, name) == 0)
2349 /* Yes; don't print it again. */
2350 return;
2351 /* No; add it to tab. */
2352 if (tab_cur_size == tab_alloc_size)
2353 {
2354 tab_alloc_size *= 2;
2355 tab = (char **) xrealloc (tab, tab_alloc_size * sizeof (*tab));
2356 }
2357 tab[tab_cur_size++] = name;
2358
2359 if (*first)
2360 {
2361 column = 0;
2362 *first = 0;
2363 }
2364 else
2365 {
2366 printf_filtered (",");
2367 column++;
2368 }
2369
2370 if (column != 0 && column + strlen (name) >= 70)
2371 {
2372 printf_filtered ("\n");
2373 column = 0;
2374 }
2375 else if (column != 0)
2376 {
2377 printf_filtered (" ");
2378 column++;
2379 }
2380 fputs_filtered (name, stdout);
2381 column += strlen (name);
2382 }
2383
2384 static void
2385 sources_info ()
2386 {
2387 register struct symtab *s;
2388 register struct partial_symtab *ps;
2389 int first;
2390
2391 if (symtab_list == 0 && partial_symtab_list == 0)
2392 {
2393 error (no_symtab_msg);
2394 }
2395
2396 printf_filtered ("Source files for which symbols have been read in:\n\n");
2397
2398 first = 1;
2399 for (s = symtab_list; s; s = s->next)
2400 output_source_filename (s->filename, &first);
2401 printf_filtered ("\n\n");
2402
2403 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2404
2405 first = 1;
2406 for (ps = partial_symtab_list; ps; ps = ps->next)
2407 if (!ps->readin)
2408 output_source_filename (ps->filename, &first);
2409 printf_filtered ("\n");
2410 }
2411
2412 /* List all symbols (if REGEXP is 0) or all symbols matching REGEXP.
2413 If CLASS is zero, list all symbols except functions and type names.
2414 If CLASS is 1, list only functions.
2415 If CLASS is 2, list only type names.
2416 If CLASS is 3, list only method names.
2417
2418 BPT is non-zero if we should set a breakpoint at the functions
2419 we find. */
2420
2421 static void
2422 list_symbols (regexp, class, bpt)
2423 char *regexp;
2424 int class;
2425 int bpt;
2426 {
2427 register struct symtab *s;
2428 register struct partial_symtab *ps;
2429 register struct blockvector *bv;
2430 struct blockvector *prev_bv = 0;
2431 register struct block *b;
2432 register int i, j;
2433 register struct symbol *sym;
2434 struct partial_symbol *psym;
2435 char *val;
2436 static char *classnames[]
2437 = {"variable", "function", "type", "method"};
2438 int found_in_file = 0;
2439 int found_misc = 0;
2440 static enum misc_function_type types[]
2441 = {mf_data, mf_text, mf_abs, mf_unknown};
2442 static enum misc_function_type types2[]
2443 = {mf_bss, mf_text, mf_abs, mf_unknown};
2444 enum misc_function_type ourtype = types[class];
2445 enum misc_function_type ourtype2 = types2[class];
2446
2447 if (regexp)
2448 if (0 != (val = re_comp (regexp)))
2449 error ("Invalid regexp (%s): %s", val, regexp);
2450
2451 /* Search through the partial_symtab_list *first* for all symbols
2452 matching the regexp. That way we don't have to reproduce all of
2453 the machinery below. */
2454 for (ps = partial_symtab_list; ps; ps = ps->next)
2455 {
2456 struct partial_symbol *bound, *gbound, *sbound;
2457 int keep_going = 1;
2458
2459 if (ps->readin) continue;
2460
2461 gbound = global_psymbols.list + ps->globals_offset + ps->n_global_syms;
2462 sbound = static_psymbols.list + ps->statics_offset + ps->n_static_syms;
2463 bound = gbound;
2464
2465 /* Go through all of the symbols stored in a partial
2466 symtab in one loop. */
2467 psym = global_psymbols.list + ps->globals_offset;
2468 while (keep_going)
2469 {
2470 if (psym >= bound)
2471 {
2472 if (bound == gbound && ps->n_static_syms != 0)
2473 {
2474 psym = static_psymbols.list + ps->statics_offset;
2475 bound = sbound;
2476 }
2477 else
2478 keep_going = 0;
2479 continue;
2480 }
2481 else
2482 {
2483 QUIT;
2484
2485 /* If it would match (logic taken from loop below)
2486 load the file and go on to the next one */
2487 if ((regexp == 0 || re_exec (SYMBOL_NAME (psym)))
2488 && ((class == 0 && SYMBOL_CLASS (psym) != LOC_TYPEDEF
2489 && SYMBOL_CLASS (psym) != LOC_BLOCK)
2490 || (class == 1 && SYMBOL_CLASS (psym) == LOC_BLOCK)
2491 || (class == 2 && SYMBOL_CLASS (psym) == LOC_TYPEDEF)
2492 || (class == 3 && SYMBOL_CLASS (psym) == LOC_BLOCK)))
2493 {
2494 (void) PSYMTAB_TO_SYMTAB(ps);
2495 keep_going = 0;
2496 }
2497 }
2498 psym++;
2499 }
2500 }
2501
2502 /* Here, we search through the misc function vector for functions that
2503 match, and call find_pc_symtab on them to force their symbols to
2504 be read. The symbol will then be found during the scan of symtabs
2505 below. If find_pc_symtab fails, set found_misc so that we will
2506 rescan to print any matching symbols without debug info. */
2507
2508 if (class == 1) {
2509 for (i = 0; i < misc_function_count; i++) {
2510 if (misc_function_vector[i].type != ourtype
2511 && misc_function_vector[i].type != ourtype2)
2512 continue;
2513 if (regexp == 0 || re_exec (misc_function_vector[i].name)) {
2514 if (0 == find_pc_symtab (misc_function_vector[i].address))
2515 found_misc = 1;
2516 }
2517 }
2518 }
2519
2520 /* Printout here so as to get after the "Reading in symbols"
2521 messages which will be generated above. */
2522 if (!bpt)
2523 printf_filtered (regexp
2524 ? "All %ss matching regular expression \"%s\":\n"
2525 : "All defined %ss:\n",
2526 classnames[class],
2527 regexp);
2528
2529 for (s = symtab_list; s; s = s->next)
2530 {
2531 found_in_file = 0;
2532 bv = BLOCKVECTOR (s);
2533 /* Often many files share a blockvector.
2534 Scan each blockvector only once so that
2535 we don't get every symbol many times.
2536 It happens that the first symtab in the list
2537 for any given blockvector is the main file. */
2538 if (bv != prev_bv)
2539 for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
2540 {
2541 b = BLOCKVECTOR_BLOCK (bv, i);
2542 /* Skip the sort if this block is always sorted. */
2543 if (!BLOCK_SHOULD_SORT (b))
2544 sort_block_syms (b);
2545 for (j = 0; j < BLOCK_NSYMS (b); j++)
2546 {
2547 QUIT;
2548 sym = BLOCK_SYM (b, j);
2549 if ((regexp == 0 || re_exec (SYMBOL_NAME (sym)))
2550 && ((class == 0 && SYMBOL_CLASS (sym) != LOC_TYPEDEF
2551 && SYMBOL_CLASS (sym) != LOC_BLOCK)
2552 || (class == 1 && SYMBOL_CLASS (sym) == LOC_BLOCK)
2553 || (class == 2 && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
2554 || (class == 3 && SYMBOL_CLASS (sym) == LOC_BLOCK)))
2555 {
2556 if (bpt)
2557 {
2558 /* Set a breakpoint here, if it's a function */
2559 if (class == 1)
2560 break_command (SYMBOL_NAME(sym), 0);
2561 }
2562 else if (!found_in_file)
2563 {
2564 fputs_filtered ("\nFile ", stdout);
2565 fputs_filtered (s->filename, stdout);
2566 fputs_filtered (":\n", stdout);
2567 }
2568 found_in_file = 1;
2569
2570 if (class != 2 && i == STATIC_BLOCK)
2571 printf_filtered ("static ");
2572
2573 /* Typedef that is not a C++ class */
2574 if (class == 2
2575 && SYMBOL_NAMESPACE (sym) != STRUCT_NAMESPACE)
2576 typedef_print (SYMBOL_TYPE(sym), sym, stdout);
2577 /* variable, func, or typedef-that-is-c++-class */
2578 else if (class < 2 ||
2579 (class == 2 &&
2580 SYMBOL_NAMESPACE(sym) == STRUCT_NAMESPACE))
2581 {
2582 type_print (SYMBOL_TYPE (sym),
2583 (SYMBOL_CLASS (sym) == LOC_TYPEDEF
2584 ? "" : SYMBOL_NAME (sym)),
2585 stdout, 0);
2586
2587 printf_filtered (";\n");
2588 }
2589 else
2590 {
2591 # if 0
2592 char buf[1024];
2593 type_print_base (TYPE_FN_FIELD_TYPE(t, i), stdout, 0, 0);
2594 type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t, i), stdout, 0);
2595 sprintf (buf, " %s::", type_name_no_tag (t));
2596 type_print_method_args (TYPE_FN_FIELD_ARGS (t, i), buf, name, stdout);
2597 # endif
2598 }
2599 }
2600 }
2601 }
2602 prev_bv = bv;
2603 }
2604
2605
2606 /* If there are no eyes, avoid all contact. I mean, if there are
2607 no debug symbols, then print directly from the misc_function_vector. */
2608
2609 if (found_misc || class != 1) {
2610 found_in_file = 0;
2611 for (i = 0; i < misc_function_count; i++) {
2612 if (misc_function_vector[i].type != ourtype
2613 && misc_function_vector[i].type != ourtype2)
2614 continue;
2615 if (regexp == 0 || re_exec (misc_function_vector[i].name)) {
2616 /* Functions: Look up by address. */
2617 if (class == 1)
2618 if (0 != find_pc_symtab (misc_function_vector[i].address))
2619 continue;
2620 /* Variables/Absolutes: Look up by name */
2621 if (0 != lookup_symbol (misc_function_vector[i].name,
2622 (struct block *)0, VAR_NAMESPACE, 0, (struct symtab **)0))
2623 continue;
2624 if (!found_in_file) {
2625 printf_filtered ("\nNon-debugging symbols:\n");
2626 found_in_file = 1;
2627 }
2628 printf_filtered (" %08x %s\n",
2629 misc_function_vector[i].address,
2630 misc_function_vector[i].name);
2631 }
2632 }
2633 }
2634 }
2635
2636 static void
2637 variables_info (regexp)
2638 char *regexp;
2639 {
2640 list_symbols (regexp, 0, 0);
2641 }
2642
2643 static void
2644 functions_info (regexp)
2645 char *regexp;
2646 {
2647 list_symbols (regexp, 1, 0);
2648 }
2649
2650 static void
2651 types_info (regexp)
2652 char *regexp;
2653 {
2654 list_symbols (regexp, 2, 0);
2655 }
2656
2657 #if 0
2658 /* Tiemann says: "info methods was never implemented." */
2659 static void
2660 methods_info (regexp)
2661 char *regexp;
2662 {
2663 list_symbols (regexp, 3, 0);
2664 }
2665 #endif /* 0 */
2666
2667 /* Breakpoint all functions matching regular expression. */
2668 static void
2669 rbreak_command (regexp)
2670 char *regexp;
2671 {
2672 list_symbols (regexp, 1, 1);
2673 }
2674 \f
2675 /* Helper function to initialize the standard scalar types. */
2676
2677 struct type *
2678 init_type (code, length, uns, name)
2679 enum type_code code;
2680 int length, uns;
2681 char *name;
2682 {
2683 register struct type *type;
2684
2685 type = (struct type *) xmalloc (sizeof (struct type));
2686 bzero (type, sizeof *type);
2687 TYPE_CODE (type) = code;
2688 TYPE_LENGTH (type) = length;
2689 TYPE_FLAGS (type) = uns ? TYPE_FLAG_UNSIGNED : 0;
2690 TYPE_FLAGS (type) |= TYPE_FLAG_PERM;
2691 TYPE_NFIELDS (type) = 0;
2692 TYPE_NAME (type) = name;
2693
2694 /* C++ fancies. */
2695 if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION)
2696 INIT_CPLUS_SPECIFIC(type);
2697 return type;
2698 }
2699
2700 /* Return Nonzero if block a is lexically nested within block b,
2701 or if a and b have the same pc range.
2702 Return zero otherwise. */
2703 int
2704 contained_in (a, b)
2705 struct block *a, *b;
2706 {
2707 if (!a || !b)
2708 return 0;
2709 return BLOCK_START (a) >= BLOCK_START (b)
2710 && BLOCK_END (a) <= BLOCK_END (b);
2711 }
2712
2713 \f
2714 /* Helper routine for make_symbol_completion_list. */
2715
2716 int return_val_size, return_val_index;
2717 char **return_val;
2718
2719 void
2720 completion_list_add_symbol (symname)
2721 char *symname;
2722 {
2723 if (return_val_index + 3 > return_val_size)
2724 return_val =
2725 (char **)xrealloc (return_val,
2726 (return_val_size *= 2) * sizeof (char *));
2727
2728 return_val[return_val_index] =
2729 (char *)xmalloc (1 + strlen (symname));
2730
2731 strcpy (return_val[return_val_index], symname);
2732
2733 return_val[++return_val_index] = (char *)NULL;
2734 }
2735
2736 /* Return a NULL terminated array of all symbols (regardless of class) which
2737 begin by matching TEXT. If the answer is no symbols, then the return value
2738 is an array which contains only a NULL pointer.
2739
2740 Problem: All of the symbols have to be copied because readline
2741 frees them. I'm not going to worry about this; hopefully there
2742 won't be that many. */
2743
2744 char **
2745 make_symbol_completion_list (text)
2746 char *text;
2747 {
2748 register struct symtab *s;
2749 register struct partial_symtab *ps;
2750 register struct block *b, *surrounding_static_block = 0;
2751 extern struct block *get_selected_block ();
2752 register int i, j;
2753 struct partial_symbol *psym;
2754
2755 int text_len = strlen (text);
2756 return_val_size = 100;
2757 return_val_index = 0;
2758 return_val =
2759 (char **)xmalloc ((1 + return_val_size) *sizeof (char *));
2760 return_val[0] = (char *)NULL;
2761
2762 /* Look through the partial symtabs for all symbols which begin
2763 by matching TEXT. Add each one that you find to the list. */
2764
2765 for (ps = partial_symtab_list; ps; ps = ps->next)
2766 {
2767 /* If the psymtab's been read in we'll get it when we search
2768 through the blockvector. */
2769 if (ps->readin) continue;
2770
2771 for (psym = global_psymbols.list + ps->globals_offset;
2772 psym < (global_psymbols.list + ps->globals_offset
2773 + ps->n_global_syms);
2774 psym++)
2775 {
2776 QUIT; /* If interrupted, then quit. */
2777 if ((strncmp (SYMBOL_NAME (psym), text, text_len) == 0))
2778 completion_list_add_symbol (SYMBOL_NAME (psym));
2779 }
2780
2781 for (psym = static_psymbols.list + ps->statics_offset;
2782 psym < (static_psymbols.list + ps->statics_offset
2783 + ps->n_static_syms);
2784 psym++)
2785 {
2786 QUIT;
2787 if ((strncmp (SYMBOL_NAME (psym), text, text_len) == 0))
2788 completion_list_add_symbol (SYMBOL_NAME (psym));
2789 }
2790 }
2791
2792 /* At this point scan through the misc function vector and add each
2793 symbol you find to the list. Eventually we want to ignore
2794 anything that isn't a text symbol (everything else will be
2795 handled by the psymtab code above). */
2796
2797 for (i = 0; i < misc_function_count; i++)
2798 if (!strncmp (text, misc_function_vector[i].name, text_len))
2799 completion_list_add_symbol (misc_function_vector[i].name);
2800
2801 /* Search upwards from currently selected frame (so that we can
2802 complete on local vars. */
2803 for (b = get_selected_block (); b; b = BLOCK_SUPERBLOCK (b))
2804 {
2805 if (!BLOCK_SUPERBLOCK (b))
2806 surrounding_static_block = b; /* For elmin of dups */
2807
2808 /* Also catch fields of types defined in this places which
2809 match our text string. Only complete on types visible
2810 from current context. */
2811 for (i = 0; i < BLOCK_NSYMS (b); i++)
2812 {
2813 register struct symbol *sym = BLOCK_SYM (b, i);
2814
2815 if (!strncmp (SYMBOL_NAME (sym), text, text_len))
2816 completion_list_add_symbol (SYMBOL_NAME (sym));
2817
2818 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF)
2819 {
2820 struct type *t = SYMBOL_TYPE (sym);
2821 enum type_code c = TYPE_CODE (t);
2822
2823 if (c == TYPE_CODE_UNION || c == TYPE_CODE_STRUCT)
2824 for (j = TYPE_N_BASECLASSES (t); j < TYPE_NFIELDS (t); j++)
2825 if (TYPE_FIELD_NAME (t, j) &&
2826 !strncmp (TYPE_FIELD_NAME (t, j), text, text_len))
2827 completion_list_add_symbol (TYPE_FIELD_NAME (t, j));
2828 }
2829 }
2830 }
2831
2832 /* Go through the symtabs and check the externs and statics for
2833 symbols which match. */
2834
2835 for (s = symtab_list; s; s = s->next)
2836 {
2837 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
2838
2839 for (i = 0; i < BLOCK_NSYMS (b); i++)
2840 if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b, i)), text, text_len))
2841 completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b, i)));
2842 }
2843
2844 for (s = symtab_list; s; s = s->next)
2845 {
2846 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
2847
2848 /* Don't do this block twice. */
2849 if (b == surrounding_static_block) continue;
2850
2851 for (i = 0; i < BLOCK_NSYMS (b); i++)
2852 if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b, i)), text, text_len))
2853 completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b, i)));
2854 }
2855
2856 return (return_val);
2857 }
2858 \f
2859 #if 0
2860 /* Add the type of the symbol sym to the type of the current
2861 function whose block we are in (assumed). The type of
2862 this current function is contained in *TYPE.
2863
2864 This basically works as follows: When we find a function
2865 symbol (N_FUNC with a 'f' or 'F' in the symbol name), we record
2866 a pointer to its type in the global in_function_type. Every
2867 time we come across a parameter symbol ('p' in its name), then
2868 this procedure adds the name and type of that parameter
2869 to the function type pointed to by *TYPE. (Which should correspond
2870 to in_function_type if it was called correctly).
2871
2872 Note that since we are modifying a type, the result of
2873 lookup_function_type() should be bcopy()ed before calling
2874 this. When not in strict typing mode, the expression
2875 evaluator can choose to ignore this.
2876
2877 Assumption: All of a function's parameter symbols will
2878 appear before another function symbol is found. The parameters
2879 appear in the same order in the argument list as they do in the
2880 symbol table. */
2881
2882 void
2883 add_param_to_type (type,sym)
2884 struct type **type;
2885 struct symbol *sym;
2886 {
2887 int num = ++(TYPE_NFIELDS(*type));
2888
2889 if(TYPE_NFIELDS(*type)-1)
2890 TYPE_FIELDS(*type) =
2891 (struct field *)xrealloc((char *)(TYPE_FIELDS(*type)),
2892 num*sizeof(struct field));
2893 else
2894 TYPE_FIELDS(*type) =
2895 (struct field *)xmalloc(num*sizeof(struct field));
2896
2897 TYPE_FIELD_BITPOS(*type,num-1) = num-1;
2898 TYPE_FIELD_BITSIZE(*type,num-1) = 0;
2899 TYPE_FIELD_TYPE(*type,num-1) = SYMBOL_TYPE(sym);
2900 TYPE_FIELD_NAME(*type,num-1) = SYMBOL_NAME(sym);
2901 }
2902 #endif
2903 \f
2904 void
2905 _initialize_symtab ()
2906 {
2907 add_info ("variables", variables_info,
2908 "All global and static variable names, or those matching REGEXP.");
2909 add_info ("functions", functions_info,
2910 "All function names, or those matching REGEXP.");
2911
2912 /* FIXME: This command has at least the following problems:
2913 1. It prints builtin types (in a very strange and confusing fashion).
2914 2. It doesn't print right, e.g. with
2915 typedef struct foo *FOO
2916 type_print prints "FOO" when we want to make it (in this situation)
2917 print "struct foo *".
2918 I also think "ptype" or "whatis" is more likely to be useful (but if
2919 there is much disagreement "info types" can be fixed). */
2920 add_info ("types", types_info,
2921 "All type names, or those matching REGEXP.");
2922
2923 #if 0
2924 add_info ("methods", methods_info,
2925 "All method names, or those matching REGEXP::REGEXP.\n\
2926 If the class qualifier is ommited, it is assumed to be the current scope.\n\
2927 If the first REGEXP is ommited, then all methods matching the second REGEXP\n\
2928 are listed.");
2929 #endif
2930 add_info ("sources", sources_info,
2931 "Source files in the program.");
2932
2933 add_com ("rbreak", no_class, rbreak_command,
2934 "Set a breakpoint for all functions matching REGEXP.");
2935
2936 /* Initialize the one built-in type that isn't language dependent... */
2937 builtin_type_error = init_type (TYPE_CODE_ERROR, 0, 0, "<unknown type>");
2938 }