5540954ff9f8e905ac859baa945614960492dddb
[binutils-gdb.git] / gdb / symtab.c
1 /* Symbol table lookup for the GNU debugger, GDB.
2 Copyright (C) 1986, 1987, 1988 Free Software Foundation, Inc.
3
4 GDB is distributed in the hope that it will be useful, but WITHOUT ANY
5 WARRANTY. No author or distributor accepts responsibility to anyone
6 for the consequences of using it or for whether it serves any
7 particular purpose or works at all, unless he says so in writing.
8 Refer to the GDB General Public License for full details.
9
10 Everyone is granted permission to copy, modify and redistribute GDB,
11 but only under the conditions described in the GDB General Public
12 License. A copy of this license is supposed to have been given to you
13 along with GDB so you can know your rights and responsibilities. It
14 should be in a file named COPYING. Among other things, the copyright
15 notice and this notice must be preserved on all copies.
16
17 In other words, go ahead and share GDB, but don't try to stop
18 anyone else from sharing it farther. Help stamp out software hoarding!
19 */
20
21 #include "defs.h"
22 #include "initialize.h"
23 #include "symtab.h"
24 #include "param.h"
25
26 #include <stdio.h>
27 #include <obstack.h>
28
29 START_FILE
30
31 /* Allocate an obstack to hold objects that should be freed
32 when we load a new symbol table.
33 This includes the symbols made by dbxread
34 and the types that are not permanent. */
35
36 struct obstack obstack1;
37
38 struct obstack *symbol_obstack = &obstack1;
39
40 /* These variables point to the objects
41 representing the predefined C data types. */
42
43 struct type *builtin_type_void;
44 struct type *builtin_type_char;
45 struct type *builtin_type_short;
46 struct type *builtin_type_int;
47 struct type *builtin_type_long;
48 struct type *builtin_type_unsigned_char;
49 struct type *builtin_type_unsigned_short;
50 struct type *builtin_type_unsigned_int;
51 struct type *builtin_type_unsigned_long;
52 struct type *builtin_type_float;
53 struct type *builtin_type_double;
54
55 /* Lookup the symbol table of a source file named NAME. */
56
57 struct symtab *
58 lookup_symtab (name)
59 char *name;
60 {
61 register struct symtab *s;
62 register char *copy;
63
64 for (s = symtab_list; s; s = s->next)
65 if (!strcmp (name, s->filename))
66 return s;
67
68 /* If name not found as specified, see if adding ".c" helps. */
69
70 copy = (char *) alloca (strlen (name) + 3);
71 strcpy (copy, name);
72 strcat (copy, ".c");
73 for (s = symtab_list; s; s = s->next)
74 if (!strcmp (copy, s->filename))
75 return s;
76
77 return 0;
78 }
79 \f
80 /* Lookup a typedef or primitive type named NAME,
81 visible in lexical block BLOCK.
82 If NOERR is nonzero, return zero if NAME is not suitably defined. */
83
84 struct type *
85 lookup_typename (name, block, noerr)
86 char *name;
87 struct block *block;
88 int noerr;
89 {
90 register struct symbol *sym = lookup_symbol (name, block, VAR_NAMESPACE);
91 if (sym == 0 || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
92 {
93 if (!strcmp (name, "int"))
94 return builtin_type_int;
95 if (!strcmp (name, "long"))
96 return builtin_type_long;
97 if (!strcmp (name, "short"))
98 return builtin_type_short;
99 if (!strcmp (name, "char"))
100 return builtin_type_char;
101 if (!strcmp (name, "float"))
102 return builtin_type_float;
103 if (!strcmp (name, "double"))
104 return builtin_type_double;
105 if (!strcmp (name, "void"))
106 return builtin_type_void;
107
108 if (noerr)
109 return 0;
110 error ("No type named %s.", name);
111 }
112 return SYMBOL_TYPE (sym);
113 }
114
115 struct type *
116 lookup_unsigned_typename (name)
117 char *name;
118 {
119 if (!strcmp (name, "int"))
120 return builtin_type_unsigned_int;
121 if (!strcmp (name, "long"))
122 return builtin_type_unsigned_long;
123 if (!strcmp (name, "short"))
124 return builtin_type_unsigned_short;
125 if (!strcmp (name, "char"))
126 return builtin_type_unsigned_char;
127 error ("No type named unsigned %s.", name);
128 }
129
130 /* Lookup a structure type named "struct NAME",
131 visible in lexical block BLOCK. */
132
133 struct type *
134 lookup_struct (name, block)
135 char *name;
136 struct block *block;
137 {
138 register struct symbol *sym = lookup_symbol (name, block, STRUCT_NAMESPACE);
139 if (sym == 0)
140 error ("No struct type named %s.", name);
141 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
142 error ("This context has class, union or enum %s, not a struct.", name);
143 return SYMBOL_TYPE (sym);
144 }
145
146 /* Lookup a union type named "union NAME",
147 visible in lexical block BLOCK. */
148
149 struct type *
150 lookup_union (name, block)
151 char *name;
152 struct block *block;
153 {
154 register struct symbol *sym = lookup_symbol (name, block, STRUCT_NAMESPACE);
155 if (sym == 0)
156 error ("No union type named %s.", name);
157 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_UNION)
158 error ("This context has class, struct or enum %s, not a union.", name);
159 return SYMBOL_TYPE (sym);
160 }
161
162 /* Lookup an enum type named "enum NAME",
163 visible in lexical block BLOCK. */
164
165 struct type *
166 lookup_enum (name, block)
167 char *name;
168 struct block *block;
169 {
170 register struct symbol *sym = lookup_symbol (name, block, STRUCT_NAMESPACE);
171 if (sym == 0)
172 error ("No enum type named %s.", name);
173 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
174 error ("This context has class, struct or union %s, not an enum.", name);
175 return SYMBOL_TYPE (sym);
176 }
177
178 /* Given a type TYPE, return a type of pointers to that type.
179 May need to construct such a type if this is the first use.
180
181 C++: use TYPE_MAIN_VARIANT and TYPE_CHAIN to keep pointer
182 to member types under control. */
183
184 struct type *
185 lookup_pointer_type (type)
186 struct type *type;
187 {
188 register struct type *ptype = TYPE_POINTER_TYPE (type);
189 if (ptype) return TYPE_MAIN_VARIANT (ptype);
190
191 /* This is the first time anyone wanted a pointer to a TYPE. */
192 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
193 ptype = (struct type *) xmalloc (sizeof (struct type));
194 else
195 ptype = (struct type *) obstack_alloc (symbol_obstack,
196 sizeof (struct type));
197
198 bzero (ptype, sizeof (struct type));
199 TYPE_MAIN_VARIANT (ptype) = ptype;
200 TYPE_TARGET_TYPE (ptype) = type;
201 TYPE_POINTER_TYPE (type) = ptype;
202 /* New type is permanent if type pointed to is permanent. */
203 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
204 TYPE_FLAGS (ptype) |= TYPE_FLAG_PERM;
205 /* We assume the machine has only one representation for pointers! */
206 TYPE_LENGTH (ptype) = sizeof (char *);
207 TYPE_CODE (ptype) = TYPE_CODE_PTR;
208 return ptype;
209 }
210
211 struct type *
212 lookup_reference_type (type)
213 struct type *type;
214 {
215 register struct type *rtype = TYPE_REFERENCE_TYPE (type);
216 if (rtype) return TYPE_MAIN_VARIANT (rtype);
217
218 /* This is the first time anyone wanted a pointer to a TYPE. */
219 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
220 rtype = (struct type *) xmalloc (sizeof (struct type));
221 else
222 rtype = (struct type *) obstack_alloc (symbol_obstack,
223 sizeof (struct type));
224
225 bzero (rtype, sizeof (struct type));
226 TYPE_MAIN_VARIANT (rtype) = rtype;
227 TYPE_TARGET_TYPE (rtype) = type;
228 TYPE_REFERENCE_TYPE (type) = rtype;
229 /* New type is permanent if type pointed to is permanent. */
230 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
231 TYPE_FLAGS (rtype) |= TYPE_FLAG_PERM;
232 /* We assume the machine has only one representation for pointers! */
233 TYPE_LENGTH (rtype) = sizeof (char *);
234 TYPE_CODE (rtype) = TYPE_CODE_REF;
235 return rtype;
236 }
237
238
239 /* Given a type TYPE, return a type of pointers to that type.
240 May need to construct such a type if this is the first use.
241 The TYPE is the type of the member. The DOMAIN is the type
242 of the aggregate that the member belongs to. */
243
244 struct type *
245 lookup_member_pointer_type (type, domain)
246 struct type *type, *domain;
247 {
248 register struct type *ptype = TYPE_POINTER_TYPE (type);
249 struct type *main_type;
250
251 if (ptype)
252 {
253 ptype = TYPE_MAIN_VARIANT (ptype);
254 main_type = ptype;
255 while (ptype)
256 {
257 if (TYPE_DOMAIN_TYPE (ptype) == domain)
258 return ptype;
259 ptype = TYPE_CHAIN (ptype);
260 }
261 }
262 else
263 {
264 main_type = lookup_pointer_type (type);
265 TYPE_POINTER_TYPE (type) = main_type;
266 }
267
268 /* This is the first time anyone wanted a pointer to a TYPE. */
269 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
270 ptype = (struct type *) xmalloc (sizeof (struct type));
271 else
272 ptype = (struct type *) obstack_alloc (symbol_obstack,
273 sizeof (struct type));
274
275 bzero (ptype, sizeof (struct type));
276 TYPE_MAIN_VARIANT (ptype) = main_type;
277 TYPE_TARGET_TYPE (ptype) = type;
278 TYPE_DOMAIN_TYPE (ptype) = domain;
279 TYPE_POINTER_TYPE (type) = ptype;
280 /* New type is permanent if type pointed to is permanent. */
281 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
282 TYPE_FLAGS (ptype) |= TYPE_FLAG_PERM;
283 /* We assume the machine has only one representation for pointers! */
284 TYPE_LENGTH (ptype) = sizeof (char *);
285 TYPE_CODE (ptype) = TYPE_CODE_MPTR;
286
287 /* Now splice in the new member pointer type. */
288 if (main_type)
289 {
290 /* This type was not "smashed". */
291 TYPE_CHAIN (ptype) = TYPE_CHAIN (main_type);
292 TYPE_CHAIN (main_type) = ptype;
293 }
294
295 return ptype;
296 }
297
298 /* Given a type TYPE, return a type of functions that return that type.
299 May need to construct such a type if this is the first use. */
300
301 struct type *
302 lookup_function_type (type, argtypes)
303 struct type *type;
304 struct type **argtypes;
305 {
306 register struct type *ptype = TYPE_FUNCTION_TYPE (type);
307 if (ptype) return ptype;
308
309 /* This is the first time anyone wanted a function returning a TYPE. */
310 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
311 ptype = (struct type *) xmalloc (sizeof (struct type));
312 else
313 ptype = (struct type *) obstack_alloc (symbol_obstack,
314 sizeof (struct type));
315
316 bzero (ptype, sizeof (struct type));
317 TYPE_TARGET_TYPE (ptype) = type;
318 TYPE_FUNCTION_TYPE (type) = ptype;
319 /* New type is permanent if type returned is permanent. */
320 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
321 TYPE_FLAGS (ptype) |= TYPE_FLAG_PERM;
322 TYPE_LENGTH (ptype) = 1;
323 TYPE_CODE (ptype) = TYPE_CODE_FUNC;
324 TYPE_NFIELDS (ptype) = 0;
325 return ptype;
326 }
327 \f
328 /* Smash TYPE to be a type of pointers to TO_TYPE.
329 If TO_TYPE is not permanent and has no pointer-type yet,
330 record TYPE as its pointer-type. */
331
332 void
333 smash_to_pointer_type (type, to_type)
334 struct type *type, *to_type;
335 {
336 bzero (type, sizeof (struct type));
337 TYPE_TARGET_TYPE (type) = to_type;
338 /* We assume the machine has only one representation for pointers! */
339 TYPE_LENGTH (type) = sizeof (char *);
340 TYPE_CODE (type) = TYPE_CODE_PTR;
341
342 TYPE_MAIN_VARIANT (type) = type;
343
344 if (TYPE_POINTER_TYPE (to_type) == 0
345 && !(TYPE_FLAGS (type) & TYPE_FLAG_PERM))
346 {
347 TYPE_POINTER_TYPE (to_type) = type;
348 }
349 }
350
351 /* Smash TYPE to be a type of pointers to TO_TYPE.
352 If TO_TYPE is not permanent and has no pointer-type yet,
353 record TYPE as its pointer-type.
354
355 TYPE is the type of the member. DOMAIN is the type of
356 the aggregate that the member belongs to. */
357
358 void
359 smash_to_member_pointer_type (type, domain, to_type)
360 struct type *type, *domain, *to_type;
361 {
362 bzero (type, sizeof (struct type));
363 TYPE_TARGET_TYPE (type) = to_type;
364 TYPE_DOMAIN_TYPE (type) = domain;
365 /* We assume the machine has only one representation for pointers! */
366 TYPE_LENGTH (type) = sizeof (char *);
367 TYPE_CODE (type) = TYPE_CODE_MPTR;
368
369 TYPE_MAIN_VARIANT (type) = lookup_pointer_type (to_type);
370
371 if (TYPE_POINTER_TYPE (to_type) == 0
372 && !(TYPE_FLAGS (type) & TYPE_FLAG_PERM))
373 {
374 TYPE_POINTER_TYPE (to_type) = type;
375 }
376 }
377
378 /* Smash TYPE to be a type of reference to TO_TYPE.
379 If TO_TYPE is not permanent and has no pointer-type yet,
380 record TYPE as its pointer-type. */
381
382 void
383 smash_to_reference_type (type, to_type)
384 struct type *type, *to_type;
385 {
386 bzero (type, sizeof (struct type));
387 TYPE_TARGET_TYPE (type) = to_type;
388 /* We assume the machine has only one representation for pointers! */
389 TYPE_LENGTH (type) = sizeof (char *);
390 TYPE_CODE (type) = TYPE_CODE_REF;
391
392 TYPE_MAIN_VARIANT (type) = type;
393
394 if (TYPE_REFERENCE_TYPE (to_type) == 0
395 && !(TYPE_FLAGS (type) & TYPE_FLAG_PERM))
396 {
397 TYPE_REFERENCE_TYPE (to_type) = type;
398 }
399 }
400
401 /* Smash TYPE to be a type of functions returning TO_TYPE.
402 If TO_TYPE is not permanent and has no function-type yet,
403 record TYPE as its function-type. */
404
405 void
406 smash_to_function_type (type, to_type)
407 struct type *type, *to_type;
408 {
409 bzero (type, sizeof (struct type));
410 TYPE_TARGET_TYPE (type) = to_type;
411 TYPE_LENGTH (type) = 1;
412 TYPE_CODE (type) = TYPE_CODE_FUNC;
413 TYPE_NFIELDS (type) = 0;
414
415 if (TYPE_FUNCTION_TYPE (to_type) == 0
416 && !(TYPE_FLAGS (type) & TYPE_FLAG_PERM))
417 {
418 TYPE_FUNCTION_TYPE (to_type) = type;
419 }
420 }
421 \f
422 static struct symbol *lookup_block_symbol ();
423
424 /* Find the definition for a specified symbol name NAME
425 in namespace NAMESPACE, visible from lexical block BLOCK.
426 Returns the struct symbol pointer, or zero if no symbol is found. */
427
428 struct symbol *
429 lookup_symbol_1 (name, block, namespace)
430 char *name;
431 register struct block *block;
432 enum namespace namespace;
433 {
434 register int i, n;
435 register struct symbol *sym;
436 register struct symtab *s;
437 struct blockvector *bv;
438
439 /* Search specified block and its superiors. */
440
441 while (block != 0)
442 {
443 sym = lookup_block_symbol (block, name, namespace);
444 if (sym) return sym;
445 block = BLOCK_SUPERBLOCK (block);
446 }
447 return 0;
448 }
449
450 struct symbol *
451 lookup_symbol_2 (name, block, namespace)
452 char *name;
453 register struct block *block; /* ignored as parameter */
454 enum namespace namespace;
455 {
456 register int i, n;
457 register struct symbol *sym;
458 register struct symtab *s;
459 struct blockvector *bv;
460
461 /* Now search all symtabs' global blocks. */
462
463 for (s = symtab_list; s; s = s->next)
464 {
465 bv = BLOCKVECTOR (s);
466 block = BLOCKVECTOR_BLOCK (bv, 0);
467 sym = lookup_block_symbol (block, name, namespace);
468 if (sym) return sym;
469 }
470
471 /* Now search all symtabs' per-file blocks.
472 Not strictly correct, but more useful than an error. */
473
474 for (s = symtab_list; s; s = s->next)
475 {
476 bv = BLOCKVECTOR (s);
477 block = BLOCKVECTOR_BLOCK (bv, 1);
478 sym = lookup_block_symbol (block, name, namespace);
479 if (sym) return sym;
480 }
481 return 0;
482 }
483
484 struct symbol *
485 lookup_symbol (name, block, namespace)
486 char *name;
487 register struct block *block;
488 enum namespace namespace;
489 {
490 register int i, n;
491 register struct symbol *sym;
492 register struct symtab *s;
493 struct blockvector *bv;
494
495 /* Search specified block and its superiors. */
496
497 while (block != 0)
498 {
499 sym = lookup_block_symbol (block, name, namespace);
500 if (sym) return sym;
501 block = BLOCK_SUPERBLOCK (block);
502 }
503
504 /* Now search all symtabs' global blocks. */
505
506 for (s = symtab_list; s; s = s->next)
507 {
508 bv = BLOCKVECTOR (s);
509 block = BLOCKVECTOR_BLOCK (bv, 0);
510 sym = lookup_block_symbol (block, name, namespace);
511 if (sym) return sym;
512 }
513
514 /* Now search all symtabs' per-file blocks.
515 Not strictly correct, but more useful than an error. */
516
517 for (s = symtab_list; s; s = s->next)
518 {
519 bv = BLOCKVECTOR (s);
520 block = BLOCKVECTOR_BLOCK (bv, 1);
521 sym = lookup_block_symbol (block, name, namespace);
522 if (sym) return sym;
523 }
524 return 0;
525 }
526
527 /* Look for a symbol in block BLOCK using binary search. */
528
529 static struct symbol *
530 lookup_block_symbol (block, name, namespace)
531 register struct block *block;
532 char *name;
533 enum namespace namespace;
534 {
535 register int bot, top, inc;
536 register struct symbol *sym;
537
538 top = BLOCK_NSYMS (block);
539 bot = 0;
540
541 /* First, advance BOT to not far before
542 the first symbol whose name is NAME. */
543
544 while (1)
545 {
546 inc = (top - bot + 1);
547 /* No need to keep binary searching for the last few bits worth. */
548 if (inc < 7)
549 break;
550 inc >>= 1;
551 sym = BLOCK_SYM (block, bot + inc);
552 if (strcmp (SYMBOL_NAME (sym), name) < 0)
553 bot += inc;
554 else
555 top = bot + inc;
556 }
557
558 /* Now scan forward until we run out of symbols,
559 find one whose name is greater than NAME,
560 or find one we want.
561 If there is more than one symbol with the right name and namespace,
562 we return the first one. dbxread.c is careful to make sure
563 that if one is a register then it comes first. */
564
565 top = BLOCK_NSYMS (block);
566 while (bot < top)
567 {
568 sym = BLOCK_SYM (block, bot);
569 inc = strcmp (SYMBOL_NAME (sym), name);
570 if (inc == 0 && SYMBOL_NAMESPACE (sym) == namespace)
571 return sym;
572 if (inc > 0)
573 return 0;
574 bot++;
575 }
576 return 0;
577 }
578 \f
579 /* Return the symbol for the function which contains a specified
580 lexical block, described by a struct block BL. */
581
582 struct symbol *
583 block_function (bl)
584 struct block *bl;
585 {
586 while (BLOCK_FUNCTION (bl) == 0 && BLOCK_SUPERBLOCK (bl) != 0)
587 bl = BLOCK_SUPERBLOCK (bl);
588
589 return BLOCK_FUNCTION (bl);
590 }
591
592 /* Subroutine of find_pc_line */
593
594 static struct symtab *
595 find_pc_symtab (pc)
596 register CORE_ADDR pc;
597 {
598 register struct block *b;
599 struct blockvector *bv;
600 register struct symtab *s;
601
602 /* Search all symtabs for one whose file contains our pc */
603
604 for (s = symtab_list; s; s = s->next)
605 {
606 bv = BLOCKVECTOR (s);
607 b = BLOCKVECTOR_BLOCK (bv, 0);
608 if (BLOCK_START (b) <= pc
609 && BLOCK_END (b) > pc)
610 break;
611 }
612
613 return s;
614 }
615
616 /* Find the source file and line number for a given PC value.
617 Return a structure containing a symtab pointer, a line number,
618 and a pc range for the entire source line.
619 The value's .pc field is NOT the specified pc.
620 NOTCURRENT nonzero means, if specified pc is on a line boundary,
621 use the line that ends there. Otherwise, in that case, the line
622 that begins there is used. */
623
624 struct symtab_and_line
625 find_pc_line (pc, notcurrent)
626 CORE_ADDR pc;
627 int notcurrent;
628 {
629 struct symtab *s;
630 register struct linetable *l;
631 register int len;
632 register int i, item;
633 int line;
634 struct symtab_and_line value;
635 struct blockvector *bv;
636
637 /* Info on best line seen so far, and where it starts, and its file. */
638
639 int best_line = 0;
640 CORE_ADDR best_pc = 0;
641 CORE_ADDR best_end = 0;
642 struct symtab *best_symtab = 0;
643
644 /* Store here the first line number
645 of a file which contains the line at the smallest pc after PC.
646 If we don't find a line whose range contains PC,
647 we will use a line one less than this,
648 with a range from the start of that file to the first line's pc. */
649 int alt_line = 0;
650 CORE_ADDR alt_pc = 0;
651 struct symtab *alt_symtab = 0;
652
653 /* Info on best line seen in this file. */
654
655 int prev_line;
656 CORE_ADDR prev_pc;
657
658 /* Info on first line of this file. */
659
660 int first_line;
661 CORE_ADDR first_pc;
662
663 /* If this pc is not from the current frame,
664 it is the address of the end of a call instruction.
665 Quite likely that is the start of the following statement.
666 But what we want is the statement containing the instruction.
667 Fudge the pc to make sure we get that. */
668
669 if (notcurrent) pc -= 1;
670
671 s = find_pc_symtab (pc);
672 if (s == 0)
673 {
674 value.symtab = 0;
675 value.line = 0;
676 value.pc = pc;
677 return value;
678 }
679
680 bv = BLOCKVECTOR (s);
681
682 /* Look at all the symtabs that share this blockvector.
683 They all have the same apriori range, that we found was right;
684 but they have different line tables. */
685
686 for (; s && BLOCKVECTOR (s) == bv; s = s->next)
687 {
688 /* Find the best line in this symtab. */
689 l = LINETABLE (s);
690 len = l->nitems;
691 prev_line = -1;
692 first_line = -1;
693 for (i = 0; i < len; i++)
694 {
695 item = l->item[i];
696 if (item < 0)
697 line = - item - 1;
698 else
699 {
700 line++;
701 if (first_line < 0)
702 {
703 first_line = line;
704 first_pc = item;
705 }
706 /* Return the last line that did not start after PC. */
707 if (pc >= item)
708 {
709 prev_line = line;
710 prev_pc = item;
711 }
712 else
713 break;
714 }
715 }
716
717 /* Is this file's best line closer than the best in the other files?
718 If so, record this file, and its best line, as best so far. */
719 if (prev_line >= 0 && prev_pc > best_pc)
720 {
721 best_pc = prev_pc;
722 best_line = prev_line;
723 best_symtab = s;
724 if (i < len)
725 best_end = item;
726 else
727 best_end = 0;
728 }
729 /* Is this file's first line closer than the first lines of other files?
730 If so, record this file, and its first line, as best alternate. */
731 if (first_line >= 0 && first_pc > pc
732 && (alt_pc == 0 || first_pc < alt_pc))
733 {
734 alt_pc = first_pc;
735 alt_line = first_line;
736 alt_symtab = s;
737 }
738 }
739 if (best_symtab == 0)
740 {
741 value.symtab = alt_symtab;
742 value.line = alt_line - 1;
743 value.pc = BLOCK_END (BLOCKVECTOR_BLOCK (bv, 0));
744 value.end = alt_pc;
745 }
746 else
747 {
748 value.symtab = best_symtab;
749 value.line = best_line;
750 value.pc = best_pc;
751 value.end = (best_end ? best_end
752 : (alt_pc ? alt_pc
753 : BLOCK_END (BLOCKVECTOR_BLOCK (bv, 0))));
754 }
755 return value;
756 }
757 \f
758 /* Find the PC value for a given source file and line number.
759 Returns zero for invalid line number.
760 The source file is specified with a struct symtab. */
761
762 CORE_ADDR
763 find_line_pc (symtab, line)
764 struct symtab *symtab;
765 int line;
766 {
767 register struct linetable *l;
768 register int index;
769 int dummy;
770
771 if (symtab == 0)
772 return 0;
773 l = LINETABLE (symtab);
774 index = find_line_common(l, line, &dummy);
775 return index ? l->item[index] : 0;
776 }
777
778 /* Find the range of pc values in a line.
779 Store the starting pc of the line into *STARTPTR
780 and the ending pc (start of next line) into *ENDPTR.
781 Returns 1 to indicate success.
782 Returns 0 if could not find the specified line. */
783
784 int
785 find_line_pc_range (symtab, thisline, startptr, endptr)
786 struct symtab *symtab;
787 int thisline;
788 CORE_ADDR *startptr, *endptr;
789 {
790 register struct linetable *l;
791 register int index;
792 int exact_match; /* did we get an exact linenumber match */
793 register CORE_ADDR prev_pc;
794 CORE_ADDR last_pc;
795
796 if (symtab == 0)
797 return 0;
798
799 l = LINETABLE (symtab);
800 index = find_line_common (l, thisline, &exact_match);
801 if (index)
802 {
803 *startptr = l->item[index];
804 /* If we have not seen an entry for the specified line,
805 assume that means the specified line has zero bytes. */
806 if (!exact_match || index == l->nitems-1)
807 *endptr = *startptr;
808 else
809 /* Perhaps the following entry is for the following line.
810 It's worth a try. */
811 if (l->item[index+1] > 0)
812 *endptr = l->item[index+1];
813 else
814 *endptr = find_line_pc (symtab, thisline+1);
815 return 1;
816 }
817
818 return 0;
819 }
820
821 /* Given a line table and a line number, return the index into the line
822 table for the pc of the nearest line whose number is >= the specified one.
823 Return 0 if none is found. The value is never zero is it is an index.
824
825 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
826
827 static int
828 find_line_common (l, lineno, exact_match)
829 register struct linetable *l;
830 register int lineno;
831 int *exact_match;
832 {
833 register int i;
834 register int len;
835
836 /* BEST is the smallest linenumber > LINENO so far seen,
837 or 0 if none has been seen so far.
838 BEST_INDEX identifies the item for it. */
839
840 int best_index = 0;
841 int best = 0;
842
843 int nextline = -1;
844
845 if (lineno <= 0)
846 return 0;
847
848 len = l->nitems;
849 for (i = 0; i < len; i++)
850 {
851 register int item = l->item[i];
852
853 if (item < 0)
854 nextline = - item - 1;
855 else
856 {
857 nextline++;
858 if (nextline == lineno)
859 {
860 *exact_match = 1;
861 return i;
862 }
863
864 if (nextline > lineno && (best == 0 || nextline < best))
865 {
866 best = lineno;
867 best_index = i;
868 }
869 }
870 }
871
872 /* If we got here, we didn't get an exact match. */
873
874 *exact_match = 0;
875 return best_index;
876 }
877
878 int
879 find_pc_line_pc_range (pc, startptr, endptr)
880 CORE_ADDR pc;
881 CORE_ADDR *startptr, *endptr;
882 {
883 struct symtab_and_line sal;
884 sal = find_pc_line (pc, 0);
885 *startptr = sal.pc;
886 *endptr = sal.end;
887 return sal.symtab != 0;
888 }
889 \f
890 /* Parse a string that specifies a line number.
891 Pass the address of a char * variable; that variable will be
892 advanced over the characters actually parsed.
893
894 The string can be:
895
896 LINENUM -- that line number in current file. PC returned is 0.
897 FILE:LINENUM -- that line in that file. PC returned is 0.
898 FUNCTION -- line number of openbrace of that function.
899 PC returned is the start of the function.
900 FILE:FUNCTION -- likewise, but prefer functions in that file.
901 *EXPR -- line in which address EXPR appears.
902
903 FUNCTION may be an undebuggable function found in misc_function_vector.
904
905 If the argument FUNFIRSTLINE is nonzero, we want the first line
906 of real code inside a function when a function is specified.
907
908 DEFAULT_SYMTAB specifies the file to use if none is specified.
909 It defaults to current_source_symtab.
910 DEFAULT_LINE specifies the line number to use for relative
911 line numbers (that start with signs). Defaults to current_source_line.
912
913 Note that it is possible to return zero for the symtab
914 if no file is validly specified. Callers must check that.
915 Also, the line number returned may be invalid. */
916
917 struct symtabs_and_lines
918 decode_line_1 (argptr, funfirstline, default_symtab, default_line)
919 char **argptr;
920 int funfirstline;
921 struct symtab *default_symtab;
922 int default_line;
923 {
924 struct symtabs_and_lines decode_line_2 ();
925 struct symtabs_and_lines values;
926 struct symtab_and_line value;
927 register char *p, *p1;
928 register struct symtab *s;
929 register struct symbol *sym;
930 register CORE_ADDR pc;
931 register int i;
932 char *copy;
933 struct symbol *sym_class;
934 char *class_name, *method_name, *phys_name;
935 int method_counter;
936 int i1;
937 struct symbol **sym_arr;
938 struct type *t, *field;
939 char **physnames;
940
941 /* Defaults have defaults. */
942
943 if (default_symtab == 0)
944 {
945 default_symtab = current_source_symtab;
946 default_line = current_source_line;
947 }
948
949 /* See if arg is *PC */
950
951 if (**argptr == '*')
952 {
953 (*argptr)++;
954 pc = parse_and_eval_address_1 (argptr);
955 values.sals = (struct symtab_and_line *)malloc (sizeof (struct symtab_and_line));
956 values.nelts = 1;
957 values.sals[0] = find_pc_line (pc, 0);
958 values.sals[0].pc = pc;
959 return values;
960 }
961
962 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
963
964 s = 0;
965
966 for (p = *argptr; *p; p++)
967 {
968 if (p[0] == ':' || p[0] == ' ' || p[0] == '\t')
969 break;
970 }
971 while (p[0] == ' ' || p[0] == '\t') p++;
972
973 if (p[0] == ':')
974 {
975
976 /* C++ */
977 if (p[1] ==':')
978 {
979 /* Extract the class name. */
980 p1 = p;
981 while (p != *argptr && p[-1] == ' ') --p;
982 copy = (char *) alloca (p - *argptr + 1);
983 bcopy (*argptr, copy, p - *argptr);
984 copy[p - *argptr] = 0;
985
986 /* Discard the class name from the arg. */
987 p = p1 + 2;
988 while (*p == ' ' || *p == '\t') p++;
989 *argptr = p;
990
991 sym_class = lookup_symbol (copy, 0, STRUCT_NAMESPACE);
992
993 if (sym_class &&
994 (TYPE_CODE (SYMBOL_TYPE (sym_class)) == TYPE_CODE_STRUCT
995 || TYPE_CODE (SYMBOL_TYPE (sym_class)) == TYPE_CODE_UNION))
996 {
997 /* Arg token is not digits => try it as a function name
998 Find the next token (everything up to end or next whitespace). */
999 p = *argptr;
1000 while (*p && *p != ' ' && *p != '\t' && *p != ',' && *p !=':') p++;
1001 copy = (char *) alloca (p - *argptr + 1);
1002 bcopy (*argptr, copy, p - *argptr);
1003 copy[p - *argptr] = '\0';
1004
1005 /* no line number may be specified */
1006 while (*p == ' ' || *p == '\t') p++;
1007 *argptr = p;
1008
1009 sym = 0;
1010 i1 = 0; /* counter for the symbol array */
1011 t = SYMBOL_TYPE (sym_class);
1012 sym_arr = (struct symbol **) alloca(TYPE_NFN_FIELDS_TOTAL (t) * sizeof(struct symbol*));
1013 physnames = (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t) * sizeof(char*));
1014
1015 if (destructor_name_p (copy, t))
1016 {
1017 /* destructors are a special case. */
1018 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, 0);
1019 int len = TYPE_FN_FIELDLIST_LENGTH (t, 0) - 1;
1020 phys_name = TYPE_FN_FIELD_PHYSNAME (f, len);
1021 physnames[i1] = (char *)alloca (strlen (phys_name) + 1);
1022 strcpy (physnames[i1], phys_name);
1023 sym_arr[i1] = lookup_symbol (phys_name, SYMBOL_BLOCK_VALUE (sym_class), VAR_NAMESPACE);
1024 if (sym_arr[i1]) i1++;
1025 }
1026 else while (t)
1027 {
1028 int constructor_p;
1029
1030 class_name = TYPE_NAME (t);
1031 while (*class_name++ != ' ');
1032
1033 constructor_p = ! strcmp (class_name, copy);
1034
1035 sym_class = lookup_symbol (class_name, 0, STRUCT_NAMESPACE);
1036 for (method_counter = TYPE_NFN_FIELDS (SYMBOL_TYPE (sym_class)) - 1;
1037 method_counter >= 0;
1038 --method_counter)
1039 {
1040 int field_counter;
1041 struct fn_field *f =
1042 TYPE_FN_FIELDLIST1 (SYMBOL_TYPE (sym_class), method_counter);
1043
1044 method_name = TYPE_FN_FIELDLIST_NAME (SYMBOL_TYPE (sym_class), method_counter);
1045 if (!strcmp (copy, method_name))
1046 for (field_counter = TYPE_FN_FIELDLIST_LENGTH (SYMBOL_TYPE (sym_class), method_counter) - (1 + constructor_p);
1047 field_counter >= 0;
1048 --field_counter)
1049 {
1050 phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter);
1051 physnames[i1] = (char*) alloca (strlen (phys_name) + 1);
1052 strcpy (physnames[i1], phys_name);
1053 sym_arr[i1] = lookup_symbol (phys_name, SYMBOL_BLOCK_VALUE (sym_class), VAR_NAMESPACE);
1054 if (sym_arr[i1]) i1++;
1055 }
1056 }
1057 t = TYPE_BASECLASS(t);
1058 }
1059
1060 if (i1 == 1)
1061 {
1062 sym = sym_arr[0];
1063
1064 if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
1065 {
1066 /* Arg is the name of a function */
1067 pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) + FUNCTION_START_OFFSET;
1068 if (funfirstline)
1069 SKIP_PROLOGUE (pc);
1070 values.sals = (struct symtab_and_line *)malloc (sizeof (struct symtab_and_line));
1071 values.nelts = 1;
1072 values.sals[0] = find_pc_line (pc, 0);
1073 values.sals[0].pc = (values.sals[0].end && values.sals[0].pc != pc) ? values.sals[0].end : pc;
1074 }
1075 else
1076 {
1077 values.nelts = 0;
1078 }
1079 return values;
1080 }
1081 if (i1 > 0)
1082 {
1083 return decode_line_2 (argptr, sym_arr, physnames, i1, funfirstline);
1084 }
1085 else
1086 error ("that class does not have any method named %s",copy);
1087 }
1088 else
1089 error("no class, struct, or union named %s", copy );
1090 }
1091 /* end of C++ */
1092
1093
1094 /* Extract the file name. */
1095 p1 = p;
1096 while (p != *argptr && p[-1] == ' ') --p;
1097 copy = (char *) alloca (p - *argptr + 1);
1098 bcopy (*argptr, copy, p - *argptr);
1099 copy[p - *argptr] = 0;
1100
1101 /* Find that file's data. */
1102 s = lookup_symtab (copy);
1103 if (s == 0)
1104 {
1105 if (symtab_list == 0)
1106 error ("No symbol table is loaded. Use the \"symbol-file\" command.");
1107 error ("No source file named %s.", copy);
1108 }
1109
1110 /* Discard the file name from the arg. */
1111 p = p1 + 1;
1112 while (*p == ' ' || *p == '\t') p++;
1113 *argptr = p;
1114 }
1115
1116 /* S is specified file's symtab, or 0 if no file specified.
1117 arg no longer contains the file name. */
1118
1119 /* Check whether arg is all digits (and sign) */
1120
1121 p = *argptr;
1122 if (*p == '-' || *p == '+') p++;
1123 while (*p >= '0' && *p <= '9')
1124 p++;
1125
1126 if (p != *argptr && (*p == 0 || *p == ' ' || *p == '\t' || *p == ','))
1127 {
1128 /* We found a token consisting of all digits -- at least one digit. */
1129 enum sign {none, plus, minus} sign = none;
1130
1131 if (**argptr == '+')
1132 sign = plus, (*argptr)++;
1133 else if (**argptr == '-')
1134 sign = minus, (*argptr)++;
1135 value.line = atoi (*argptr);
1136 switch (sign)
1137 {
1138 case plus:
1139 if (p == *argptr)
1140 value.line = 5;
1141 if (s == 0)
1142 value.line = default_line + value.line;
1143 break;
1144 case minus:
1145 if (p == *argptr)
1146 value.line = 15;
1147 if (s == 0)
1148 value.line = default_line - value.line;
1149 else
1150 value.line = 1;
1151 break;
1152 }
1153
1154 while (*p == ' ' || *p == '\t') p++;
1155 *argptr = p;
1156 if (s == 0)
1157 s = default_symtab;
1158 value.symtab = s;
1159 value.pc = 0;
1160 values.sals = (struct symtab_and_line *)malloc (sizeof (struct symtab_and_line));
1161 values.sals[0] = value;
1162 values.nelts = 1;
1163 return values;
1164 }
1165
1166 /* Arg token is not digits => try it as a function name
1167 Find the next token (everything up to end or next whitespace). */
1168 p = *argptr;
1169 while (*p && *p != ' ' && *p != '\t' && *p != ',') p++;
1170 copy = (char *) alloca (p - *argptr + 1);
1171 bcopy (*argptr, copy, p - *argptr);
1172 copy[p - *argptr] = 0;
1173 while (*p == ' ' || *p == '\t') p++;
1174 *argptr = p;
1175
1176 /* Look up that token as a function.
1177 If file specified, use that file's per-file block to start with. */
1178
1179 sym = lookup_symbol (copy, s ? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), 1) : 0,
1180 VAR_NAMESPACE);
1181
1182 if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
1183 {
1184 /* Arg is the name of a function */
1185 pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) + FUNCTION_START_OFFSET;
1186 if (funfirstline)
1187 SKIP_PROLOGUE (pc);
1188 value = find_pc_line (pc, 0);
1189 value.pc = (value.end && value.pc != pc) ? value.end : pc;
1190 values.sals = (struct symtab_and_line *)malloc (sizeof (struct symtab_and_line));
1191 values.sals[0] = value;
1192 values.nelts = 1;
1193 return values;
1194 }
1195
1196 if (sym)
1197 error ("%s is not a function.", copy);
1198
1199 if ((i = lookup_misc_func (copy)) < 0)
1200 error ("Function %s not defined.", copy);
1201 else
1202 {
1203 value.symtab = 0;
1204 value.line = 0;
1205 value.pc = misc_function_vector[i].address + FUNCTION_START_OFFSET;
1206 if (funfirstline)
1207 SKIP_PROLOGUE (value.pc);
1208 values.sals = (struct symtab_and_line *)malloc (sizeof (struct symtab_and_line));
1209 values.sals[0] = value;
1210 values.nelts = 1;
1211 return values;
1212 }
1213
1214 if (symtab_list == 0)
1215 error ("No symbol table is loaded. Use the \"symbol-file\" command.");
1216 error ("Function %s not defined.", copy);
1217 }
1218
1219 struct symtabs_and_lines
1220 decode_line_spec (string, funfirstline)
1221 char *string;
1222 int funfirstline;
1223 {
1224 struct symtabs_and_lines sals;
1225 if (string == 0)
1226 error ("Empty line specification.");
1227 sals = decode_line_1 (&string, funfirstline,
1228 current_source_symtab, current_source_line);
1229 if (*string)
1230 error ("Junk at end of line specification: %s", string);
1231 return sals;
1232 }
1233
1234 struct symtabs_and_lines
1235 decode_line_2 (argptr, sym_arr, physnames, nelts, funfirstline)
1236 char **argptr;
1237 struct symbol *sym_arr[];
1238 char *physnames[];
1239 int nelts;
1240 int funfirstline;
1241 {
1242 char *getenv();
1243 struct symtabs_and_lines values, return_values;
1244 register CORE_ADDR pc;
1245 char *args, *arg1, *read_line ();
1246 int i;
1247 char *prompt;
1248
1249 values.sals = (struct symtab_and_line *) alloca (nelts * sizeof(struct symtab_and_line));
1250 return_values.sals = (struct symtab_and_line *) malloc (nelts * sizeof(struct symtab_and_line));
1251
1252 i = 0;
1253 printf("[0] cancel\n[1] all\n");
1254 while (i < nelts)
1255 {
1256 if (sym_arr[i] && SYMBOL_CLASS (sym_arr[i]) == LOC_BLOCK)
1257 {
1258 /* Arg is the name of a function */
1259 pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym_arr[i]))
1260 + FUNCTION_START_OFFSET;
1261 if (funfirstline)
1262 SKIP_PROLOGUE (pc);
1263 values.sals[i] = find_pc_line (pc, 0);
1264 printf("[%d] file:%s; line number:%d\n",
1265 (i+2), values.sals[i].symtab->filename, values.sals[i].line);
1266 }
1267 else printf ("?HERE\n");
1268 i++;
1269 }
1270
1271 if ((prompt = getenv ("PS2")) == NULL)
1272 {
1273 prompt = ">";
1274 }
1275 printf("%s ",prompt);
1276 fflush(stdout);
1277
1278 args = read_line (0);
1279
1280 if (args == 0)
1281 error_no_arg ("one or more choice numbers");
1282
1283 i = 0;
1284 while (*args)
1285 {
1286 int num;
1287
1288 arg1 = args;
1289 while (*arg1 >= '0' && *arg1 <= '9') arg1++;
1290 if (*arg1 && *arg1 != ' ' && *arg1 != '\t')
1291 error ("Arguments must be choice numbers.");
1292
1293 num = atoi (args);
1294
1295 if (num == 0)
1296 error ("cancelled");
1297 else if (num == 1)
1298 {
1299 bcopy (values.sals, return_values.sals, (nelts * sizeof(struct symtab_and_line)));
1300 return_values.nelts = nelts;
1301 return return_values;
1302 }
1303
1304 if (num > nelts + 2)
1305 {
1306 printf ("No choice number %d.\n", num);
1307 }
1308 else
1309 {
1310 num -= 2;
1311 if (values.sals[num].pc)
1312 {
1313 return_values.sals[i++] = values.sals[num];
1314 values.sals[num].pc = 0;
1315 }
1316 else
1317 {
1318 printf ("duplicate request for %d ignored.\n", num);
1319 }
1320 }
1321
1322 args = arg1;
1323 while (*args == ' ' || *args == '\t') args++;
1324 }
1325 return_values.nelts = i;
1326 return return_values;
1327 }
1328
1329 /* Return the index of misc function named NAME. */
1330
1331 static
1332 lookup_misc_func (name)
1333 register char *name;
1334 {
1335 register int i;
1336
1337 for (i = 0; i < misc_function_count; i++)
1338 if (!strcmp (misc_function_vector[i].name, name))
1339 return i;
1340 return -1; /* not found */
1341 }
1342 \f
1343 static void
1344 sources_info ()
1345 {
1346 register struct symtab *s;
1347 register int column = 0;
1348
1349 if (symtab_list == 0)
1350 {
1351 printf ("No symbol table is loaded.\n");
1352 return;
1353 }
1354 printf ("Source files for which symbol table is known:\n");
1355 for (s = symtab_list; s; s = s->next)
1356 {
1357 if (column != 0 && column + strlen (s->filename) >= 70)
1358 {
1359 printf ("\n");
1360 column = 0;
1361 }
1362 else if (column != 0)
1363 {
1364 printf (" ");
1365 column++;
1366 }
1367 printf ("%s", s->filename);
1368 column += strlen (s->filename);
1369 if (s->next)
1370 {
1371 printf (",");
1372 column++;
1373 }
1374 }
1375 printf ("\n");
1376 }
1377
1378 /* List all symbols (if REGEXP is 0) or all symbols matching REGEXP.
1379 If CLASS is zero, list all symbols except functions and type names.
1380 If CLASS is 1, list only functions.
1381 If CLASS is 2, list only type names. */
1382
1383 #define MORE \
1384 { print_count++; \
1385 if (print_count >= 21) \
1386 { printf ("--Type Return to print more--"); \
1387 print_count = 0; \
1388 fflush (stdout); \
1389 read_line (); } }
1390
1391 static void
1392 list_symbols (regexp, class)
1393 char *regexp;
1394 int class;
1395 {
1396 register struct symtab *s;
1397 register struct blockvector *bv;
1398 struct blockvector *prev_bv = 0;
1399 register struct block *b;
1400 register int i, j;
1401 register struct symbol *sym;
1402 char *val;
1403 int found_in_file;
1404 static char *classnames[]
1405 = {"variable", "function", "type", "method"};
1406 int print_count = 0;
1407
1408 if (regexp)
1409 if (val = (char *) re_comp (regexp))
1410 error ("Invalid regexp: %s", val);
1411
1412 printf (regexp
1413 ? "All %ss matching regular expression \"%s\":\n"
1414 : "All defined %ss:\n",
1415 classnames[class],
1416 regexp);
1417
1418 for (s = symtab_list; s; s = s->next)
1419 {
1420 found_in_file = 0;
1421 bv = BLOCKVECTOR (s);
1422 /* Often many files share a blockvector.
1423 Scan each blockvector only once so that
1424 we don't get every symbol many times.
1425 It happens that the first symtab in the list
1426 for any given blockvector is the main file. */
1427 if (bv != prev_bv)
1428 for (i = 0; i < 2; i++)
1429 {
1430 b = BLOCKVECTOR_BLOCK (bv, i);
1431 for (j = 0; j < BLOCK_NSYMS (b); j++)
1432 {
1433 QUIT;
1434 sym = BLOCK_SYM (b, j);
1435 if ((regexp == 0 || re_exec (SYMBOL_NAME (sym)))
1436 && ((class == 0 && SYMBOL_CLASS (sym) != LOC_TYPEDEF
1437 && SYMBOL_CLASS (sym) != LOC_BLOCK)
1438 || (class == 1 && SYMBOL_CLASS (sym) == LOC_BLOCK)
1439 || (class == 2 && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
1440 || (class == 3 && SYMBOL_CLASS (sym) == LOC_BLOCK)))
1441 {
1442 if (!found_in_file)
1443 {
1444 printf ("\nFile %s:\n", s->filename);
1445 print_count += 2;
1446 }
1447 found_in_file = 1;
1448 MORE;
1449 if (class != 2 && i == 1)
1450 printf ("static ");
1451 if (class == 2
1452 && SYMBOL_NAMESPACE (sym) != STRUCT_NAMESPACE)
1453 printf ("typedef ");
1454
1455 if (class < 3)
1456 {
1457 type_print (SYMBOL_TYPE (sym),
1458 (SYMBOL_CLASS (sym) == LOC_TYPEDEF
1459 ? "" : SYMBOL_NAME (sym)),
1460 stdout, 0);
1461 printf (";\n");
1462 }
1463 else
1464 {
1465 char buf[1024];
1466 # if 0
1467 type_print_base (TYPE_FN_FIELD_TYPE(t, i), stdout, 0, 0);
1468 type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t, i), stdout, 0);
1469 sprintf (buf, " %s::", TYPE_NAME (t));
1470 type_print_method_args (TYPE_FN_FIELD_ARGS (t, i), buf, name, stdout);
1471 # endif
1472 }
1473 if (class == 2
1474 && SYMBOL_NAMESPACE (sym) != STRUCT_NAMESPACE
1475 && (TYPE_NAME ((SYMBOL_TYPE (sym))) == 0
1476 || 0 != strcmp (TYPE_NAME ((SYMBOL_TYPE (sym))),
1477 SYMBOL_NAME (sym))))
1478 printf (" %s", SYMBOL_NAME (sym));
1479 }
1480 }
1481 }
1482 prev_bv = bv;
1483 }
1484 }
1485
1486 static void
1487 variables_info (regexp)
1488 char *regexp;
1489 {
1490 list_symbols (regexp, 0);
1491 }
1492
1493 static void
1494 functions_info (regexp)
1495 char *regexp;
1496 {
1497 list_symbols (regexp, 1);
1498 }
1499
1500 static void
1501 types_info (regexp)
1502 char *regexp;
1503 {
1504 list_symbols (regexp, 2);
1505 }
1506
1507 static void
1508 methods_info (regexp)
1509 char *regexp;
1510 {
1511 list_symbols (regexp, 3);
1512 }
1513 \f
1514 /* Initialize the standard C scalar types. */
1515
1516 static
1517 struct type *
1518 init_type (code, length, uns, name)
1519 enum type_code code;
1520 int length, uns;
1521 char *name;
1522 {
1523 register struct type *type;
1524
1525 type = (struct type *) xmalloc (sizeof (struct type));
1526 bzero (type, sizeof *type);
1527 TYPE_MAIN_VARIANT (type) = type;
1528 TYPE_CODE (type) = code;
1529 TYPE_LENGTH (type) = length;
1530 TYPE_FLAGS (type) = uns ? TYPE_FLAG_UNSIGNED : 0;
1531 TYPE_FLAGS (type) |= TYPE_FLAG_PERM;
1532 TYPE_NFIELDS (type) = 0;
1533 TYPE_NAME (type) = name;
1534
1535 /* C++ fancies. */
1536 TYPE_NFN_FIELDS (type) = 0;
1537 TYPE_BASECLASS (type) = 0;
1538 return type;
1539 }
1540
1541 static
1542 initialize ()
1543 {
1544 add_info ("variables", variables_info,
1545 "All global and static variable names, or those matching REGEXP.");
1546 add_info ("functions", functions_info,
1547 "All function names, or those matching REGEXP.");
1548 add_info ("types", types_info,
1549 "All types names, or those matching REGEXP.");
1550 add_info ("methods", methods_info,
1551 "All method names, or those matching REGEXP::REGEXP.\n\
1552 If the class qualifier is ommited, it is assumed to be the current scope.\n\
1553 If the first REGEXP is ommited, then all methods matching the second REGEXP\n\
1554 are listed.");
1555 add_info ("sources", sources_info,
1556 "Source files in the program.");
1557
1558 obstack_init (symbol_obstack);
1559
1560 builtin_type_void = init_type (TYPE_CODE_VOID, 0, 0, "void");
1561
1562 builtin_type_float = init_type (TYPE_CODE_FLT, sizeof (float), 0, "float");
1563 builtin_type_double = init_type (TYPE_CODE_FLT, sizeof (double), 0, "double");
1564
1565 builtin_type_char = init_type (TYPE_CODE_INT, sizeof (char), 0, "char");
1566 builtin_type_short = init_type (TYPE_CODE_INT, sizeof (short), 0, "short");
1567 builtin_type_long = init_type (TYPE_CODE_INT, sizeof (long), 0, "long");
1568 builtin_type_int = init_type (TYPE_CODE_INT, sizeof (int), 0, "int");
1569
1570 builtin_type_unsigned_char = init_type (TYPE_CODE_INT, sizeof (char), 1, "unsigned char");
1571 builtin_type_unsigned_short = init_type (TYPE_CODE_INT, sizeof (short), 1, "unsigned short");
1572 builtin_type_unsigned_long = init_type (TYPE_CODE_INT, sizeof (long), 1, "unsigned long");
1573 builtin_type_unsigned_int = init_type (TYPE_CODE_INT, sizeof (int), 1, "unsigned int");
1574 }
1575
1576 END_FILE