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