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