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