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