1 /* Symbol table lookup for the GNU debugger, GDB.
2 Copyright (C) 1986, 1987, 1988 Free Software Foundation, Inc.
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.
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.
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!
22 #include "initialize.h"
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. */
36 struct obstack obstack1;
38 struct obstack *symbol_obstack = &obstack1;
40 /* These variables point to the objects
41 representing the predefined C data types. */
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;
55 /* Lookup the symbol table of a source file named NAME. */
61 register struct symtab *s;
64 for (s = symtab_list; s; s = s->next)
65 if (!strcmp (name, s->filename))
68 /* If name not found as specified, see if adding ".c" helps. */
70 copy = (char *) alloca (strlen (name) + 3);
73 for (s = symtab_list; s; s = s->next)
74 if (!strcmp (copy, s->filename))
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. */
85 lookup_typename (name, block, noerr)
90 register struct symbol *sym = lookup_symbol (name, block, VAR_NAMESPACE);
91 if (sym == 0 || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
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;
110 error ("No type named %s.", name);
112 return SYMBOL_TYPE (sym);
116 lookup_unsigned_typename (name)
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);
130 /* Lookup a structure type named "struct NAME",
131 visible in lexical block BLOCK. */
134 lookup_struct (name, block)
138 register struct symbol *sym = lookup_symbol (name, block, STRUCT_NAMESPACE);
140 error ("No struct type named %s.", name);
141 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
142 error ("This context has union or enum %s, not a struct.", name);
143 return SYMBOL_TYPE (sym);
146 /* Lookup a union type named "union NAME",
147 visible in lexical block BLOCK. */
150 lookup_union (name, block)
154 register struct symbol *sym = lookup_symbol (name, block, STRUCT_NAMESPACE);
156 error ("No union type named %s.", name);
157 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_UNION)
158 error ("This context has struct or enum %s, not a union.", name);
159 return SYMBOL_TYPE (sym);
162 /* Lookup an enum type named "enum NAME",
163 visible in lexical block BLOCK. */
166 lookup_enum (name, block)
170 register struct symbol *sym = lookup_symbol (name, block, STRUCT_NAMESPACE);
172 error ("No enum type named %s.", name);
173 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
174 error ("This context has struct or union %s, not an enum.", name);
175 return SYMBOL_TYPE (sym);
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. */
182 lookup_pointer_type (type)
185 register struct type *ptype = TYPE_POINTER_TYPE (type);
186 if (ptype) return ptype;
188 /* This is the first time anyone wanted a pointer to a TYPE. */
189 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
190 ptype = (struct type *) xmalloc (sizeof (struct type));
192 ptype = (struct type *) obstack_alloc (symbol_obstack,
193 sizeof (struct type));
195 bzero (ptype, sizeof (struct type));
196 TYPE_TARGET_TYPE (ptype) = type;
197 TYPE_POINTER_TYPE (type) = ptype;
198 /* New type is permanent if type pointed to is permanent. */
199 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
200 TYPE_FLAGS (ptype) |= TYPE_FLAG_PERM;
201 /* We assume the machine has only one representation for pointers! */
202 TYPE_LENGTH (ptype) = sizeof (char *);
203 TYPE_CODE (ptype) = TYPE_CODE_PTR;
207 /* Given a type TYPE, return a type of functions that return that type.
208 May need to construct such a type if this is the first use. */
211 lookup_function_type (type)
214 register struct type *ptype = TYPE_FUNCTION_TYPE (type);
215 if (ptype) return ptype;
217 /* This is the first time anyone wanted a function returning a TYPE. */
218 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
219 ptype = (struct type *) xmalloc (sizeof (struct type));
221 ptype = (struct type *) obstack_alloc (symbol_obstack,
222 sizeof (struct type));
224 bzero (ptype, sizeof (struct type));
225 TYPE_TARGET_TYPE (ptype) = type;
226 TYPE_FUNCTION_TYPE (type) = ptype;
227 /* New type is permanent if type returned is permanent. */
228 if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
229 TYPE_FLAGS (ptype) |= TYPE_FLAG_PERM;
230 TYPE_LENGTH (ptype) = 1;
231 TYPE_CODE (ptype) = TYPE_CODE_FUNC;
232 TYPE_NFIELDS (ptype) = 0;
236 /* Smash TYPE to be a type of pointers to TO_TYPE.
237 If TO_TYPE is not permanent and has no pointer-type yet,
238 record TYPE as its pointer-type. */
241 smash_to_pointer_type (type, to_type)
242 struct type *type, *to_type;
244 bzero (type, sizeof (struct type));
245 TYPE_TARGET_TYPE (type) = to_type;
246 /* We assume the machine has only one representation for pointers! */
247 TYPE_LENGTH (type) = sizeof (char *);
248 TYPE_CODE (type) = TYPE_CODE_PTR;
250 if (TYPE_POINTER_TYPE (to_type) == 0
251 && !(TYPE_FLAGS (type) & TYPE_FLAG_PERM))
253 TYPE_POINTER_TYPE (to_type) = type;
257 /* Smash TYPE to be a type of functions returning TO_TYPE.
258 If TO_TYPE is not permanent and has no function-type yet,
259 record TYPE as its function-type. */
262 smash_to_function_type (type, to_type)
263 struct type *type, *to_type;
265 bzero (type, sizeof (struct type));
266 TYPE_TARGET_TYPE (type) = to_type;
267 TYPE_LENGTH (type) = 1;
268 TYPE_CODE (type) = TYPE_CODE_FUNC;
269 TYPE_NFIELDS (type) = 0;
271 if (TYPE_FUNCTION_TYPE (to_type) == 0
272 && !(TYPE_FLAGS (type) & TYPE_FLAG_PERM))
274 TYPE_FUNCTION_TYPE (to_type) = type;
278 static struct symbol *lookup_block_symbol ();
280 /* Find the definition for a specified symbol name NAME
281 in namespace NAMESPACE, visible from lexical block BLOCK.
282 Returns the struct symbol pointer, or zero if no symbol is found. */
285 lookup_symbol (name, block, namespace)
287 register struct block *block;
288 enum namespace namespace;
291 register struct symbol *sym;
292 register struct symtab *s;
293 struct blockvector *bv;
295 /* Search specified block and its superiors. */
299 sym = lookup_block_symbol (block, name, namespace);
301 block = BLOCK_SUPERBLOCK (block);
304 /* Now search all symtabs' global blocks. */
306 for (s = symtab_list; s; s = s->next)
308 bv = BLOCKVECTOR (s);
309 block = BLOCKVECTOR_BLOCK (bv, 0);
310 sym = lookup_block_symbol (block, name, namespace);
314 /* Now search all symtabs' per-file blocks.
315 Not strictly correct, but more useful than an error. */
317 for (s = symtab_list; s; s = s->next)
319 bv = BLOCKVECTOR (s);
320 block = BLOCKVECTOR_BLOCK (bv, 1);
321 sym = lookup_block_symbol (block, name, namespace);
327 /* Look for a symbol in block BLOCK. */
329 static struct symbol *
330 lookup_block_symbol (block, name, namespace)
331 register struct block *block;
333 enum namespace namespace;
335 register int bot, top, inc;
336 register struct symbol *sym;
338 top = BLOCK_NSYMS (block);
341 /* If the blocks's symbols were sorted, start with a binary search. */
343 if (BLOCK_SHOULD_SORT (block))
345 /* First, advance BOT to not far before
346 the first symbol whose name is NAME. */
350 inc = (top - bot + 1);
351 /* No need to keep binary searching for the last few bits worth. */
354 inc = (inc >> 1) + bot;
355 sym = BLOCK_SYM (block, inc);
356 if (SYMBOL_NAME (sym)[0] < name[0])
358 else if (SYMBOL_NAME (sym)[0] > name[0])
360 else if (strcmp (SYMBOL_NAME (sym), name) < 0)
366 /* Now scan forward until we run out of symbols,
367 find one whose name is greater than NAME,
369 If there is more than one symbol with the right name and namespace,
370 we return the first one. dbxread.c is careful to make sure
371 that if one is a register then it comes first. */
373 top = BLOCK_NSYMS (block);
376 sym = BLOCK_SYM (block, bot);
377 inc = SYMBOL_NAME (sym)[0] - name[0];
379 inc = strcmp (SYMBOL_NAME (sym), name);
380 if (inc == 0 && SYMBOL_NAMESPACE (sym) == namespace)
389 /* Here if block isn't sorted.
390 This loop is equivalent to the loop above,
391 but hacked greatly for speed. */
393 top = BLOCK_NSYMS (block);
397 sym = BLOCK_SYM (block, bot);
398 if (SYMBOL_NAME (sym)[0] == inc
399 && !strcmp (SYMBOL_NAME (sym), name)
400 && SYMBOL_NAMESPACE (sym) == namespace)
407 /* Return the symbol for the function which contains a specified
408 lexical block, described by a struct block BL. */
414 while (BLOCK_FUNCTION (bl) == 0 && BLOCK_SUPERBLOCK (bl) != 0)
415 bl = BLOCK_SUPERBLOCK (bl);
417 return BLOCK_FUNCTION (bl);
420 /* Subroutine of find_pc_line */
422 static struct symtab *
424 register CORE_ADDR pc;
426 register struct block *b;
427 struct blockvector *bv;
428 register struct symtab *s;
430 /* Search all symtabs for one whose file contains our pc */
432 for (s = symtab_list; s; s = s->next)
434 bv = BLOCKVECTOR (s);
435 b = BLOCKVECTOR_BLOCK (bv, 0);
436 if (BLOCK_START (b) <= pc
437 && BLOCK_END (b) > pc)
444 /* Find the source file and line number for a given PC value.
445 Return a structure containing a symtab pointer, a line number,
446 and a pc range for the entire source line.
447 The value's .pc field is NOT the specified pc.
448 NOTCURRENT nonzero means, if specified pc is on a line boundary,
449 use the line that ends there. Otherwise, in that case, the line
450 that begins there is used. */
452 struct symtab_and_line
453 find_pc_line (pc, notcurrent)
458 register struct linetable *l;
460 register int i, item;
462 struct symtab_and_line value;
463 struct blockvector *bv;
465 /* Info on best line seen so far, and where it starts, and its file. */
468 CORE_ADDR best_pc = 0;
469 CORE_ADDR best_end = 0;
470 struct symtab *best_symtab = 0;
472 /* Store here the first line number
473 of a file which contains the line at the smallest pc after PC.
474 If we don't find a line whose range contains PC,
475 we will use a line one less than this,
476 with a range from the start of that file to the first line's pc. */
478 CORE_ADDR alt_pc = 0;
479 struct symtab *alt_symtab = 0;
481 /* Info on best line seen in this file. */
486 /* Info on first line of this file. */
491 /* If this pc is not from the current frame,
492 it is the address of the end of a call instruction.
493 Quite likely that is the start of the following statement.
494 But what we want is the statement containing the instruction.
495 Fudge the pc to make sure we get that. */
497 if (notcurrent) pc -= 1;
499 s = find_pc_symtab (pc);
508 bv = BLOCKVECTOR (s);
510 /* Look at all the symtabs that share this blockvector.
511 They all have the same apriori range, that we found was right;
512 but they have different line tables. */
514 for (; s && BLOCKVECTOR (s) == bv; s = s->next)
516 /* Find the best line in this symtab. */
521 for (i = 0; i < len; i++)
534 /* Return the last line that did not start after PC. */
545 /* Is this file's best line closer than the best in the other files?
546 If so, record this file, and its best line, as best so far. */
547 if (prev_line >= 0 && prev_pc > best_pc)
550 best_line = prev_line;
557 /* Is this file's first line closer than the first lines of other files?
558 If so, record this file, and its first line, as best alternate. */
559 if (first_line >= 0 && first_pc > pc
560 && (alt_pc == 0 || first_pc < alt_pc))
563 alt_line = first_line;
567 if (best_symtab == 0)
569 value.symtab = alt_symtab;
570 value.line = alt_line - 1;
571 value.pc = BLOCK_END (BLOCKVECTOR_BLOCK (bv, 0));
576 value.symtab = best_symtab;
577 value.line = best_line;
579 value.end = (best_end ? best_end
581 : BLOCK_END (BLOCKVECTOR_BLOCK (bv, 0))));
586 /* Find the PC value for a given source file and line number.
587 Returns zero for invalid line number.
588 The source file is specified with a struct symtab. */
591 find_line_pc (symtab, line)
592 struct symtab *symtab;
595 register struct linetable *l;
601 l = LINETABLE (symtab);
602 index = find_line_common(l, line, &dummy);
603 return index ? l->item[index] : 0;
606 /* Find the range of pc values in a line.
607 Store the starting pc of the line into *STARTPTR
608 and the ending pc (start of next line) into *ENDPTR.
609 Returns 1 to indicate success.
610 Returns 0 if could not find the specified line. */
613 find_line_pc_range (symtab, thisline, startptr, endptr)
614 struct symtab *symtab;
616 CORE_ADDR *startptr, *endptr;
618 register struct linetable *l;
620 int exact_match; /* did we get an exact linenumber match */
621 register CORE_ADDR prev_pc;
627 l = LINETABLE (symtab);
628 index = find_line_common (l, thisline, &exact_match);
631 *startptr = l->item[index];
632 /* If we have not seen an entry for the specified line,
633 assume that means the specified line has zero bytes. */
634 if (!exact_match || index == l->nitems-1)
637 /* Perhaps the following entry is for the following line.
639 if (l->item[index+1] > 0)
640 *endptr = l->item[index+1];
642 *endptr = find_line_pc (symtab, thisline+1);
649 /* Given a line table and a line number, return the index into the line
650 table for the pc of the nearest line whose number is >= the specified one.
651 Return 0 if none is found. The value is never zero is it is an index.
653 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
656 find_line_common (l, lineno, exact_match)
657 register struct linetable *l;
664 /* BEST is the smallest linenumber > LINENO so far seen,
665 or 0 if none has been seen so far.
666 BEST_INDEX identifies the item for it. */
677 for (i = 0; i < len; i++)
679 register int item = l->item[i];
682 nextline = - item - 1;
686 if (nextline == lineno)
692 if (nextline > lineno && (best == 0 || nextline < best))
700 /* If we got here, we didn't get an exact match. */
707 find_pc_line_pc_range (pc, startptr, endptr)
709 CORE_ADDR *startptr, *endptr;
711 struct symtab_and_line sal;
712 sal = find_pc_line (pc, 0);
715 return sal.symtab != 0;
718 /* Parse a string that specifies a line number.
719 Pass the address of a char * variable; that variable will be
720 advanced over the characters actually parsed.
724 LINENUM -- that line number in current file. PC returned is 0.
725 FILE:LINENUM -- that line in that file. PC returned is 0.
726 FUNCTION -- line number of openbrace of that function.
727 PC returned is the start of the function.
728 FILE:FUNCTION -- likewise, but prefer functions in that file.
729 *EXPR -- line in which address EXPR appears.
731 FUNCTION may be an undebuggable function found in misc_function_vector.
733 If the argument FUNFIRSTLINE is nonzero, we want the first line
734 of real code inside a function when a function is specified.
736 DEFAULT_SYMTAB specifies the file to use if none is specified.
737 It defaults to current_source_symtab.
738 DEFAULT_LINE specifies the line number to use for relative
739 line numbers (that start with signs). Defaults to current_source_line.
741 Note that it is possible to return zero for the symtab
742 if no file is validly specified. Callers must check that.
743 Also, the line number returned may be invalid. */
745 struct symtab_and_line
746 decode_line_1 (argptr, funfirstline, default_symtab, default_line)
749 struct symtab *default_symtab;
752 struct symtab_and_line value;
753 register char *p, *p1;
754 register struct symtab *s;
755 register struct symbol *sym;
756 register CORE_ADDR pc;
760 /* Defaults have defaults. */
762 if (default_symtab == 0)
764 default_symtab = current_source_symtab;
765 default_line = current_source_line;
768 /* See if arg is *PC */
773 pc = parse_and_eval_address_1 (argptr);
774 value = find_pc_line (pc, 0);
779 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
783 for (p = *argptr; *p; p++)
785 if (p[0] == ':' || p[0] == ' ' || p[0] == '\t')
788 while (p[0] == ' ' || p[0] == '\t') p++;
792 /* Extract the file name. */
794 while (p != *argptr && p[-1] == ' ') --p;
795 copy = (char *) alloca (p - *argptr + 1);
796 bcopy (*argptr, copy, p - *argptr);
797 copy[p - *argptr] = 0;
799 /* Find that file's data. */
800 s = lookup_symtab (copy);
803 if (symtab_list == 0)
804 error ("No symbol table is loaded. Use the \"symbol-file\" command.");
805 error ("No source file named %s.", copy);
808 /* Discard the file name from the arg. */
810 while (*p == ' ' || *p == '\t') p++;
814 /* S is specified file's symtab, or 0 if no file specified.
815 arg no longer contains the file name. */
817 /* Check whether arg is all digits (and sign) */
820 if (*p == '-' || *p == '+') p++;
821 while (*p >= '0' && *p <= '9')
824 if (p != *argptr && (*p == 0 || *p == ' ' || *p == '\t' || *p == ','))
826 /* We found a token consisting of all digits -- at least one digit. */
827 enum sign {none, plus, minus} sign = none;
830 sign = plus, (*argptr)++;
831 else if (**argptr == '-')
832 sign = minus, (*argptr)++;
833 value.line = atoi (*argptr);
840 value.line = default_line + value.line;
846 value.line = default_line - value.line;
852 while (*p == ' ' || *p == '\t') p++;
861 /* Arg token is not digits => try it as a function name
862 Find the next token (everything up to end or next whitespace). */
864 while (*p && *p != ' ' && *p != '\t' && *p != ',') p++;
865 copy = (char *) alloca (p - *argptr + 1);
866 bcopy (*argptr, copy, p - *argptr);
867 copy[p - *argptr] = 0;
868 while (*p == ' ' || *p == '\t') p++;
871 /* Look up that token as a function.
872 If file specified, use that file's per-file block to start with. */
874 sym = lookup_symbol (copy, s ? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), 1) : 0,
877 if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
879 /* Arg is the name of a function */
880 pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) + FUNCTION_START_OFFSET;
883 value = find_pc_line (pc, 0);
884 value.pc = (value.end && value.pc != pc) ? value.end : pc;
889 error ("%s is not a function.", copy);
891 if ((i = lookup_misc_func (copy)) < 0)
892 error ("Function %s not defined.", copy);
897 value.pc = misc_function_vector[i].address + FUNCTION_START_OFFSET;
899 SKIP_PROLOGUE (value.pc);
903 if (symtab_list == 0)
904 error ("No symbol table is loaded. Use the \"symbol-file\" command.");
905 error ("Function %s not defined.", copy);
908 struct symtab_and_line
909 decode_line_spec (string, funfirstline)
913 struct symtab_and_line sal;
915 error ("Empty line specification.");
916 sal = decode_line_1 (&string, funfirstline,
917 current_source_symtab, current_source_line);
919 error ("Junk at end of line specification: %s", string);
923 /* Return the index of misc function named NAME. */
926 lookup_misc_func (name)
931 for (i = 0; i < misc_function_count; i++)
932 if (!strcmp (misc_function_vector[i].name, name))
934 return -1; /* not found */
940 register struct symtab *s;
941 register int column = 0;
943 if (symtab_list == 0)
945 printf ("No symbol table is loaded.\n");
948 printf ("Source files for which symbol table is known:\n");
949 for (s = symtab_list; s; s = s->next)
951 if (column != 0 && column + strlen (s->filename) >= 70)
956 else if (column != 0)
961 printf ("%s", s->filename);
962 column += strlen (s->filename);
972 /* List all symbols (if REGEXP is 0) or all symbols matching REGEXP.
973 If CLASS is zero, list all symbols except functions and type names.
974 If CLASS is 1, list only functions.
975 If CLASS is 2, list only type names. */
979 if (print_count >= 21) \
980 { printf ("--Type Return to print more--"); \
985 static void sort_block_syms ();
988 list_symbols (regexp, class)
992 register struct symtab *s;
993 register struct blockvector *bv;
994 struct blockvector *prev_bv = 0;
995 register struct block *b;
997 register struct symbol *sym;
1000 static char *classnames[]
1001 = {"variable", "function", "type"};
1002 int print_count = 0;
1005 if (val = (char *) re_comp (regexp))
1006 error ("Invalid regexp: %s", val);
1009 ? "All %ss matching regular expression \"%s\":\n"
1010 : "All defined %ss:\n",
1014 for (s = symtab_list; s; s = s->next)
1017 bv = BLOCKVECTOR (s);
1018 /* Often many files share a blockvector.
1019 Scan each blockvector only once so that
1020 we don't get every symbol many times.
1021 It happens that the first symtab in the list
1022 for any given blockvector is the main file. */
1024 for (i = 0; i < 2; i++)
1026 b = BLOCKVECTOR_BLOCK (bv, i);
1027 /* Skip the sort if this block is always sorted. */
1028 if (!BLOCK_SHOULD_SORT (b))
1029 sort_block_syms (b);
1030 for (j = 0; j < BLOCK_NSYMS (b); j++)
1033 sym = BLOCK_SYM (b, j);
1034 if ((regexp == 0 || re_exec (SYMBOL_NAME (sym)))
1035 && ((class == 0 && SYMBOL_CLASS (sym) != LOC_TYPEDEF
1036 && SYMBOL_CLASS (sym) != LOC_BLOCK)
1037 || (class == 1 && SYMBOL_CLASS (sym) == LOC_BLOCK)
1038 || (class == 2 && SYMBOL_CLASS (sym) == LOC_TYPEDEF)))
1042 printf ("\nFile %s:\n", s->filename);
1047 if (class != 2 && i == 1)
1050 && SYMBOL_NAMESPACE (sym) != STRUCT_NAMESPACE)
1051 printf ("typedef ");
1053 type_print (SYMBOL_TYPE (sym),
1054 (SYMBOL_CLASS (sym) == LOC_TYPEDEF
1055 ? "" : SYMBOL_NAME (sym)),
1058 && SYMBOL_NAMESPACE (sym) != STRUCT_NAMESPACE
1059 && (TYPE_NAME ((SYMBOL_TYPE (sym))) == 0
1060 || 0 != strcmp (TYPE_NAME ((SYMBOL_TYPE (sym))),
1061 SYMBOL_NAME (sym))))
1062 printf (" %s", SYMBOL_NAME (sym));
1072 variables_info (regexp)
1075 list_symbols (regexp, 0);
1079 functions_info (regexp)
1082 list_symbols (regexp, 1);
1089 list_symbols (regexp, 2);
1092 /* Call sort_block_syms to sort alphabetically the symbols of one block. */
1095 compare_symbols (s1, s2)
1096 struct symbol **s1, **s2;
1098 /* Names that are less should come first. */
1099 register int namediff = strcmp (SYMBOL_NAME (*s1), SYMBOL_NAME (*s2));
1100 if (namediff != 0) return namediff;
1101 /* For symbols of the same name, registers should come first. */
1102 return ((SYMBOL_CLASS (*s2) == LOC_REGISTER)
1103 - (SYMBOL_CLASS (*s1) == LOC_REGISTER));
1108 register struct block *b;
1110 qsort (&BLOCK_SYM (b, 0), BLOCK_NSYMS (b),
1111 sizeof (struct symbol *), compare_symbols);
1114 /* Initialize the standard C scalar types. */
1118 init_type (code, length, uns, name)
1119 enum type_code code;
1123 register struct type *type;
1125 type = (struct type *) xmalloc (sizeof (struct type));
1126 bzero (type, sizeof *type);
1127 TYPE_CODE (type) = code;
1128 TYPE_LENGTH (type) = length;
1129 TYPE_FLAGS (type) = uns ? TYPE_FLAG_UNSIGNED : 0;
1130 TYPE_FLAGS (type) |= TYPE_FLAG_PERM;
1131 TYPE_NFIELDS (type) = 0;
1132 TYPE_NAME (type) = name;
1140 add_info ("variables", variables_info,
1141 "All global and static variable names, or those matching REGEXP.");
1142 add_info ("functions", functions_info,
1143 "All function names, or those matching REGEXP.");
1144 add_info ("types", types_info,
1145 "All types names, or those matching REGEXP.");
1146 add_info ("sources", sources_info,
1147 "Source files in the program.");
1149 obstack_init (symbol_obstack);
1151 builtin_type_void = init_type (TYPE_CODE_VOID, 0, 0, "void");
1153 builtin_type_float = init_type (TYPE_CODE_FLT, sizeof (float), 0, "float");
1154 builtin_type_double = init_type (TYPE_CODE_FLT, sizeof (double), 0, "double");
1156 builtin_type_char = init_type (TYPE_CODE_INT, sizeof (char), 0, "char");
1157 builtin_type_short = init_type (TYPE_CODE_INT, sizeof (short), 0, "short");
1158 builtin_type_long = init_type (TYPE_CODE_INT, sizeof (long), 0, "long");
1159 builtin_type_int = init_type (TYPE_CODE_INT, sizeof (int), 0, "int");
1161 builtin_type_unsigned_char = init_type (TYPE_CODE_INT, sizeof (char), 1, "unsigned char");
1162 builtin_type_unsigned_short = init_type (TYPE_CODE_INT, sizeof (short), 1, "unsigned short");
1163 builtin_type_unsigned_long = init_type (TYPE_CODE_INT, sizeof (long), 1, "unsigned long");
1164 builtin_type_unsigned_int = init_type (TYPE_CODE_INT, sizeof (int), 1, "unsigned int");